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 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 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 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 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 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