def handle(message, client): response = "Roles for {}:\n".format(message.author.name) for role in message.author.roles: # replace @s so we don't spam everyone with pings r_name = role.name.replace('@', '(at)') response += "{} - {}\n".format(role.id, r_name) reply(client, message, response)
def handle_let(message, client): global strings args = message.content[4:].strip() # Register new custom command if '->' in args: args = args.split("->", 1) new_custom_cmd = args[0].strip() if len(new_custom_cmd) < 1: post = "Missing command name for new custom command." else: # Prepend '!' if necessary if not new_custom_cmd.startswith('!'): new_custom_cmd = '!' + new_custom_cmd if len(args) < 2 or len(args[1]) < 1: post = "Missing command body for new custom command." else: register_command(new_custom_cmd, args[1].strip()) post = "Registered custom command: " + new_custom_cmd # Delete existing custom command elif args.startswith('delete'): args = args.split(" ") if len(args) < 2: post = "Missing an argument." else: custom_cmd = args[1] # Prepend ! if necessary if not custom_cmd.startswith('!'): custom_cmd = '!' + custom_cmd if custom_cmd in strings.keys(): delete_command(custom_cmd) post = "Deleted custom command: " + custom_cmd else: post = "Custom command '{}' not found.".format(custom_cmd) # List custom commands elif args.startswith('list'): post = '' for custom_cmd, string in strings.items(): post += "{} -> {}\n".format(custom_cmd, string) # Unknown subcommand else: post = "Unknown subcommand." logger.info("Rejected command: " + message.content) # Respond reply(client, message, post)
def handle(message, client): args = message.content[7:] thera_dist = evescout.query_thera_distance(args) jumps = 0 try: for thera_hole in thera_dist: if jumps == 0 or thera_hole["jumps"] < jumps: jumps = thera_hole["jumps"] reply(client, message, "The closest hole to Thera is **{}** jumps from {}".format(jumps, args)) except KeyError: reply(client, message, "Invalid solar system")
def handle(message, client): args = message.content[5:] try: char_id = eve_xml.get_entity_id_for_name(args) zkb_stats = zkb.query_character_stats(char_id) msg = "\n{} [{} - {}] \n{} \n{}".format( zkb_stats['info']['name'], zkb_stats['shipsDestroyed'], zkb_stats['shipsLost'], eve_xml.get_entity_name(zkb_stats['info']['corporationID']), eve_xml.get_entity_name(zkb_stats['info']['allianceID'])) client.send_message(message.channel, msg) except TypeError: reply(client, message, "\nDid not find your dude. " "\nEnter a dude who's bad enough to be found. ")
def handle(message, client): global strings # Default module action if message.content.startswith('!let'): # check permissions if may_let(message): handle_let(message, client) else: reply(client, message, "Access denied.") # The special poop command elif message.content.startswith('!poop'): if message.author.name == 'Ipoopedbad Ernaga': post = "Narcissist" else: post = "{} and Poop are friends.".format(message.author.mention()) reply(client, message, post) # Execute existing custom command else: for cmd, string in strings.items(): if message.content.startswith(cmd): post = parse(message, client, string) reply(client, message, post)
def handle_load_module(message): module_name = message.content[6:].strip() try: load_module(modules, module_name) reply(client, message, "(Re)Loaded module '{}'".format(module_name)) logger.info("(Re)Loaded module '%s'", module_name) except ImportError as e: reply(client, message, "Module hotload failed: " + str(e)) logger.error("Module '%s' hotload failed: %s", module_name, repr(e)) except ModuleInitError as e: reply(client, message, "Module '{}' failed to initialize".format(module_name)) logger.error("Module '%s' failed to initialize: %s", module_name, repr(e)) except Exception as e: reply(client, message, "Unexpected error during module hotload: " + repr(e)) logger.error("Module '%s' hotload encountered an unexpected error: %s", module_name, str(e))
def on_message(message): if message.author == client.user: return # # Module commands # handled_by_module = False for c, m in modules.items(): if message.content.startswith(c): m.handle(message, client) handled_by_module = True # # Global commands # if handled_by_module: return # elif message.content.startswith('!help'): # for _, m in modules.items(): # m.help() elif message.content.startswith('Are you there?'): reply(client, message, "Yes, yes I am. No worries. Everything is fine.") # This needed to be done. With updated responses! elif message.content.startswith('!poop'): if message.author.name == 'Ipoopedbad Ernaga': post = "Narcissist" else: post = "{} and Poop are friends."\ .format(message.author.mention()) reply(client, message, post) elif message.content.startswith('!ping'): reply(client, message, "We're not doing this again.") elif message.content.startswith('!trivia'): post = "F**k you, {}. Blame Fenrir."\ .format(message.author.mention()) reply(client, message, post)
def handle_unload_module(message): module_name = message.content[8:].strip() try: unload_module(modules, module_name) logger.info("Module '%s' unloaded", module_name) reply(client, message, "Module '{}' unloaded".format(module_name)) except ModuleNotLoadedError: reply(client, message, "Module '{}' not present".format(module_name)) logger.error("Module '%s' not loaded", module_name) except Exception as e: reply(client, message, "Module '{}' failed to unload".format(module_name)) logger.error("Module '%s' failed to unload: %s", module_name, repr(e))
def on_message(message): if message.author == client.user: return # # Global commands # if message.content.startswith('Are you there?'): reply(client, message, "Yes, yes I am. No worries. Everything is fine.") # elif message.content.startswith('!help'): # for _, m in modules.items(): # m.help() elif message.content.startswith('!load'): if message.author.id in admins: handle_load_module(message) else: reply(client, message, "Access denied.") elif message.content.startswith('!unload'): if message.author.id in admins: handle_unload_module(message) else: reply(client, message, "Access denied.") # # Module commands # else: # 1 Command = 1 Module # Modules have priority over custom commands handled_by_module = False for c, m in modules.items(): if message.content.startswith('!' + c): m.handle(message, client) handled_by_module = True # Fallthrough for custom commands handled by the 'let' module if not handled_by_module and is_loaded(modules, 'let') and message.content.startswith('!'): modules['let'].handle(message, client)
def handle(message, client): reply(client, message, "This channel's ID is **{}**".format(message.channel.id))