def gadmin(inp, notice=None, bot=None, config=None, db=None): "gadmin <add|del> <nick|host> -- Make <nick|host> an global admin." \ "(you can delete multiple admins at once)" inp = inp.lower() command = inp.split()[0] targets = inp.split()[1:] if 'add' in command: for target in targets: target = user.get_hostmask(target,db) if target in bot.config["admins"]: notice(u"%s is already a global admin." % target) else: notice(u"%s is now a global admin." % target) bot.config["admins"].append(target) bot.config["admins"].sort() json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2) return elif 'del' in command: for target in targets: target = user.get_hostmask(target, db) if target in bot.config["admins"]: notice(u"%s is no longer a global admin." % target) bot.config["admins"].remove(target) bot.config["admins"].sort() json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2) else: notice(u"%s is not a global admin." % target) return
def admin(inp, notice=None, bot=None, chan=None, db=None): """admin [channel] <add|del> <nick|host> -- Makes the user an admin.""" admins = database.get(db, 'channels', 'admins', 'chan', chan) channel = chan.lower() command = inp.split()[0] nicks = inp.split()[1:] if 'add' in command: for nick in nicks: nick = user.get_hostmask(nick, db) if admins and nick in admins: notice(u"[{}]: {} is already an admin.".format(chan, nick)) else: admins = '{} {}'.format(nick, admins).replace('False', '').strip() database.set(db, 'channels', 'admins', admins, 'chan', chan) notice(u"[{}]: {} is now an admin.".format(chan, nick)) elif 'del' in command: if '*' in nicks: database.set(db, 'channels', 'admins', '', 'chan', chan) notice(u"[{}]: All admins have been removed.".format(chan)) else: for nick in nicks: nick = user.get_hostmask(nick, db) if admins and nick in admins: admins = " ".join(admins.replace(nick, '').strip().split()) database.set(db, 'channels', 'admins', admins, 'chan', chan) notice(u"[{}]: {} is no longer an admin.".format( chan, nick)) else: notice(u"[{}]: {} is not an admin.".format(chan, nick)) return
def autoop(inp, notice=None, bot=None, chan=None, db=None): """aop [channel] <enable|disable> OR <add|del> <nick|host> -- Add/Del Autoops.""" inp,chan = get_chan(inp,chan) autoops = database.get(db,'channels','autoops','chan',chan) channel = chan.lower() command = inp.split()[0] if 'enable' in command: database.set(db,'channels','autoop',True,'chan',chan) notice(u"[{}]: Autoops is now enabled.".format(chan)) elif 'disable' in command: database.set(db,'channels','autoop',False,'chan',chan) notice(u"[{}]: Autoops is now disabled.".format(chan)) elif 'add' in command: nicks = inp.split()[1:] for nick in nicks: nick = user.get_hostmask(nick,db) if autoops and nick in autoops: notice(u"[{}]: {} is already an autoop.".format(chan,nick)) else: autoops = '{} {}'.format(nick,autoops).replace('False','').strip() database.set(db,'channels','autoops',autoops,'chan',chan) notice(u"[{}]: {} is now an auto op.".format(chan,nick)) elif 'del' in command: nicks = inp.split()[1:] for nick in nicks: nick = user.get_hostmask(nick,db) if autoops and nick in autoops: autoops = " ".join(autoops.replace(nick,'').strip().split()) database.set(db,'channels','autoops',autoops,'chan',chan) notice(u"[{}]: {} is no longer an auto op.".format(chan,nick)) else: notice(u"[{}]: {} is not an auto op.".format(chan,nick)) return
def autoop(inp, notice=None, bot=None, chan=None, db=None): """aop [channel] <enable|disable> OR <add|del> <nick|host> -- Add/Del Autoops.""" autoops = database.get(db, "channels", "autoops", "chan", chan) channel = chan.lower() command = inp.split()[0] if "enable" in command: database.set(db, "channels", "autoop", True, "chan", chan) notice(u"[{}]: Autoops is now enabled.".format(chan)) elif "disable" in command: database.set(db, "channels", "autoop", False, "chan", chan) notice(u"[{}]: Autoops is now disabled.".format(chan)) elif "add" in command: nicks = inp.split()[1:] for nick in nicks: nick = user.get_hostmask(nick, db) if autoops and nick in autoops: notice(u"[{}]: {} is already an autoop.".format(chan, nick)) else: autoops = "{} {}".format(nick, autoops).replace("False", "").strip() database.set(db, "channels", "autoops", autoops, "chan", chan) notice(u"[{}]: {} is now an auto op.".format(chan, nick)) elif "del" in command: nicks = inp.split()[1:] for nick in nicks: nick = user.get_hostmask(nick, db) if autoops and nick in autoops: autoops = " ".join(autoops.replace(nick, "").strip().split()) database.set(db, "channels", "autoops", autoops, "chan", chan) notice(u"[{}]: {} is no longer an auto op.".format(chan, nick)) else: notice(u"[{}]: {} is not an auto op.".format(chan, nick)) return
def admin(inp, notice=None, bot=None, chan=None, db=None): """admin [channel] <add|del> <nick|host> -- Makes the user an admin.""" inp,chan = get_chan(inp,chan) admins = database.get(db,'channels','admins','chan',chan) channel = chan.lower() command = inp.split()[0] nicks = inp.split()[1:] if 'add' in command: for nick in nicks: nick = user.get_hostmask(nick,db) if admins and nick in admins: notice(u"[{}]: {} is already an admin.".format(chan,nick)) else: admins = '{} {}'.format(nick,admins).replace('False','').strip() database.set(db,'channels','admins',admins,'chan',chan) notice(u"[{}]: {} is now an admin.".format(chan,nick)) elif 'del' in command: for nick in nicks: nick = user.get_hostmask(nick,db) if admins and nick in admins: admins = " ".join(admins.replace(nick,'').strip().split()) database.set(db,'channels','admins',admins,'chan',chan) notice(u"[{}]: {} is no longer an admin.".format(chan,nick)) else: notice(u"[{}]: {} is not an admin.".format(chan,nick)) return
def gadmin(inp, notice=None, bot=None, config=None, db=None): "gadmin <add|del> <nick|host> -- Make <nick|host> an global admin." \ "(you can delete multiple admins at once)" inp = inp.lower() command = inp.split()[0] targets = inp.split()[1:] if 'add' in command: for target in targets: target = user.get_hostmask(target, db) if target in bot.config["admins"]: notice(u"%s is already a global admin." % target) else: notice(u"%s is now a global admin." % target) bot.config["admins"].append(target) bot.config["admins"].sort() json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2) return elif 'del' in command: for target in targets: target = user.get_hostmask(target, db) if target in bot.config["admins"]: notice(u"%s is no longer a global admin." % target) bot.config["admins"].remove(target) bot.config["admins"].sort() json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2) else: notice(u"%s is not a global admin." % target) return
def admin(inp, notice=None, bot=None, chan=None, db=None): """admin [channel] <add|del> <nick|host> -- Makes the user an admin.""" admins = database.get(db, "channels", "admins", "chan", chan) channel = chan.lower() command = inp.split()[0] nicks = inp.split()[1:] if "add" in command: for nick in nicks: nick = user.get_hostmask(nick, db) if admins and nick in admins: notice(u"[{}]: {} is already an admin.".format(chan, nick)) else: admins = "{} {}".format(nick, admins).replace("False", "").strip() database.set(db, "channels", "admins", admins, "chan", chan) notice(u"[{}]: {} is now an admin.".format(chan, nick)) elif "del" in command: if "*" in nicks: database.set(db, "channels", "admins", "", "chan", chan) notice(u"[{}]: All admins have been removed.".format(chan)) else: for nick in nicks: nick = user.get_hostmask(nick, db) if admins and nick in admins: admins = " ".join(admins.replace(nick, "").strip().split()) database.set(db, "channels", "admins", admins, "chan", chan) notice(u"[{}]: {} is no longer an admin.".format(chan, nick)) else: notice(u"[{}]: {} is not an admin.".format(chan, nick)) return
def autoop(inp, notice=None, bot=None, chan=None, db=None): """aop [channel] <enable|disable> OR <add|del> <nick|host> -- Add/Del Autoops.""" autoops = database.get(db, 'channels', 'autoops', 'chan', chan) channel = chan.lower() command = inp.split()[0] if 'enable' in command: database.set(db, 'channels', 'autoop', True, 'chan', chan) notice(u"[{}]: Autoops is now enabled.".format(chan)) elif 'disable' in command: database.set(db, 'channels', 'autoop', False, 'chan', chan) notice(u"[{}]: Autoops is now disabled.".format(chan)) elif 'add' in command: nicks = inp.split()[1:] for nick in nicks: nick = user.get_hostmask(nick, db) if autoops and nick in autoops: notice(u"[{}]: {} is already an autoop.".format(chan, nick)) else: autoops = '{} {}'.format(nick, autoops).replace('False', '').strip() database.set(db, 'channels', 'autoops', autoops, 'chan', chan) notice(u"[{}]: {} is now an auto op.".format(chan, nick)) elif 'del' in command: nicks = inp.split()[1:] for nick in nicks: nick = user.get_hostmask(nick, db) if autoops and nick in autoops: autoops = " ".join(autoops.replace(nick, '').strip().split()) database.set(db, 'channels', 'autoops', autoops, 'chan', chan) notice(u"[{}]: {} is no longer an auto op.".format(chan, nick)) else: notice(u"[{}]: {} is not an auto op.".format(chan, nick)) return
def ban(inp, conn=None, chan=None, notice=None, db=None, nick=None): """ban [channel] <user> [reason] [timer] -- Makes the bot ban <user> in [channel]. If [channel] is blank the bot will ban <user> in the channel the command was used in.""" mode = "+b" reason = "#rekt" inp,chan = get_chan(inp,chan) split = inp.split(" ") inp_nick = split[0] if conn.nick in inp_nick or 'infinity' in inp_nick: target = nick reason = "Youre silly onii-chan." conn.send(u"KICK {} {} :{}".format(chan, target, reason)) return if len(split) > 1: reason = " ".join(split[1:]) target = user.get_hostmask(inp_nick,db) if '@' in target and not '!' in target: target = '*!*{}'.format(target) timer = scheduler.check_for_timers(inp) if timer > 0: reason = "{} Come back in {} seconds!!!".format(reason,timer) notice(u"Attempting to ban {} in {}...".format(nick, chan)) conn.send(u"MODE {} {} {}".format(chan, mode, target)) conn.send(u"KICK {} {} :{}".format(chan, inp_nick, reason)) if timer > 0: notice(u"{} will be unbanned in {} seconds".format(target, timer)) scheduler.schedule(timer, 1, "MODE {} -b {}".format(chan, target), conn) #scheduler.schedule(timer, 2, "PRIVMSG ChanServ :unban {} {}".format(channel, nick), conn) else: banlist = database.get(db,'channels','bans','chan',chan) banlist = '{} {}'.format(target,banlist).replace('False','').strip() database.set(db,'channels','bans',banlist,'chan',chan) return
def host(inp, nick=None, conn=None, db=None): if not inp: return 'Your host is ' + user.get_hostmask(nick, db) db_host = database.get(db, 'users', 'mask', 'nick', inp) if inp is db_host: db_host = database.get(db, 'seen', 'host', 'name', inp) return "{}: {}".format(inp, db_host)
def ignore(inp, notice=None, bot=None, chan=None, db=None): """ignore [channel] <nick|host> -- Makes the bot ignore <nick|host>.""" ignorelist = database.get(db, 'channels', 'ignored', 'chan', chan) targets = inp.split() for target in targets: target = user.get_hostmask(target, db) if (user.is_admin(target, chan, db, bot)): notice( u"[{}]: {} is an admin and cannot be ignored.".format( chan, inp)) else: if ignorelist and target in ignorelist: notice(u"[{}]: {} is already ignored.".format(chan, target)) else: ignorelist = '{} {}'.format(target, ignorelist) database.set( db, 'channels', 'ignored', ignorelist, 'chan', chan) notice(u"[{}]: {} has been ignored.".format(chan, target)) return
def process_vote(target,action,chan,mask,db,notice,conn): if ' ' in target: notice('Invalid nick') return try: votes2kick = database.get(db,'channels','votekick','chan',chan) except: votes2kick = 10 try: votes2ban = database.get(db,'channels','voteban','chan',chan) except: votes2ban = 10 if len(target) is 0: if action is 'kick': notice('Votes required to kick: {}'.format(votes2kick)) elif action is 'ban': notice('Votes required to ban: {}'.format(votes2ban)) return votefinished = False global db_ready if not db_ready: db_init(db) chan = chan.lower() target = target.lower() voter = user.format_hostmask(mask) oters = db.execute("SELECT voters FROM votes where chan='{}' and action='{}' and target like '{}'".format(chan,action,target)).fetchone() if conn.nick.lower() in target: return "I dont think so Tim." if voters: voters = voters[0] if voter in voters: notice("You have already voted.") return else: voters = '{} {}'.format(voters,voter).strip() notice("Thank you for your vote!") else: voters = voter votecount = len(voters.split(' ')) if 'kick' in action: votemax = int(votes2kick) if votecount >= votemax: votefinished = True conn.send("KICK {} {} :{}".format(chan, target, "You have been voted off the island.")) if 'ban' in action: votemax = int(votes2ban) if votecount >= votemax: votefinished = True conn.send("MODE {} +b {}".format(chan, user.get_hostmask(target,db))) conn.send("KICK {} {} :".format(chan, target, "You have been voted off the island.")) if votefinished: db.execute("DELETE FROM votes where chan='{}' and action='{}' and target like '{}'".format(chan,action,target)) else: db.execute("insert or replace into votes(chan, action, target, voters, time) values(?,?,?,?,?)", (chan, action, target, voters, time.time())) db.commit() return ("Votes to {} {}: {}/{}".format(action, target, votecount,votemax))
def match(inp,nick=None,chan=None,bot=None,input=None,db=None): if inp: mask = user.get_hostmask(inp,db) else: mask = input.mask # hostmask = format_hostmask(mask) channeladmin = user.is_channeladmin(mask, chan, db) globaladmin = user.is_globaladmin(mask, chan, bot) if channeladmin and globaladmin: return "Global & Local Admin: ({})".format(mask) elif channeladmin: return "Local Admin: {}".format(mask) elif globaladmin: return "Global Admin: {}".format(mask) return '{}: is not an admin'.format(mask)
def unignore(inp, notice=None, bot=None, chan=None, db=None): """unignore [channel] <nick|host> -- Makes the bot listen to <nick|host>.""" ignorelist = database.get(db,'channels','ignored','chan',chan) targets = inp.split() for target in targets: target = user.get_hostmask(target,db) if ignorelist and target in ignorelist: ignorelist = " ".join(ignorelist.replace(target,'').strip().split()) database.set(db,'channels','ignored',ignorelist,'chan',chan) notice(u"[{}]: {} has been unignored.".format(chan,target)) else: notice(u"[{}]: {} is not ignored.".format(chan,target)) return
def gunignore(inp, notice=None, bot=None, chan=None, db=None): """unignore [channel] <nick|host> -- Makes the bot listen to <nick|host>.""" ignorelist = bot.config["ignored"] targets = inp.split() for target in targets: target = user.get_hostmask(target,db) if ignorelist and target in ignorelist: bot.config["ignored"].remove(target) bot.config["ignored"].sort() json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2) notice("[Global]: {} has been unignored.".format(target)) else: notice("[Global]: {} is not ignored.".format(target)) return
def ban(inp, conn=None, chan=None, notice=None, db=None, nick=None, bot=None): ''' ban [channel] <user> [reason] [timer] Makes the bot ban <user> in [channel]. If [channel] is blank the bot will ban <user> in the channel the command was used in. ''' mode = "+b" reason = "#rekt" # inp,chan = get_chan(inp,chan) split = inp.split(" ") inp_nick = split[0] if conn.nick in inp_nick or bot.config['owner'] == inp_nick: target = nick reason = "Your attitude is not conducive to the desired environment" conn.send(u"KICK {} {} :{}".format(chan, target, reason)) return if len(split) > 1: reason = " ".join(split[1:]) if '@' not in inp_nick: target = user.get_hostmask(inp_nick, db) else: target = inp_nick if '@' in target and '!' not in target: target = '*!*{}'.format(target) timer = scheduler.check_for_timers(inp) if timer > 0: reason = "{} Come back in {} seconds!!!".format(reason, timer) notice(u"Attempting to ban {} in {}...".format(target, chan)) conn.send(u"MODE {} {} {}".format(chan, mode, target)) conn.send(u"KICK {} {} :{}".format(chan, inp_nick, reason)) if timer > 0: notice(u"{} will be unbanned in {} seconds".format(target, timer)) scheduler.schedule( timer, 1, "MODE {} -b {}".format(chan, target), conn) # scheduler.schedule(timer, 2, # "PRIVMSG ChanServ :unban {} {}".format(channel, # nick), # conn) else: banlist = database.get(db, 'channels', 'bans', 'chan', chan) banlist = '{} {}'.format(target, banlist).replace('False', '').strip() database.set(db, 'channels', 'bans', banlist, 'chan', chan) return
def unban(inp, conn=None, chan=None, notice=None, db=None): """unban [channel] <user> -- Makes the bot unban <user> in [channel]. If [channel] is blank the bot will unban <user> in the channel the command was used in.""" #mode_cmd("-b", "unban", inp, chan, conn, notice) inp,chan = get_chan(inp,chan) split = inp.split(" ") nick = split[0] target = user.get_hostmask(nick,db) if '@' in target and not '!' in target: target = '*!*{}'.format(target) notice(u"Attempting to unban {} in {}...".format(nick, chan)) conn.send(u"MODE {} -b {}".format(chan, target)) banlist = database.get(db,'channels','bans','chan',chan) banlist = " ".join(banlist.replace(target,'').strip().split()) database.set(db,'channels','bans',banlist,'chan',chan) return
def ignore(inp, notice=None, bot=None, chan=None, db=None): """ignore [channel] <nick|host> -- Makes the bot ignore <nick|host>.""" ignorelist = database.get(db,'channels','ignored','chan',chan) targets = inp.split() for target in targets: target = user.get_hostmask(target,db) if (user.is_admin(target,chan,db,bot)): notice(u"[{}]: {} is an admin and cannot be ignored.".format(chan,inp)) else: if ignorelist and target in ignorelist: notice(u"[{}]: {} is already ignored.".format(chan, target)) else: ignorelist = '{} {}'.format(target,ignorelist) database.set(db,'channels','ignored',ignorelist,'chan',chan) notice(u"[{}]: {} has been ignored.".format(chan,target)) return
def gignore(inp, notice=None, bot=None, chan=None, db=None): """gignore <nick|host> -- Makes the bot ignore nick|host.""" ignorelist = bot.config["ignored"] targets = inp.split() for target in targets: target = user.get_hostmask(target,db) if (user.is_globaladmin(target,db,bot)): notice("[Global]: {} is an admin and cannot be ignored.".format(inp)) else: if ignorelist and target in ignorelist: notice("[Global]: {} is already ignored.".format(target)) else: bot.config["ignored"].append(target) bot.config["ignored"].sort() json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2) notice("[Global]: {} has been ignored.".format(target)) return
def gunignore(inp, notice=None, bot=None, chan=None, db=None): """unignore [channel] <nick|host> -- Makes the bot listen to <nick|host>.""" ignorelist = bot.config["ignored"] targets = inp.split() for target in targets: target = user.get_hostmask(target, db) if ignorelist and target in ignorelist: bot.config["ignored"].remove(target) bot.config["ignored"].sort() json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2) notice(u"[Global]: {} has been unignored.".format(target)) else: notice(u"[Global]: {} is not ignored.".format(target)) return
def unban(inp, conn=None, chan=None, notice=None, db=None): """unban [channel] <user> -- Makes the bot unban <user> in [channel]. If [channel] is blank the bot will unban <user> in the channel the command was used in.""" #mode_cmd("-b", "unban", inp, chan, conn, notice) # inp,chan = get_chan(inp,chan) split = inp.split(" ") nick = split[0] if not '@' in nick: target = user.get_hostmask(nick, db) else: target = nick if '@' in target and not '!' in target: target = '*!*{}'.format(target) notice(u"Attempting to unban {} in {}...".format(target, chan)) conn.send(u"MODE {} -b {}".format(chan, target)) banlist = database.get(db, 'channels', 'bans', 'chan', chan) banlist = " ".join(banlist.replace(target, '').strip().split()) database.set(db, 'channels', 'bans', banlist, 'chan', chan) return
def rquote(inp, db=None, notice=None, nick=None, bot=None, reply=None): """rquote <nick> <number/*> - Deletes a quote from a nick""" target = inp.split(' ')[0] if nick != target: if user.is_globaladmin(user.get_hostmask(nick, db), nick, bot): pass else: notice('You can only remove your own quotes.') return num = inp.split(' ')[1] if num == '*': tmp = 0 while True: if 'No quotes found for' in get_quote_by_nick(db, target, tmp): return reply('Removing: {}'.format(get_quote_by_nick(db, target, tmp).encode('UTF-8')).decode('UTF-8')) del_quote(db, target, tmp) time.sleep(0.5) else: notice(del_quote(db, target, num))
def gignore(inp, notice=None, bot=None, chan=None, db=None): """gignore <nick|host> -- Makes the bot ignore nick|host.""" ignorelist = bot.config["ignored"] targets = inp.split() for target in targets: target = user.get_hostmask(target, db) if (user.is_globaladmin(target, db, bot)): notice( u"[Global]: {} is an admin and cannot be ignored.".format(inp)) else: if ignorelist and target in ignorelist: notice(u"[Global]: {} is already ignored.".format(target)) else: bot.config["ignored"].append(target) bot.config["ignored"].sort() json.dump(bot.config, open('config', 'w'), sort_keys=True, indent=2) notice(u"[Global]: {} has been ignored.".format(target)) return
def ban(inp, conn=None, chan=None, notice=None, db=None, nick=None, bot=None): """ban [channel] <user> [reason] [timer] -- Makes the bot ban <user> in [channel]. If [channel] is blank the bot will ban <user> in the channel the command was used in.""" mode = "+b" reason = "#rekt" # inp,chan = get_chan(inp,chan) split = inp.split(" ") inp_nick = split[0] if conn.nick in inp_nick or bot.config['owner'] == inp_nick: target = nick reason = "Your attitude is not conducive to the desired environment" conn.send(u"KICK {} {} :{}".format(chan, target, reason)) return if len(split) > 1: reason = " ".join(split[1:]) if not '@' in inp_nick: target = user.get_hostmask(inp_nick, db) else: target = inp_nick if '@' in target and not '!' in target: target = '*!*{}'.format(target) timer = scheduler.check_for_timers(inp) if timer > 0: reason = "{} Come back in {} seconds!!!".format(reason, timer) notice(u"Attempting to ban {} in {}...".format(target, chan)) conn.send(u"MODE {} {} {}".format(chan, mode, target)) conn.send(u"KICK {} {} :{}".format(chan, inp_nick, reason)) if timer > 0: notice(u"{} will be unbanned in {} seconds".format(target, timer)) scheduler.schedule(timer, 1, "MODE {} -b {}".format(chan, target), conn) #scheduler.schedule(timer, 2, "PRIVMSG ChanServ :unban {} {}".format(channel, nick), conn) else: banlist = database.get(db, 'channels', 'bans', 'chan', chan) banlist = '{} {}'.format(target, banlist).replace('False', '').strip() database.set(db, 'channels', 'bans', banlist, 'chan', chan) return
def rquote(inp, db=None, notice=None, nick=None, bot=None, reply=None): """rquote <nick> <number/*> - Deletes a quote from a nick""" target = inp.split(' ')[0] if nick != target: if user.is_globaladmin(user.get_hostmask(nick, db), nick, bot): pass else: notice('You can only remove your own quotes.') return num = inp.split(' ')[1] if num == '*': tmp = 0 while True: if 'No quotes found for' in get_quote_by_nick(db, target, tmp): return reply('Removing: {}'.format( get_quote_by_nick(db, target, tmp).encode('UTF-8')).decode('UTF-8')) del_quote(db, target, tmp) time.sleep(0.5) else: notice(del_quote(db, target, num))
def fhost(inp, nick=None, conn=None, db=None): if not inp: inp = nick return user.get_hostmask(inp, db)
def fhost(inp, nick=None, conn=None, db=None): if not inp: inp = nick return user.get_hostmask(inp,db)
def process_vote(target, action, chan, mask, db, notice, conn): if ' ' in target: notice('Invalid nick') return try: votes2kick = database.get(db, 'channels', 'votekick', 'chan', chan) except: votes2kick = 10 try: votes2ban = database.get(db, 'channels', 'voteban', 'chan', chan) except: votes2ban = 10 if len(target) is 0: if action is 'kick': notice('Votes required to kick: {}'.format(votes2kick)) elif action is 'ban': notice('Votes required to ban: {}'.format(votes2ban)) return votefinished = False global db_ready if not db_ready: db_init(db) chan = chan.lower() target = target.lower() voter = user.format_hostmask(mask) oters = db.execute( "SELECT voters FROM votes where chan='{}' and action='{}' and target like '{}'" .format(chan, action, target)).fetchone() if conn.nick.lower() in target: return "I dont think so Tim." if voters: voters = voters[0] if voter in voters: notice("You have already voted.") return else: voters = '{} {}'.format(voters, voter).strip() notice("Thank you for your vote!") else: voters = voter votecount = len(voters.split(' ')) if 'kick' in action: votemax = int(votes2kick) if votecount >= votemax: votefinished = True conn.send("KICK {} {} :{}".format( chan, target, "You have been voted off the island.")) if 'ban' in action: votemax = int(votes2ban) if votecount >= votemax: votefinished = True conn.send("MODE {} +b {}".format(chan, user.get_hostmask(target, db))) conn.send("KICK {} {} :".format( chan, target, "You have been voted off the island.")) if votefinished: db.execute( "DELETE FROM votes where chan='{}' and action='{}' and target like '{}'" .format(chan, action, target)) else: db.execute( "insert or replace into votes(chan, action, target, voters, time) values(?,?,?,?,?)", (chan, action, target, voters, time.time())) db.commit() return ("Votes to {} {}: {}/{}".format(action, target, votecount, votemax))