def highlight_sieve(bot, input, func, kind, args): fn = re.match(r'^plugins.(.+).py$', func._filename) if fn.group(1) == 'seen' or \ fn.group(1) == 'tell' or\ fn.group(1) == 'ai' or \ fn.group(1) == 'core_ctcp': return input global userlist try: users = userlist[input.chan.lower().replace('#', '')] except: return input inp = set(re.sub('[#~&@+%,\.]', '', input.msg.lower()).split(' ')) if len(users & inp) > 3: globaladmin = user.is_globaladmin(input.mask, input.chan, bot) db = bot.get_db_connection(input.conn) channeladmin = user.is_channeladmin(input.mask, input.chan, db) if not globaladmin and not channeladmin: if len(users & inp) > 5: input.conn.send(u"MODE {} +b *!*{}".format( input.chan, user.format_hostmask(input.mask))) input.conn.send( u"KICK {} {} :MASSHIGHLIGHTING F****T GET #REKT".format( input.chan, input.nick)) return input
def highlight_sieve(bot, input, func, kind, args): fn = re.match(r'^plugins.(.+).py$', func._filename) if fn.group(1) == 'seen' or \ fn.group(1) == 'tell' or\ fn.group(1) == 'ai' or \ fn.group(1) == 'core_ctcp': return input global userlist try: users = userlist[input.chan.lower().replace('#', '')] except: return input inp = set(re.sub('[#~&@+%,\.]', '', input.msg.lower()).split(' ')) if len(users & inp) > 3: globaladmin = user.is_globaladmin(input.mask, input.chan, bot) db = bot.get_db_connection(input.conn) channeladmin = user.is_channeladmin(input.mask, input.chan, db) if not globaladmin and not channeladmin: if len(users & inp) > 5: s = u"MODE {} +b *!*{}" input.conn.send(s.format(input.chan, user.format_hostmask(input.mask))) s = u"KICK {} {} :MASSHIGHLIGHTING F****T GET #REKT" input.conn.send(s.format(input.chan, input.nick)) return input
def commands(inp, say=None, notice=None, input=None, conn=None, bot=None, db=None): "commands -- Gives a list of commands/help for a command." funcs = {} disabled = bot.config.get('disabled_plugins', []) disabled_comm = bot.config.get('disabled_commands', []) for command, (func, args) in bot.commands.iteritems(): fn = re.match(r'^plugins.(.+).py$', func._filename) if fn.group(1).lower() not in disabled and command not in disabled_comm: # Ignores disabled plugins and commands if args.get('channeladminonly', False) and not user.is_admin(input.mask, input.chan, db, bot): continue if args.get('adminonly', False) and not user.is_globaladmin(input.mask, input.chan, bot): continue if func.__doc__ is not None: if func in funcs: if len(funcs[func]) < len(command): funcs[func] = command else: funcs[func] = command commands = dict((value, key) for key, value in funcs.iteritems()) if not inp: output = [] well = [] line = [] help = "For detailed help, do '{}help <example>' where <example> "\ "is the name of the command you want help for.".format(conn.conf["command_prefix"]) for command in commands: well.append(command) well.sort() for command in well: if output == [] and line == []: line.append("Commands you have access to ({}): {}".format(len(well), str(command))) else: line.append(str(command)) if len(", ".join(line)) > 405: output.append(", ".join(line)) line = [] if len(line) > 0: output.append(", ".join(line)) if len(output) == 1: output.append(help) for line in output: notice(line) else: output = ", ".join(output) # print(output) print bot.config.get('api_keys', {}).get('pastebin') pastebin_vars = {'api_dev_key': bot.config.get('api_keys', {}).get('pastebin'), 'api_option': 'paste', 'api_paste_code': output} response = urllib.urlopen('http://pastebin.com/api/api_post.php', urllib.urlencode(pastebin_vars)) url = response.read() #haste = web.haste("{}\n\n{}".format(output, help)) notice("Commands you have access to ({}): {}".format(len(well), url)) elif inp in commands: notice("{}{}".format(conn.conf["command_prefix"], commands[inp].__doc__)) return
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 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 highlight_sieve(bot, input, func, kind, args): fn = re.match(r"^plugins.(.+).py$", func._filename) if fn.group(1) == "seen" or fn.group(1) == "tell" or fn.group(1) == "ai" or fn.group(1) == "core_ctcp": return input global userlist try: users = userlist[input.chan.lower().replace("#", "")] except: return input inp = set(re.sub("[#~&@+%,\.]", "", input.msg.lower()).split(" ")) if len(users & inp) > 3: globaladmin = user.is_globaladmin(input.mask, input.chan, bot) db = bot.get_db_connection(input.conn) channeladmin = user.is_channeladmin(input.mask, input.chan, db) if not globaladmin and not channeladmin: if len(users & inp) > 5: input.conn.send("MODE {} +b *!*{}".format(input.chan, user.format_hostmask(input.mask))) input.conn.send("KICK {} {} :MASSHIGHLIGHTING F****T GET #REKT".format(input.chan, input.nick)) return input
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 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 sieve_suite(bot, input, func, kind, args): global ledzep_counter global sudos_counter # ignore any input from the bot if input.nick == input.conn.nick: return None # print "Ignoring {}".format(input.conn.nick) if input.command == 'QUIT': return None #fix for db issue??? # ignore bots if ignorebots = true if input.command == 'PRIVMSG' and input.nick.lower().endswith('bot') and args.get('ignorebots', True): return None fn = re.match(r'^plugins.(.+).py$', func._filename) db = bot.get_db_connection(input.conn) # parse for different dest channel if kind == "command": try: if input.inp[0][0] == "#": if "join" in input.trigger or "part" in input.trigger: pass else: input.chan = input.inp.split(' ')[0] input.inp = input.inp.replace(input.chan,'').strip() except: pass chan = input.chan.lower() #if fn.group(1) == 'core_ctcp' : return input ### Disabled commands # ignore plugins disabled in the config # print input if fn and fn.group(1).lower() in bot.config.get('disabled_plugins', []): return None if fn and fn.group(1).lower() in bot.config.get('disabled_commands', []): print("[{}]: {} is disabled.".format(input.chan,fn.group(1))) return None #print 'fn: {} | fn.group: {}'.format(fn,fn.group(1)) # ignore plugins disabled in the channel disabled_commands = database.get(db,'channels','disabled','chan',chan) if disabled_commands and not fn.group(1).lower().strip() == 'log': # check for disabled modules if fn and re.search(r"\b{}\b".format(fn.group(1).lower().strip()), disabled_commands): if user.is_globaladmin(input.mask, chan, bot): print("[{}]: {} is disabled.".format(input.chan,fn.group(1))) return None # check for disabled commands if kind == "command" and re.search(r"\b{}\b".format(input.trigger.lower().strip()), disabled_commands): if user.is_globaladmin(input.mask, chan, bot): input.notice("[{}]: {} is disabled.".format(input.chan,input.trigger)) print("[{}]: {} is disabled.".format(input.chan,input.trigger)) return None # check for disabled regex if kind == "regex" and re.search(r"\b{}\b".format(func.__name__.lower().strip()), disabled_commands): if user.is_globaladmin(input.mask, chan, bot): print("[{}]: {} is disabled.".format(input.chan,func.__name__)) return None # print fn.group(1) # Return other Sieves if fn.group(1) == 'seen' or \ fn.group(1) == 'tell' or\ fn.group(1) == 'ai' or \ fn.group(1) == 'core_ctcp': return input # fn.group(1) == 'log': if 'ledzep' in input.nick.lower(): ledzep_counter+=input.msg.lower().count('tfw') if 'sudos' in input.nick.lower(): sudos_counter+=input.msg.lower().count('tfw') # CANT SOMEONE DISABLE SEEN OR LOG???? ### process global config options # process acls acl = bot.config.get('acls', {}).get(func.__name__) if acl: if 'deny-except' in acl: allowed_channels = map(unicode.lower, acl['deny-except']) if input.chan.lower() not in allowed_channels: return None if 'allow-except' in acl: denied_channels = map(unicode.lower, acl['allow-except']) if input.chan.lower() in denied_channels: return None # if not fn.group(1) == 'log': print fn.group(1) ### channel configs globaladmin = user.is_globaladmin(input.mask, chan, bot) if args.get('adminonly', False): if not globaladmin: return None if globaladmin: return input channeladmin = user.is_channeladmin(input.mask, chan, db) if args.get('channeladminonly', False): if not channeladmin and not globaladmin: return None if channeladmin: return input #badwords if not globaladmin and not channeladmin: badwordlist = database.get(db,'channels','badwords','chan',chan) if badwordlist: for badword in badwordlist.split(' '): if len(badword) > 2 and badword.lower() is not chan.lower() and badword.lower().strip() in input.msg.lower(): input.conn.send(u"KICK {} {} :{}".format(input.chan, input.nick, 'Used bad word: {}'.format(badword))) return #flood protection if not globaladmin and not channeladmin: if kind == "command": cmdflood_protection = database.get(db,'channels','cmdflood','chan',chan) if cmdflood_protection: cmdflood_num = cmdflood_protection.split(' ')[0] cmdflood_duration = cmdflood_protection.split(' ')[1] now = time.time() cmdflood = json.load(open(cmdflood_filename)) try: nick = cmdflood[input.nick] except: nick = [] cmdflood[input.nick] = nick cmdflood[input.nick].append(now) for x in cmdflood[input.nick]: if now - x > int(cmdflood_duration): cmdflood[input.nick].remove(x) json.dump(cmdflood, open(cmdflood_filename, 'w'), sort_keys=True, indent=2) if len(cmdflood[input.nick]) > (int(cmdflood_num)): input.notice("Flood detected. Please wait {} seconds.".format(cmdflood_duration)) return None elif kind == "event": if input.command == 'PRIVMSG': flood_protection = database.get(db,'channels','flood','chan',chan) if flood_protection: flood_num = (int(flood_protection.split(' ')[0]) * 1) flood_duration = flood_protection.split(' ')[1] now = time.time() flood = json.load(open(flood_filename)) try: nick = flood[input.nick] except: nick = [] flood[input.nick] = nick for x in flood[input.nick]: if now - x > int(flood_duration): flood[input.nick].remove(x) flood[input.nick].append(now) # print "%s / %s" % (flood_num,len(flood[input.nick])) if len(flood[input.nick]) == (int(flood_num)): input.conn.send("KICK {} {} #rekt".format(input.chan, input.nick)) flood[input.nick] = [] json.dump(flood, open(flood_filename, 'w'), sort_keys=True, indent=2) return None else: json.dump(flood, open(flood_filename, 'w'), sort_keys=True, indent=2) return input
def commands(inp, say=None, notice=None, input=None, conn=None, bot=None, db=None): "commands -- Gives a list of commands/help for a command." funcs = {} disabled = bot.config.get('disabled_plugins', []) disabled_comm = bot.config.get('disabled_commands', []) for command, (func, args) in bot.commands.iteritems(): fn = re.match(r'^plugins.(.+).py$', func._filename) if fn.group(1).lower( ) not in disabled and command not in disabled_comm: # Ignores disabled plugins and commands if args.get('channeladminonly', False) and not user.is_admin( input.mask, input.chan, db, bot): continue if args.get('adminonly', False) and not user.is_globaladmin( input.mask, input.chan, bot): continue if func.__doc__ is not None: if func in funcs: if len(funcs[func]) < len(command): funcs[func] = command else: funcs[func] = command commands = dict((value, key) for key, value in funcs.iteritems()) if not inp: output = [] well = [] line = [] help = "For detailed help, do '{}help <example>' where <example> "\ "is the name of the command you want help for.".format(conn.conf["command_prefix"]) for command in commands: well.append(command) well.sort() for command in well: if output == [] and line == []: line.append("Commands you have access to ({}): {}".format( len(well), str(command))) else: line.append(str(command)) if len(", ".join(line)) > 405: output.append(", ".join(line)) line = [] if len(line) > 0: output.append(", ".join(line)) if len(output) == 1: output.append(help) for line in output: notice(line) else: output = ", ".join(output) # print(output) print bot.config.get('api_keys', {}).get('pastebin') pastebin_vars = { 'api_dev_key': bot.config.get('api_keys', {}).get('pastebin'), 'api_option': 'paste', 'api_paste_code': output.encode('utf-8') } response = urllib.urlopen('http://pastebin.com/api/api_post.php', urllib.urlencode(pastebin_vars)) url = response.read() #haste = web.haste("{}\n\n{}".format(output, help)) notice("Commands you have access to ({}): {}".format( len(well), url)) elif inp in commands: notice("{}{}".format(conn.conf["command_prefix"], commands[inp].__doc__)) return
def sieve_suite(bot, input, func, kind, args): global ledzep_counter global sudos_counter # ignore any input from the bot if input.nick == input.conn.nick: return None # print "Ignoring {}".format(input.conn.nick) if input.command == 'QUIT': return None #fix for db issue??? # ignore bots if ignorebots = true if input.command == 'PRIVMSG' and input.nick.lower().endswith( 'bot') and args.get('ignorebots', True): return None fn = re.match(r'^plugins.(.+).py$', func._filename) db = bot.get_db_connection(input.conn) # parse for different dest channel if kind == "command": try: if input.inp[0][0] == "#": if "join" in input.trigger or "part" in input.trigger: pass else: input.chan = input.inp.split(' ')[0] input.inp = input.inp.replace(input.chan, '').strip() except: pass chan = input.chan.lower() #if fn.group(1) == 'core_ctcp' : return input ### Disabled commands # ignore plugins disabled in the config # print input if fn and fn.group(1).lower() in bot.config.get('disabled_plugins', []): return None if fn and fn.group(1).lower() in bot.config.get('disabled_commands', []): print("[{}]: {} is disabled.".format(input.chan, fn.group(1))) return None #print 'fn: {} | fn.group: {}'.format(fn,fn.group(1)) # ignore plugins disabled in the channel disabled_commands = database.get(db, 'channels', 'disabled', 'chan', chan) if disabled_commands and not fn.group(1).lower().strip() == 'log': # check for disabled modules if fn and re.search(r"\b{}\b".format(fn.group(1).lower().strip()), disabled_commands): if user.is_globaladmin(input.mask, chan, bot): print("[{}]: {} is disabled.".format(input.chan, fn.group(1))) return None # check for disabled commands if kind == "command" and re.search( r"\b{}\b".format(input.trigger.lower().strip()), disabled_commands): if user.is_globaladmin(input.mask, chan, bot): input.notice("[{}]: {} is disabled.".format( input.chan, input.trigger)) print("[{}]: {} is disabled.".format(input.chan, input.trigger)) return None # check for disabled regex if kind == "regex" and re.search( r"\b{}\b".format(func.__name__.lower().strip()), disabled_commands): if user.is_globaladmin(input.mask, chan, bot): print("[{}]: {} is disabled.".format(input.chan, func.__name__)) return None # print fn.group(1) # Return other Sieves if fn.group(1) == 'seen' or \ fn.group(1) == 'tell' or\ fn.group(1) == 'ai' or \ fn.group(1) == 'core_ctcp': return input # fn.group(1) == 'log': if 'ledzep' in input.nick.lower(): ledzep_counter += input.msg.lower().count('tfw') if 'sudos' in input.nick.lower(): sudos_counter += input.msg.lower().count('tfw') # CANT SOMEONE DISABLE SEEN OR LOG???? ### process global config options # process acls acl = bot.config.get('acls', {}).get(func.__name__) if acl: if 'deny-except' in acl: allowed_channels = map(unicode.lower, acl['deny-except']) if input.chan.lower() not in allowed_channels: return None if 'allow-except' in acl: denied_channels = map(unicode.lower, acl['allow-except']) if input.chan.lower() in denied_channels: return None # if not fn.group(1) == 'log': print fn.group(1) ### channel configs globaladmin = user.is_globaladmin(input.mask, chan, bot) if args.get('adminonly', False): if not globaladmin: return None if globaladmin: return input channeladmin = user.is_channeladmin(input.mask, chan, db) if args.get('channeladminonly', False): if not channeladmin and not globaladmin: return None if channeladmin: return input #badwords if not globaladmin and not channeladmin: badwordlist = database.get(db, 'channels', 'badwords', 'chan', chan) if badwordlist: for badword in badwordlist.split(' '): if len(badword) > 2 and badword.lower() is not chan.lower( ) and badword.lower().strip() in input.msg.lower(): input.conn.send(u"KICK {} {} :{}".format( input.chan, input.nick, 'Used bad word: {}'.format(badword))) return #flood protection if not globaladmin and not channeladmin: if kind == "command": cmdflood_protection = database.get(db, 'channels', 'cmdflood', 'chan', chan) if cmdflood_protection: cmdflood_num = cmdflood_protection.split(' ')[0] cmdflood_duration = cmdflood_protection.split(' ')[1] now = time.time() cmdflood = json.load(open(cmdflood_filename)) try: nick = cmdflood[input.nick] except: nick = [] cmdflood[input.nick] = nick cmdflood[input.nick].append(now) for x in cmdflood[input.nick]: if now - x > int(cmdflood_duration): cmdflood[input.nick].remove(x) json.dump(cmdflood, open(cmdflood_filename, 'w'), sort_keys=True, indent=2) if len(cmdflood[input.nick]) > (int(cmdflood_num)): input.notice( "Flood detected. Please wait {} seconds.".format( cmdflood_duration)) return None elif kind == "event": if input.command == 'PRIVMSG': flood_protection = database.get(db, 'channels', 'flood', 'chan', chan) if flood_protection: flood_num = (int(flood_protection.split(' ')[0]) * 1) flood_duration = flood_protection.split(' ')[1] now = time.time() flood = json.load(open(flood_filename)) try: nick = flood[input.nick] except: nick = [] flood[input.nick] = nick for x in flood[input.nick]: if now - x > int(flood_duration): flood[input.nick].remove(x) flood[input.nick].append(now) # print "%s / %s" % (flood_num,len(flood[input.nick])) if len(flood[input.nick]) == (int(flood_num)): input.conn.send("KICK {} {} #rekt".format( input.chan, input.nick)) flood[input.nick] = [] json.dump(flood, open(flood_filename, 'w'), sort_keys=True, indent=2) return None else: json.dump(flood, open(flood_filename, 'w'), sort_keys=True, indent=2) return input