예제 #1
0
파일: apps.py 프로젝트: siggame/server
 def command(**args):
     if self.game.current_player._connection != self:
         return {'type': 'failure',
                 'args': {'message': 'not your turn'}}
     if 'actor' not in args:
         command = getattr(self.game, command_name, None)
         if not command or not is_command(command):
             return {'type': 'error',
                 'args': {'message': 'global command %s does not exist' %
                     command_name
                     }}
     else:
         actor = self.game.objects.get(args['actor'], None)
         del args['actor']
         if not actor:
             return {'type': 'bad arguments',
                     'args': {'message': 'actor does not exist'}}
         command = getattr(actor, command_name, None)
         if not command or not is_command(command):
             return {'type': 'error',
                     'args': {'message': '%s does not have command %s' %
                         (actor.__class__.__name__, command_name)}}
     value = command(**args)
     self.game.flush()
     if not value:
         return {'type': 'success', 'args': {}}
     else:
         return value
예제 #2
0
    def text_message_received(self, origin, target, message):
        if is_command(message):
            self.handle_command(origin, message)

        else:
            self.bus.broadcast(self, origin.name, strip_html(message),
                               MsgType.TEXT)
예제 #3
0
    def on_message(self, message):
        sanitized_content = DiscordClient.fix_message(message)

        # If there are attached files, append them to the sanitized message
        if len(message.attachments):
            for attachment in message.attachments:
                sanitized_content += " {}".format(attachment['url'])

        # If there are embeds, append their URLs to the message
        if len(message.embeds):
            for embed in message.embeds:
                sanitized_content += " {}".format(embed['url'])

        # Replace those ugly custom emoji strings with the name of the emoji
        sanitized_content = re.sub('<:\S+:\d+>', DiscordClient.fix_emojis,
                                   sanitized_content)

        if message.channel.id == self.channel_id \
                and message.author != self.user:
            if is_command(sanitized_content):
                self.handle_command(message.author, sanitized_content)
            else:
                if message.author.nick:
                    self.bus.broadcast(
                        self, '{} ({})'.format(str(message.author.name),
                                               str(message.author.nick)),
                        sanitized_content, MsgType.TEXT)
                else:
                    self.bus.broadcast(self, str(message.author.name),
                                       sanitized_content, MsgType.TEXT)
        # TODO: make this check that the message sending user shares servers
        # with the bot
        if message.channel.is_private:
            if is_command(sanitized_content):
                self.handle_command(message.author, sanitized_content)
        return
예제 #4
0
파일: apps.py 프로젝트: siggame/server
 def run(self, command):
     try:
         command_name = command['type']
         args = command['args']
     except KeyError:
         self.send_error(command, 'was missing values')
         return
     function = self.get_command(command_name)
     if not function or not is_command(function):
         self.send_error(command,
                 "%s is not a valid command" % command_name,
                 'command not found')
         return
     try:
         result = function(**args)
     except:
         traceback.print_exc()
         self.send_error(command, traceback.format_exc())
         return
     if result != None:
         self.connection.send_json(result)
예제 #5
0
 def run(self, command):
     try:
         command_name = command['type']
         args = command['args']
     except KeyError:
         self.send_error(command, 'was missing values')
         return
     function = self.get_command(command_name)
     if not function or not is_command(function):
         self.send_error(command,
                 "%s is not a valid command" % command_name,
                 'command not found')
         return
     try:
         result = function(**args)
     except:
         traceback.print_exc()
         self.send_error(command, traceback.format_exc())
         return
     if result != None:
         self.connection.send_json(result)
예제 #6
0
 def command(**args):
     if self.game.current_player._connection != self:
         return {'type': 'failure',
                 'args': {'message': 'not your turn'}}
     if 'actor' not in args:
         return {'type': 'bad arguments',
                 'args': {'message': 'actor required'}}
     actor = self.game.objects.get(args['actor'], None)
     del args['actor']
     if not actor:
         return {'type': 'bad arguments',
                 'args': {'message': 'actor does not exist'}}
     command = getattr(actor, command_name, None)
     if not command or not is_command(command):
         return {'type': 'error',
                 'args': {'message': '%s does not have command %s' %
                     (actor.__class__.__name__, command_name)}}
     #TODO make sure command is a command function rather than a security compromise
     value = command(**args)
     self.game.flush()
     if not value:
         return {'type': 'success', 'args': {}}
     else:
         return value
예제 #7
0
 def on_message(self, source, target, message):
     if is_command(message):
         self.handle_command(target, message)
     else:
         self.bus.broadcast(self, target, message, MsgType.TEXT)