async def exec_cmd(self, **kwargs): self.session = kwargs['session'] smart_commands = kwargs['smart_commands'] admins = kwargs['admins'] server = self.server from_admin = int(self.author.id) in admins[int(server.id)] botcommands = self.get_channel_by_name(server, 'bot-commands') if botcommands and botcommands[0] != self.channel and not from_admin: await self.client.send_message(self.channel, botcommands[0].mention + '?') return parser = re.search('!set (.+)::(.+)', self.content, re.IGNORECASE) if parser and len(parser.group(2)) <= 200 and len(parser.group( 1)) > 1 and server.default_role.mention not in parser.group( 2) or from_admin: try: command = smart_command(parser.group(1), parser.group(2), 0, server, self.author.id) except VaguePatternError as e: await self.client.send_message( self.channel, 'let\'s try making that a little more specific please') return if not any(command == oldcommand for oldcommand in smart_commands[ int(server.id)]) and not len(command.raw_trigger) == 0: smart_commands[int(server.id)].append(command) new_command = Command(server.id + command.raw_trigger, command.raw_response, command.count, int(server.id), self.author.id) self.session.add(new_command) self.session.commit() await self.client.send_message(self.channel, 'command set') return elif parser.group(2) == "remove" or parser.group(2) == " remove": for oldcommand in smart_commands[int(server.id)]: if oldcommand == command: smart_commands[int(server.id)].remove(oldcommand) self.update_command(oldcommand.raw_trigger, '', 0, server, self.author.id, delete=True) await self.client.send_message(self.channel, 'removed') return elif parser.group(2) == "list" or parser.group(2) == " list": for oldcommand in smart_commands[int(server.id)]: if oldcommand == command: await self.client.send_message(self.channel, str(oldcommand)) return await self.client.send_message(self.channel, 'no')
def initialize_commands(): command_list = session.query(Command).all() for server in client.servers: smart_commands.setdefault(int(server.id), []) #settings = server_settings(session, server) #settings.admins_ids = [JOHNYS_ID] #settings.bot_commands_channels = [] #print(settings.admins_ids) for command in command_list: smart_commands.setdefault(command.server_id, []) smart_commands[command.server_id].append(smart_command(command.trigger.replace(str(command.server_id), '', 1), command.response, command.count, client.get_server(str(command.server_id)), command.author_id)) for server, cmds in smart_commands.items(): smart_commands[server].sort()
def initialize_commands(): command_list = session.query(Command).all() for server in client.servers: smart_commands.setdefault(int(server.id), []) for command in command_list: smart_commands.setdefault(command.server_id, []) smart_commands[command.server_id].append( smart_command( command.trigger.replace(str(command.server_id), '', 1), command.response, command.count, client.get_server(str(command.server_id)), command.author_id)) for server, cmds in smart_commands.items(): smart_commands[server].sort()