Beispiel #1
0
    async def response(self, room, user, args):
        """ Returns a response to the user.

        Args:
            room: Room, room this command was evoked from.
            user: User, user who evoked this command.
            args: no arguments should be passed except for help
        Returns:
            ReplyObject
        """
        if len(args) == 1 and args[0] == 'help':
            return self._help(room, user, args)
        elif len(args) >= 2:
            return ReplyObject("This command only takes 1 argument", True)
        elif len(args) == 1 and args[0] not in [
                'off', '+', '%', '@', '*', '#'
        ]:
            return ReplyObject("You have provided an invalid argument", True)
        elif len(args) == 1 and room.is_pm:
            return ReplyObject("There are no broadcast ranks in PMs", True)
        elif len(args) == 1 and not user.has_rank('#'):
            return ReplyObject("This command is reserved for Room Owners(#)",
                               True)
        else:
            return self._success(room, user, args)
Beispiel #2
0
    async def _success(self, room, user, args):
        """ Returns a success response to the user.

      Successfully returns the expected response from the user based on the args.

      Args:
          room: Room, room this command was evoked from.
          user: User, user who evoked this command.
          args: list of str, any sequence of parameters which are supplied to this command
      Returns:
          ReplyObject
      """
        search = args[0]
        show_image = args[-1] == 'showimage' if args else False
        q = await self.query(search)
        if q['results']:
            url = q['results'][0]['url']
            content = q['results'][0]['content']
            gameid = self.parse_gameid(url)
            game_url, header_image, name, description = await self.get_game_data(
                gameid)
            width, height = OnlineImage.get_image_info(header_image)
            if User.compare_ranks(room.rank, '*') and show_image:
                return ReplyObject((
                    '/addhtmlbox <div id="gameinfo"> <img src="{}" height="{}" width="{}"></img> <p>Name: <a href="{}"> {}</a></p> <p>Description: {} </p> </div>'
                ).format(header_image, height, width, game_url, name,
                         description), True, True)
            else:
                rep = '**Name:** {} **Link:** {} **Description:** {}'.format(
                    name, game_url, description)
                return ReplyObject(rep,
                                   True) if len(rep) <= 300 else ReplyObject(
                                       rep[:300], True)
        else:
            return ReplyObject('Your query didn\'t come up with results')
Beispiel #3
0
 async def response(self, room, user, args):
     if len(args) == 1 and args[0] == 'help':
         return ReplyObject('{}/{}'.format(config['base-url'],
                                           self.aliases[0]))
     elif len(args) > 2:
         return ReplyObject('Too many arguments provided.')
     elif len(args) == 0:
         return ReplyObject('Not enough arguments provided.')
     else:
         return await self._success(room, user, args)
Beispiel #4
0
    def _success(self, room, user, args):
        """ Returns a success response to the user.

        Successfully returns the expected response from the user based on the args.

        Args:
            room: Room, room this command was evoked from.
            user: User, user who evoked this command.
            args: list of str, any sequence of parameters which are supplied to this command
        Returns:
            ReplyObject
        """
        if len(args) == 0:
            return ReplyObject('Rank required to broadcast: {rank}'.format(
                rank=room.broadcastrank))
        else:
            broadcast_rank = ' ' if args[0] == 'off' else args[0]
            room.broadcastrank = broadcast_rank
            return ReplyObject(
                'Broadcast rank set to {rank}. (This is not saved on reboot)'.
                format(rank=broadcast_rank
                       if not broadcast_rank == ' ' else 'none'), True)
Beispiel #5
0
    async def _success(self, room, user, args):
        """ Returns a success response to the user.

      Successfully returns the expected response from the user based on the args.

      Args:
          room: Room, room this command was evoked from.
          user: User, user who evoked this command.
          args: list of str, any sequence of parameters which are supplied to this command
      Returns:
          ReplyObject
      """
        if len(args) == 1:
            search = args[0]
            q = await self.query(search)
            if q['results']:
                url = q['results'][0]['pretty_url']
                content = q['results'][0]['content']
                rep = '{} - retrieved from {}'.format(content, url)
                return ReplyObject(rep,
                                   True) if len(rep) <= 300 else ReplyObject(
                                       rep[:300], True)
            else:
                return ReplyObject('Your query didn\'t come up with results')
        elif len(args) == 2:
            search, engine = args[0], args[1]
            q = await self.query(search, engine)
            if q['results']:
                url = q['results'][0]['pretty_url']
                content = q['results'][0]['content']
                rep = '{} - retrieved from {}'.format(content, url)
                return ReplyObject(rep,
                                   True) if len(rep) <= 300 else ReplyObject(
                                       rep[:300], True)
            else:
                return ReplyObject('Your query didn\'t come up with results')
        elif len(args) == 3:
            search, engine, limit = args[0], args[1], int(args[2])
            q = await self.query(search, engine)
            if q['results']:
                reply = []
                for i in range(min(len(q['results']), limit)):
                    url, content = q['results'][i]['pretty_url'], q['results'][
                        i]['content']
                    rep = '{} - retrieved from {}'.format(content, url)
                    reply.append(rep if len(rep) <= 300 else rep[:300])
                return ReplyObject('\n'.join(reply))
            else:
                return ReplyObject('Your query didn\'t come up with results')
Beispiel #6
0
 async def invoke_command(self, message):
     """Attempt to invoke invoke the specific command with provided arguments.
     Args:
         message: MessageWrapper, message wrapper containing content.
     Returns:
         
     """
     command_alias = self.parse_alias(message.content)
     command_msg = message.content[len(command_alias) + 1:].lstrip()
     for cmd in self.modules:
         if command_alias in cmd.aliases:
             response = await cmd.response(message.room, message.user,
                                           cmd.parse_args(command_msg))
             return response
     return ReplyObject()