static void cmd_slowpart(int idx, char *par) { int intvl = 0, delay = 0, count = 1; char *chname = NULL, *p = NULL; struct chanset_t *chan = NULL; tand_t *bot = NULL; /* slowpart #chan 60 */ putlog(LOG_CMDS, "*", "#%s# slowpart %s", dcc[idx].nick, par); chname = newsplit(&par); p = newsplit(&par); intvl = atoi(p); if (!chname[0] || !p[0]) { dprintf(idx, "Usage: slowpart <channel> <interval-seconds>\n"); return; } if (intvl < 10) { dprintf(idx, "Interval must be at least 10 seconds\n"); return; } if (!(chan = findchan_by_dname(chname))) { dprintf(idx, "No such channel %s\n", chname); return; } if (conf.bot->hub) count = 0; for (bot = tandbot; bot; bot = bot->next) { char tmp[100] = ""; tmp[0] = 0; if (bot->u) { if (bot_hublevel(bot->u) < 999) { /* HUB */ simple_snprintf(tmp, sizeof(tmp), "sp %s 0", chname); } else { /* LEAF */ struct flag_record fr = { FR_CHAN|FR_GLOBAL|FR_BOT, 0, 0, 0 }; get_user_flagrec(bot->u, &fr, chname); /* Only send the 'sp' command if the bot is supposed to be in the channel (backups and such) */ if (bot_shouldjoin(bot->u, &fr, chan)) { /* Variation: 60 secs intvl should be 60 +/- 15 */ int v = (random() % (intvl / 2)) - (intvl / 4); delay += intvl; simple_snprintf(tmp, sizeof(tmp), "sp %s %i", chname, delay + v); count++; } } if (tmp[0]) putbot(bot->bot, tmp); } } remove_channel(chan); if (conf.bot->hub) write_userfile(-1); dprintf(idx, "Channel %s removed from the bot.\n", chname); dprintf(idx, "This includes any channel specific bans, invites, exemptions and user records that you set.\n"); if (findchan_by_dname(chname)) { dprintf(idx, "Failed to remove channel.\n"); return; } dprintf(idx, "%i bots parting %s during the next %i seconds\n", count, chname, delay); if (!conf.bot->hub) dprintf(DP_MODE, "PART %s\n", chname); }
bool shouldjoin(struct chanset_t *chan) { struct flag_record fr = { FR_CHAN|FR_GLOBAL|FR_BOT, 0, 0, 0 }; get_user_flagrec(conf.bot->u, &fr, chan->dname, chan); return bot_shouldjoin(conf.bot->u, &fr, chan); }
static void cmd_slowjoin(int idx, char *par) { int intvl = 0, delay = 0, count = 0; char *chname = NULL, *p = NULL, buf[2048] = "", buf2[RESULT_LEN] = ""; struct chanset_t *chan = NULL; tand_t *bot = NULL; /* slowjoin #chan 60 */ putlog(LOG_CMDS, "*", "#%s# slowjoin %s", dcc[idx].nick, par); chname = newsplit(&par); p = newsplit(&par); intvl = atoi(p); if (!chname[0] || !p[0]) { dprintf(idx, "Usage: slowjoin <channel> <interval-seconds> [channel options]\n"); return; } if (intvl < 10) { dprintf(idx, "Interval must be at least 10 seconds\n"); return; } if ((chan = findchan_by_dname(chname))) { dprintf(idx, "Already on %s\n", chan->dname); return; } if (!strchr(CHANMETA, chname[0])) { dprintf(idx, "Invalid channel name\n"); return; } simple_snprintf(buf, sizeof(buf), "+inactive addedby %s addedts %li ", dcc[idx].nick, (long)now); if (par[0]) strlcat(buf, par, sizeof(buf)); if (channel_add(buf2, chname, buf) == ERROR) { dprintf(idx, "Invalid channel or channel options.\n"); if (buf2[0]) dprintf(idx, " %s\n", buf2); return; } buf2[0] = 0; chan = findchan_by_dname(chname); if (!chan) { dprintf(idx, "Hmmm... Channel didn't get added. Weird *shrug*\n"); return; } simple_snprintf(buf2, sizeof(buf2), "cjoin %s %s", chan->dname, buf); putallbots(buf2); if (conf.bot->hub) count = 0; chan->status &= ~CHAN_INACTIVE; for (bot = tandbot; bot; bot = bot->next) { char tmp[100] = ""; tmp[0] = 0; if (bot->u) { if (bot_hublevel(bot->u) < 999) { simple_snprintf(tmp, sizeof(tmp), "sj %s 0", chname); } else { struct flag_record fr = { FR_CHAN|FR_GLOBAL|FR_BOT, 0, 0, 0 }; get_user_flagrec(bot->u, &fr, chname); /* Only send the 'sj' command if the bot is supposed to be in the channel (backups and such) */ if (bot_shouldjoin(bot->u, &fr, chan, 1)) { /* Variation: 60 secs intvl should be 60 +/- 15 */ int v = (random() % (intvl / 2)) - (intvl / 4); delay += intvl; simple_snprintf(tmp, sizeof(tmp), "sj %s %i", chname, delay + v); count++; } } if (tmp[0]) putbot(bot->bot, tmp); } } if (!conf.bot->hub && shouldjoin(chan)) count++; dprintf(idx, "%i bots joining %s during the next %i seconds\n", count, chan->dname, delay); if (!conf.bot->hub && shouldjoin(chan)) join_chan(chan); }