Esempio n. 1
0
    async def run_view(self, context, opts=None):
        """
        View a list of the user's projects
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        projects = user.get_projects()

        # If they have no projects, then we can't display them.
        if not projects:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('project:noprojects', user.get_guild()))

        # Did they specify a shortname to look at?
        if opts:

            shortname = opts[0].lower()

            # Make sure the project exists.
            project = user.get_project(shortname)
            if not project:
                return await context.send(
                    user.get_mention() +
                    ', ' + lib.get_string('project:err:noexists',
                                          user.get_guild()).format(shortname))

            # Re-create the array, but with just this one element in it.
            projects = [project]

        message = ''

        for project in projects:

            if project.is_completed():
                message += ':sparkler: '

            message += '**' + project.get_name(
            ) + '** (' + project.get_shortname() + ')\n'
            message += lib.get_string('wordcount',
                                      user.get_guild()) + ': ' + str(
                                          project.get_words()) + '\n\n'

        # Project lists can get very long. If it is over 2000 characters, we need to split it.
        if len(message) >= 2000:
            return await self.split_send(
                context, user,
                lib.get_string('project:list', user.get_guild()) + message)
        else:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('project:list', user.get_guild()) + message)
    async def run_list(self, context, opts=None):
        """
        View a list of the user's projects
        @param context:
        @param opts:
        @return:
        """
        user = User(context.message.author.id, context.guild.id, context)

        by = opts[0].lower() if opts else None
        filter = opts[1].lower() if len(opts) > 1 else None

        # If supplied, make sure the filters are valid.
        if by is not None and by not in ['status', 'genre']:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('project:err:filter:type', user.get_guild()))

        if by == 'status':
            options = self._statuses
        elif by == 'genre':
            options = self._genres

        if by is not None and filter not in options:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('project:err:filter', user.get_guild()).format(
                    ', '.join(options)))

        projects = user.get_projects(by, filter)

        # If they have no projects, then we can't display them.
        if not projects:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('project:noprojects', user.get_guild()))

        message = ''

        for project in projects:

            message += '**' + project.get_name(
            ) + '** (' + project.get_shortname() + ') [' + str("{:,}".format(
                project.get_words())) + ' ' + lib.get_string(
                    'words', user.get_guild()).lower() + ']\n'
            message += project.get_status_emote()
            if project.get_genre() is not None:
                message += '\t' + project.get_genre_emote()
            message += '\n\n'

        filter_string = lib.get_string(
            'project:' + by + ':' + filter,
            user.get_guild()) if filter is not None else lib.get_string(
                'all', user.get_guild())

        # Project lists can get very long. If it is over 2000 characters, we need to split it. Using 1750 to give us leeway on the user mention as well.
        if len(message) >= 1750:
            return await self.split_send(
                context, user,
                lib.get_string('project:list',
                               user.get_guild()).format(filter_string) +
                message)
        else:
            return await context.send(
                user.get_mention() + ', ' + lib.get_string(
                    'project:list', user.get_guild()).format(filter_string) +
                message)