def on_message_delete(message): billy_c_stats.update_msg_deletion(message) content = sh.rm_leading_quotes(message) if message.author == client.user or not message.server or not re.match( client.command_prefix, content): return sh.debug("User message deleted: " + message.content, message) for log in reversed( list((yield from client.logs_from(message.channel, limit=50, after=message)))): if log.author != client.user or not log.content.startswith( "<@!" + message.author.id + ">:"): continue sh.debug("Found a message to delete: " + log.content, message) yield from client.delete_message(log) return sh.debug("No matching bot response found")
def parse_message(message, edited=False): #if not edited: # billy_c_stats.insert_msg(message) # Track used emojis #emoji_list = list(c for c in message.clean_content if c in emoji.UNICODE_EMOJI) or [] #custom_emoji_list = re.findall(r"<:\S+?:\d+>", message.clean_content, re.IGNORECASE) or [] #billy_c_stats.insert_emojis_post(message, emoji_list, custom_emoji_list, edited) # ignore bot messages if message.author == client.user: return perm = af.check_channel_whitelist(client, message) # channel blacklisted if perm["disallow"]: return # strip quotes content = unidecode.unidecode(sh.rm_leading_quotes(message)) if not edited: # fulltext search for f in f_functions: c = getattr(f, "command", False) p = getattr(f, "prob", False) if c and p and re.search(c, content, re.IGNORECASE) and ( p >= 1.0 or (perm["fulltext"] and random.random() < p)): sh.debug("Triggered " + f.__name__ + "...") try: yield from f(client, message) except Exception: print_warning("An error occured in " + f.__name__ + "!!! (" + content + ")") raise # commands if re.match(client.command_prefix, content): sh.debug("This seems to be a command: " + sh.get_command(message)) # check antiflood if perm["flood"] and ( (yield from af.check_flood_channel(client, message)) or (yield from af.check_flood(client, message))): sh.debug("Anti-flood kicked in yo") return # help if re.match(compile_command(r"(help|pomoc)"), content, re.IGNORECASE): sh.debug("What a noob") ret = "Witam witam, z tej strony Billy Mays z kolejnym fantastycznym produktem!\nDozwolone przedrostki funkcji: . , \ / ! ;\n\n" for f in c_functions: desc = getattr(f, "desc", False) if hasattr(f, "rhyme") or desc == "hidden": continue command = getattr(f, "command", False) ret += "." + getattr(f, "command") params = getattr(f, "params", False) if params: for p in params: ret += " [" + p + "]" if desc: ret += " - " + desc ret += "\n" ret += "\nRymy i inne bzdety: .rymy" ret += "\nZadzwoń teraz, a podwoimy ofertę!" if len(ret) > 2000: n = 40 groups = ret.split("\n") help = ["\n".join(groups[:n]), "\n".join(groups[n:])] else: help = [ret] for m in help: yield from client.send_message(message.channel, m) elif re.match(compile_command(r"(rymy|rhymes)"), content, re.IGNORECASE): sh.debug("What an utter pillock") ret = "Rymy i inne bzdety:\n" for f in c_functions: if not hasattr(f, "rhyme"): continue command = getattr(f, "command", False) ret += "." + getattr(f, "command") + "\n" yield from client.send_message(message.channel, ret[:-1]) else: # iterate over functions for f in c_functions: c = getattr(f, "command", False) r = re.match(compile_command(c), content, re.IGNORECASE) if c and r: sh.debug("Executing " + f.__name__ + "...") yield from client.send_typing(message.channel) try: yield from f(client, message) #billy_c_stats.update_msg_function(message, f.__name__) except Exception: yield from client.send_message( message.channel, "Oho, chyba jakiś błąd w kodzie. <@307949259658100736> to kiedyś naprawi, jak się skończy bawić pociągami." ) print_warning("An error occured in " + f.__name__ + "!!! (" + content + ")") #CZEMU TY CHUJU NIE DZIALASZ #logging.exception("An error occured in " + f.__name__ + "!!! (" + content + ")") raise continue break
def parse_message(message, edited=False): if not edited: billy_c_stats.insert_msg(message) # Track used emojis emoji_list = list( c for c in message.clean_content if c in emoji.UNICODE_EMOJI) or [] custom_emoji_list = re.findall(r"<:\S+?:\d+>", message.clean_content, re.IGNORECASE) or [] billy_c_stats.insert_emojis_post(message, emoji_list, custom_emoji_list, edited) # ignore bot messages if message.author == client.user: return perm = af.check_channel_whitelist(client, message) # channel blacklisted if perm["disallow"]: return # strip quotes content = sh.rm_leading_quotes(message) if not edited: # fulltext search for f in f_functions: c = getattr(f, "command", False) p = getattr(f, "prob", False) if c and p and re.search(c, content, re.IGNORECASE) and ( p >= 1.0 or (perm["fulltext"] and random.random() < p)): sh.debug("Triggered " + f.__name__ + "...") try: yield from f(client, message) except Exception: print_warning("An error occured in " + f.__name__ + "!!! (" + content + ")") raise # commands if re.match(client.command_prefix, content): sh.debug("This seems to be a command: " + sh.get_command(message)) # check antiflood #if perm["flood"] and ((yield from af.check_flood_channel(client, message)) or (yield from af.check_flood(client, message))): # sh.debug("Anti-flood kicked in yo") # return # help # not needed here #else: # iterate over functions for f in c_functions: c = getattr(f, "command", False) r = re.match(compile_command(c), content, re.IGNORECASE) if c and r: sh.debug("Executing " + f.__name__ + "...") yield from client.send_typing(message.channel) try: yield from f(client, message) billy_c_stats.update_msg_function(message, f.__name__) except Exception: yield from client.send_message( message.channel, "Oho, chyba jakiś błąd w kodzie. <@307949259658100736> to kiedyś naprawi, jak się skończy bawić pociągami." ) print_warning("An error occured in " + f.__name__ + "!!! (" + content + ")") #CZEMU TY CHUJU NIE DZIALASZ #logging.exception("An error occured in " + f.__name__ + "!!! (" + content + ")") raise continue break
def on_message(message): #ignore bot messages if message.author == client.user: return perm = af.check_channel_whitelist(client, message) # channel blacklisted if perm["disallow"]: return # strip quotes content = sh.rm_leading_quotes(message) if perm["fulltext"]: # fulltext search for f in f_functions: c = getattr(f, "command", False) p = getattr(f, "prob", False) if c and p and re.search(c, content, re.IGNORECASE) and random.random() < p: sh.debug("Triggered " + f.__name__ + "...") try: yield from f(client, message) except Exception: print("An error occured in " + f.__name__ + "!!! (" + content + ")") raise continue # commands if re.match(client.command_prefix, content): sh.debug("This seems to be a command: " + sh.get_command(message)) # check antiflood if perm["flood"] and ( (yield from af.check_flood_channel(client, message)) or (yield from af.check_flood(client, message))): sh.debug("Anti-flood kicked in yo") return # help if re.match(compile_command(r"(help|pomoc)"), content, re.IGNORECASE): sh.debug("What a noob") ret = "Witam witam, z tej strony Billy Mays z kolejnym fantastycznym produktem!\nDozwolone przedrostki funkcji: . , \ / !\n\n" for f in c_functions: desc = getattr(f, "desc", False) if hasattr(f, "rhyme") or desc == "hidden": continue command = getattr(f, "command", False) ret += "." + getattr(f, "command") params = getattr(f, "params", False) if params: for p in params: ret += " [" + p + "]" if desc: ret += " - " + desc ret += "\n" ret += "\nRymy i inne bzdety: .rymy" ret += "\nZadzwoń teraz, a podwoimy ofertę!" yield from client.send_message(message.channel, ret) elif re.match(compile_command(r"(rymy|rhymes)"), content, re.IGNORECASE): sh.debug("What an utter pillock") ret = "Rymy i inne bzdety:\n" for f in c_functions: if not hasattr(f, "rhyme"): continue command = getattr(f, "command", False) ret += "." + getattr(f, "command") + "\n" yield from client.send_message(message.channel, ret[:-1]) else: # iterate over functions for f in c_functions: c = getattr(f, "command", False) r = re.match(compile_command(c), content, re.IGNORECASE) if c and r: sh.debug("Executing " + f.__name__ + "...") yield from client.send_typing(message.channel) try: yield from f(client, message) except Exception: yield from client.send_message( message.channel, "Oho, chyba jakiś błąd w kodzie. <@307949259658100736> to kiedyś naprawi, jak się skończy bawić pociągami." ) print("An error occured in " + f.__name__ + "!!! (" + content + ")") #CZEMU TY CHUJU NIE DZIALASZ #logging.exception("An error occured in " + f.__name__ + "!!! (" + content + ")") raise continue break return