+ free_NeonSpam();
+}
+
+struct ClientSocket *getChannelBot(struct ChanNode *chan, int botid) {
+ struct ClientSocket *bot, *use_bot = NULL, *second_bot = NULL, *third_bot = NULL;
+ struct ChanUser *chanuser;
+ for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
+ if(botid && bot->botid != botid) continue;
+ if((chanuser = getChanUser(bot->user, chan)) != NULL) {
+ if((chanuser->flags & CHANUSERFLAG_OPPED)) {
+ use_bot = bot;
+ if(bot->flags & SOCKET_FLAG_PREFERRED) break;
+ } else if(bot->flags & SOCKET_FLAG_PREFERRED)
+ second_bot = bot;
+ else
+ third_bot = bot;
+ }
+ }
+ if(!use_bot) use_bot = second_bot;
+ if(!use_bot) use_bot = third_bot;
+ return use_bot;
+}
+
+TIMEQ_CALLBACK(channel_ban_timeout) {
+ char *str_banid = data;
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+ printf_mysql_query("SELECT `ban_mask`, `channel_name` FROM `bans` LEFT JOIN `channels` ON `ban_channel` = `channel_id` WHERE `ban_id` = '%s'", str_banid);
+ res = mysql_use();
+ struct ChanNode *chan;
+ if((row = mysql_fetch_row(res)) != NULL && (chan = getChanByName(row[1])) != NULL) {
+ struct ClientSocket *use_bot = getChannelBot(chan, 0);
+ if(use_bot) {
+ putsock(use_bot, "MODE %s -b %s", chan->name, row[0]);
+ }
+ printf_mysql_query("DELETE FROM `bans` WHERE `ban_id` = '%s'", str_banid);
+ }
+ free(str_banid);