Пример #1
0
    async def run_status(self, context):
        """
        Get the user's status in this sprint
        :param context:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        sprint = Sprint(user.get_guild())

        # If there is no active sprint, then just display an error
        if not sprint.exists():
            return await context.send(user.get_mention() + ', ' + lib.get_string('sprint:err:noexists', user.get_guild()))

        # If the user is not sprinting, then again, just display that error
        if not sprint.is_user_sprinting(user.get_id()):
            return await context.send(user.get_mention() + ', ' + lib.get_string('sprint:err:notjoined', user.get_guild()))

        # If the sprint hasn't started yet, display error
        if not sprint.has_started():
            return await context.send(user.get_mention() + ', ' + lib.get_string('sprint:err:notstarted', user.get_guild()))

        # If they are sprinting, then display their current status.
        user_sprint = sprint.get_user_sprint(user.get_id())

        # Build the variables to be passed into the status string
        now = int(time.time())
        current = user_sprint['current_wc']
        written = current - user_sprint['starting_wc']
        seconds = now - user_sprint['timejoined']
        elapsed = round(seconds / 60, 1)
        wpm = Sprint.calculate_wpm(written, seconds)
        left = round((sprint.get_end() - now) / 60, 1)

        return await context.send(user.get_mention() + ', ' + lib.get_string('sprint:status', user.get_guild()).format(current, written, elapsed, wpm, left))
Пример #2
0
    async def run_description(self, context, opts):
        """
        Update the description of a project
        @param context:
        @param opts:
        @return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        shortname = opts[0].lower()
        description = " ".join(opts[1:])

        # 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))

        # Description cannot be longer than 200 words.
        words = description.split(' ')
        if len(words) > 200:
            return await context.send(
                user.get_mention() +
                ', ' + lib.get_string('project:err:desc:length',
                                      user.get_guild()).format(len(words)))

        project.set_description(description)
        return await context.send(
            user.get_mention() + ', ' +
            lib.get_string('project:description', user.get_guild()))
Пример #3
0
    async def run_update(self, context, opts):
        """
        Update a project's word count
        :param context:
        :param opts:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)

        shortname = opts[0].lower()
        amount = opts[1] if len(opts) > 1 else None

        # Make sure the amount is valid.
        amount = lib.is_number(amount)
        if not amount:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('project:err:amount', user.get_guild()))

        # 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))

        # Update the word count.
        project.update(amount)
        return await context.send(
            user.get_mention() + ', ' +
            lib.get_string('project:updated', user.get_guild()).format(
                amount, project.get_name(), project.get_shortname()))
Пример #4
0
    async def xp(self, context, who='me'):
        """
        Checks your Experience Points and Level. Use the 'top' flag to see the top 10 on this server.
        Examples:
            !xp - Shows your level/xp
            !xp top - Shows the top 10 users on this server
        """
        if not Guild(context.guild).is_command_enabled('xp'):
            return await context.send(lib.get_string('err:disabled', context.guild.id))

        guild_id = context.guild.id
        user_id = context.message.author.id

        if who == 'top':

            title = context.guild.name + ' - ' + lib.get_string('xp:leaderboard', guild_id)
            embed = discord.Embed(title=title, color=discord.Color.red(), description=None)
            embed.add_field(name=lib.get_string('xp:leaderboard', guild_id), value='Leaderboard temporarily disabled until a fix can be implemented', inline=False)
            return await context.send(embed=embed)

        else:
            user = User(user_id, guild_id)
            xp = user.get_xp()

            # Either display a message saying they have no XP, or display the XP bar for the user
            if xp is None:
                output = context.message.author.mention + ', ' + lib.get_string('xp:noxp', guild_id)
            else:
                output = context.message.author.mention + ', ' + lib.get_string('youare', guild_id) + ' ' + user.get_xp_bar()

        await context.send(output)
Пример #5
0
    async def prompt(self, context, argument, raw_message=False, timeout=None):

        # Get the message we want to use for the prompt
        message = argument['prompt']

        # Use default timeout is none specified
        if timeout is None:
            timeout = self.TIMEOUT_WAIT

        # Send the prompt message and wait for a reply
        if not raw_message:
            message = lib.get_string(message, context.guild.id)

        # Define the function we use to check the value
        def _check(msg):
            return msg.author == context.author and msg.channel == context.channel and not msg.content.startswith(
                context.prefix)

        # Send the prompt message asking for the argument and await response
        req = await context.send(f'{context.author.mention}, {message}')
        try:
            response = await self.bot.wait_for('message',
                                               check=_check,
                                               timeout=timeout)
            return response
        except asyncio.TimeoutError:
            await req.edit(
                content=lib.get_string('req:timeout', context.guild.id))
            return False
Пример #6
0
    async def run_cancel(self, context):
        """
        Cancel a running sprint on the server
        :param context:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        sprint = Sprint(user.get_guild())

        # If there is no active sprint, then just display an error
        if not sprint.exists():
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('sprint:err:noexists', user.get_guild()))

        # If they do not have permission to cancel this sprint, display an error
        if int(sprint.get_createdby()) != user.get_id(
        ) and context.message.author.permissions_in(
                context.message.channel).manage_messages is not True:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('sprint:err:cannotcancel', user.get_guild()))

        # Get the users sprinting and create an array of mentions
        users = sprint.get_users()
        notify = sprint.get_notifications(users)

        # Cancel the sprint
        sprint.cancel(context)

        # Display the cancellation message
        message = lib.get_string('sprint:cancelled', user.get_guild())
        message = message + ', '.join(notify)
        return await context.send(message)
Пример #7
0
    async def run_update(self, context, type, amount):
        """
        Update the value of a goal, without affecting the others or updating XP, etc...
        Useful for if you want to record the writing you have done, before you started using Writer-Bot.
        @param context:
        @param type:
        @param amount:
        @return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        type_string = lib.get_string('goal:' + type, user.get_guild())
        user_goal = user.get_goal(type)

        # Check if we can convert the amount to an int
        amount = lib.is_number(amount)
        if not amount:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('err:validamount', user.get_guild()))

        # Set the goal's current amount.
        if user_goal and user.update_goal(type, amount):
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('goal:updated', user.get_guild()).format(
                    type_string, amount))
        else:
            return await context.send(
                user.get_mention() + ', ' + lib.get_string(
                    'goal:nogoal', user.get_guild()).format(type_string, type))
Пример #8
0
    async def run_create(self, context, opts):
        """
        Create an event on the server
        :param context:
        :param opts:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)

        # Do they have the permissions to create an event?
        self.check_permissions(context)

        # Get the title out of the arguments
        title = " ".join(opts[0:])

        # Check if there is already an event running
        event = Event.get_by_guild(user.get_guild())
        if event is not None:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('event:err:alreadyexists', user.get_guild()))

        # Make sure they specified a title.
        if len(title) == 0 or len(title) > 255:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('event:err:title', user.get_guild()))

        # Create the event
        Event.create(guild=user.get_guild(),
                     channel=context.message.channel.id,
                     title=title)
        return await context.send(
            user.get_mention() + ', ' +
            lib.get_string('event:created', user.get_guild()).format(title))
Пример #9
0
    async def run_complete(self, context):

        user = User(context.message.author.id, context.guild.id, context)

        # Do they have an active challenge to mark as complete?
        challenge = user.get_challenge()
        if challenge:

            # Update the challenge with the time completed
            user.complete_challenge(challenge['id'])

            # Add the XP
            await user.add_xp(challenge['xp'])

            # Increment the challenges_completed stat
            user.add_stat('challenges_completed', 1)

            output = lib.get_string('challenge:completed', user.get_guild(
            )) + ' **' + challenge['challenge'] + '**          +' + str(
                challenge['xp']) + 'xp'

        else:
            output = lib.get_string('challenge:noactive', user.get_guild())

        await context.send(f'{context.message.author.mention}, {output}')
Пример #10
0
    async def run_update(self, context, amount):
        """
        Update the user's word count on the event
        :param context:
        :param amount:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        event = Event.get_by_guild(user.get_guild())

        amount = lib.is_number(amount[0])
        if amount is False or amount < 0:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('err:validamount', user.get_guild()))

        # Make sure the event is running
        if event is None or not event.is_running():
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('event:err:noexists', user.get_guild()))

        event.update_wordcount(user.get_id(), amount)
        return await context.send(
            user.get_mention() + ', ' +
            lib.get_string('event:updated', user.get_guild()).format(
                event.get_title(), amount))
Пример #11
0
    async def run_rename(self, context, opts):
        """
        Rename the event
        :param context:
        :param opts:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)

        # Do they have the permissions to rename an event?
        self.check_permissions(context)

        # Check if there is an event running
        event = Event.get_by_guild(user.get_guild())
        if event is None or not event.is_valid():
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('event:err:noexists', user.get_guild()))

        # Get the title out of the arguments
        title = " ".join(opts[0:])

        # Make sure they specified a title.
        if len(title) == 0 or len(title) > 255:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('event:err:rename:title', user.get_guild()))

        # Create the event
        event.set_title(title)
        event.save()
        return await context.send(
            user.get_mention() + ', ' +
            lib.get_string('event:renamed', user.get_guild()).format(title))
Пример #12
0
    async def check_answers(self, context, answers):
        """
        Run the checks on their answers to make sure their values are valid
        :param answers:
        :return:
        """
        now = datetime.today()
        start = datetime.strptime(
            lib.find(answers, 'stage', 1)['answer'] + ' ' +
            lib.find(answers, 'stage', 2)['answer'], '%d-%m-%Y %H:%M')
        end = datetime.strptime(
            lib.find(answers, 'stage', 3)['answer'] + ' ' +
            lib.find(answers, 'stage', 4)['answer'], '%d-%m-%Y %H:%M')

        # Check that the end date is later than the start date.
        if start > end:
            await context.send(
                context.message.author.mention + ', ' +
                lib.get_string('event:err:dates', context.guild.id))
            return False

        # Check that dates are in the future
        if start < now or end < now:
            await context.send(
                context.message.author.mention + ', ' +
                lib.get_string('event:err:dates:past', context.guild.id))
            return False

        return True
Пример #13
0
    async def run_unschedule(self, context):
        """
        Unschedule the event
        :param context:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        event = Event.get_by_guild(user.get_guild())

        # Do they have the permissions to rename an event?
        self.check_permissions(context)

        # Make sure the event is running
        if event is None:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('event:err:noexists', user.get_guild()))

        # Unschedule the event
        event.set_startdate(None)
        event.set_enddate(None)
        event.save()

        # Remove any tasks we already had saved for this event.
        Task.cancel('event', event.get_id())

        return await context.send(user.get_mention() + ', ' + lib.get_string(
            'event:unscheduled', user.get_guild()).format(event.get_title()))
Пример #14
0
    async def run_time(self, context):
        """
        Get how long is left in the sprint
        :param context:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        sprint = Sprint(user.get_guild())

        # If there is no active sprint, then just display an error
        if not sprint.exists():
            return await context.send(user.get_mention() + ', ' + lib.get_string('sprint:err:noexists', user.get_guild()))

        now = int(time.time())

        # If the sprint has not yet started, display the time until it starts
        if not sprint.has_started():
            left = lib.secs_to_mins(sprint.get_start() - now)
            return await context.send(user.get_mention() + ', ' + lib.get_string('sprint:startsin', user.get_guild()).format(left['m'], left['s']))

        # If it's currently still running, display how long is left
        elif not sprint.is_finished():
            left = lib.secs_to_mins(sprint.get_end() - now)
            return await context.send(user.get_mention() + ', ' + lib.get_string('sprint:timeleft', user.get_guild()).format(left['m'], left['s']))

        # If it's finished but not yet marked as completed, we must be waiting for word counts
        elif sprint.is_finished():
            return await context.send(user.get_mention() + ', ' + lib.get_string('sprint:waitingforwc', user.get_guild()))
Пример #15
0
    async def run_project(self, context, shortname):
        """
        Set the project the user wants to sprint in.
        :param context:
        :param shortname:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        sprint = Sprint(user.get_guild())

        # If there is no active sprint, then just display an error
        if not sprint.exists():
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('sprint:err:noexists', user.get_guild()))

        # If the user is not sprinting, then again, just display that error
        if not sprint.is_user_sprinting(user.get_id()):
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('sprint:err:notjoined', user.get_guild()))

        # Make sure the project exists.
        shortname = shortname.lower() if shortname is not None else None
        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))

        sprint.set_project(project.get_id(), user.get_id())
        return await context.send(user.get_mention() + ', ' + lib.get_string(
            'sprint:project', user.get_guild()).format(project.get_title()))
Пример #16
0
    async def goal(self, context, option=None, type=None, value=None):
        """
        Sets a daily goal which resets every 24 hours at midnight in your timezone.

        Examples:
            !goal - Print a table of all your goals, with their progress and next reset time.
            !goal check daily - Checks how close you are to your daily goal
            !goal set weekly 500 - Sets your weekly goal to be 500 words per day
            !goal cancel monthly - Deletes your monthly goal
            !goal time daily - Checks how long until your daily goal resets
        """
        user = User(context.message.author.id, context.guild.id, context)

        # If no option is sent and we just do `goal` then display a table of all their goals.
        if option is None:
            return await self.run_check_all(context)

        # Otherwise, we must specify a type.
        if type is None or type not in self.types:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('goal:invalidtype', user.get_guild()))

        if option == 'set':
            return await self.run_set(context, type, value)
        elif option == 'cancel' or option == 'delete' or option == 'reset':
            return await self.run_cancel(context, type)
        elif option == 'time':
            return await self.run_time(context, type)
        elif option == 'check':
            return await self.run_check(context, type)
        else:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('goal:invalidoption', user.get_guild()))
Пример #17
0
    async def run_leave(self, context):
        """
        Leave the sprint
        :param context:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        sprint = Sprint(user.get_guild())

        # If there is no active sprint or the user is not joined to it, display an error
        if not sprint.exists() or not sprint.is_user_sprinting(user.get_id()):
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('sprint:err:notjoined', user.get_guild()))

        # Remove the user from the sprint
        sprint.leave(user.get_id())

        await context.send(user.get_mention() + ', ' +
                           lib.get_string('sprint:leave', user.get_guild()))

        # If there are now no users left, cancel the whole sprint
        if len(sprint.get_users()) == 0:

            # Cancel the sprint
            sprint.cancel(context)

            # Decrement sprints_started stat for whoever started this one
            creator = User(sprint.get_createdby(), sprint.get_guild())
            creator.add_stat('sprints_started', -1)

            # Display a message letting users know
            return await context.send(
                lib.get_string('sprint:leave:cancelled', user.get_guild()))
Пример #18
0
    async def run_time(self, context):
        """
        Check how long until the goal resets
        :param context:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)

        # Currently only daily goals implemented
        type = 'daily'

        # Get the goal of this type for this user
        goal = user.get_goal(type)
        if goal:

            now = int(time.time())
            reset = goal['reset']
            left = lib.secs_to_days(reset - now)
            return await context.send(
                user.get_mention() + ', ' + lib.get_string(
                    'goal:timeleft', user.get_guild()).format(left, type))

        else:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('goal:nogoal', user.get_guild()).format(type))
Пример #19
0
    async def run_check_all(self, context):
        """
        Print a table of all the user's goals.
        @param context:
        @return:
        """

        now = int(time.time())
        user = User(context.message.author.id, context.guild.id, context)
        embed = discord.Embed(title=lib.get_string('goals', user.get_guild()),
                              color=10038562)

        for type in self.types:

            type_string = lib.get_string('goal:' + type, user.get_guild())
            goal = user.get_goal(type)
            if goal is not None:
                progress = user.get_goal_progress(type)
                left = lib.secs_to_days(goal['reset'] - now)
                text = lib.get_string('goal:yourgoal',
                                      user.get_guild()).format(
                                          type_string, goal['goal']) + "\n"
                text += lib.get_string('goal:status', user.get_guild()).format(
                    progress['percent'], type_string, progress['current'],
                    progress['goal']) + "\n"
                text += lib.get_string('goal:timeleft',
                                       user.get_guild()).format(
                                           left, type_string)
            else:
                text = None

            embed.add_field(name=type_string, value=text, inline=False)

        # Send the message
        await context.send(embed=embed)
Пример #20
0
    async def run_rename(self, context, opts):
        """
        Rename a project
        :param context:
        :param opts:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)

        original_shortname = opts[0].lower()
        new_shortname = opts[1].lower()
        new_title = " ".join(opts[2:])

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

        # Make sure they don't already have one with that new shortname.
        project_with_new_shortname = user.get_project(new_shortname)
        if project_with_new_shortname is not None and project_with_new_shortname.get_id() != project.get_id():
            return await context.send(user.get_mention() + ', ' + lib.get_string('project:err:exists', user.get_guild()).format(new_shortname))

        # Get the original title.
        original_title = project.get_name()

        # Rename it.
        project.rename(new_shortname, new_title)
        return await context.send(user.get_mention() + ', ' + lib.get_string('project:renamed', user.get_guild()).format(original_title, original_shortname, new_title, new_shortname))
Пример #21
0
    async def run_history(self, context, type):
        """
        Get the user's goal history, so they can look back and see how they did for previous goals
        @param context:
        @param type:
        @return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        type_string = lib.get_string('goal:' + type, user.get_guild()).lower()
        history = user.get_goal_history(type)

        # Build embedded response.
        embed = discord.Embed(title=lib.get_string(
            'goal:history', user.get_guild()).format(type_string),
                              color=10038562)

        # Loop through each history record.
        for record in history:

            title = record['date']
            text = str(record['result']) + '/' + str(record['goal'])
            text += ' :white_check_mark:' if record['completed'] else ''
            embed.add_field(name=title, value=text, inline=False)

        await context.send(embed=embed)
Пример #22
0
    async def run_create(self, context, opts):
        """
        Try to create a project with the given names
        :param context:
        :param shortname:
        :param title:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)

        # Get the shortname and title out of the argument list.
        shortname = opts[0].lower()
        title = " ".join(opts[1:]) # Every argument after the first one, joined with spaces.

        # Make sure the shortname and title are set.
        if len(shortname) == 0 or len(title) == 0:
            return await context.send(user.get_mention() + ', ' + lib.get_string('project:err:names', user.get_guild()))

        # Make sure they don't already have a project with this shortname
        project = user.get_project(shortname)
        if project is not None:
            return await context.send(user.get_mention() + ', ' + lib.get_string('project:err:exists', user.get_guild()).format(shortname))

        # Create the project
        user.create_project(shortname, title)
        return await context.send(user.get_mention() + ', ' + lib.get_string('project:created', user.get_guild()).format(title, shortname))
Пример #23
0
    async def xp(self, context, who='me'):
        """
        Checks your Experience Points and Level. Use the 'top' flag to see the top 10 on this server.
        Examples:
            !xp - Shows your level/xp
            !xp top - Shows the top 10 users on this server
        """

        guild_id = context.guild.id
        user_id = context.message.author.id

        if who == 'top':

            guild = Guild(context.guild)
            users = guild.get_top_xp()
            output = ':trophy: **' + lib.get_string(
                'xp:leaderboard', guild_id) + '** :trophy: \n\n'
            for key in range(len(users)):
                user = users[key]
                output += str(key + 1) + '. ' + user.get_name(
                ) + ' - ' + user.get_xp_bar() + '\n'

        else:
            user = User(user_id, guild_id)
            xp = user.get_xp()

            # Either display a message saying they have no XP, or display the XP bar for the user
            if xp is None:
                output = context.message.author.mention + ', ' + lib.get_string(
                    'xp:noxp', guild_id)
            else:
                output = context.message.author.mention + ', ' + lib.get_string(
                    'youare', guild_id) + ' ' + user.get_xp_bar()

        await context.send(output)
Пример #24
0
    async def run_complete(self, context, opts):
        """
        Mark a project as completed
        :param context:
        :param opts:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        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))

        already_completed = project.is_completed()
        project.complete()

        # Was this the first time they completed it?
        if already_completed == 0:

            # Calculate how much XP to give them (1xp per 100 words). Min 10. Max 5000.
            xp = math.ceil(project.get_words() / 100)
            if xp < 10:
                xp = 10
            elif xp > 5000:
                xp = 5000

            # Give them the xp and print the message.
            await user.add_xp(xp)
            return await context.send(user.get_mention() + ', ' + lib.get_string('project:completed', user.get_guild()).format(project.get_title(), xp))

        else:
            return await context.send(user.get_mention() + ', ' + lib.get_string('project:recompleted', user.get_guild()))
Пример #25
0
    async def _8ball(self, context, question=None):
        """
        Ask the magic 8-ball a question. Your question will be routed to a text-processing AI in order to properly analyze the content of the question and provide a meaningful answer.

        Examples: !8ball Should I do some writing?
        """
        if not Guild(context.guild).is_command_enabled('8ball'):
            return await context.send(
                lib.get_string('err:disabled', context.guild.id))

        guild_id = context.guild.id

        # Check the arguments were all supplied and get a dict list of them and their values, after any prompts
        args = await self.check_arguments(context, question=question)
        if not args:
            return

        # Overwrite variable from check_arguments()
        question = args['question']

        # Create array of possible answers to choose from
        answers = []

        # Load all 21 possible answers into an array to pick from
        for i in range(21):
            answers.append(lib.get_string('8ball:' + format(i), guild_id))

        # Pick a random answer
        answer = random.choice(answers)

        # Send the message
        await context.send(context.message.author.mention + ', ' +
                           format(answer))
Пример #26
0
    async def remind(self, context, *opts):
        """
        Set or configure a reminder
        @param opts:
        @param context:
        @return:
        """
        if not Guild(context.guild).is_command_enabled('remind'):
            return await context.send(lib.get_string('err:disabled', context.guild.id))

        user = User(context.message.author.id, context.guild.id, context)

        # Does the user have a timezone setup? If not, can't do anything.
        if not lib.is_valid_timezone(user.get_setting('timezone')):
            return await context.send(user.get_mention() + ', ' + lib.get_string('err:notimezone', user.get_guild()))

        # Convert the natural language of the command into variables.
        cmd = ' '.join(opts)

        # Check what we are trying to do with reminders.
        if cmd.lower() == 'list':
            return await self.run_list(context, user)
        elif cmd.lower() == 'delete':
            return await self.run_delete(context, user)
        else:
            return await self.run_remind(context, user, cmd)
Пример #27
0
    async def run_genre(self, context, opts):
        """
        Update the genre of a project
        @param context:
        @param opts:
        @return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        shortname = opts[0].lower() if opts else None
        genre = opts[1].lower() if len(opts) > 1 else None

        # 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))

        # Make sure the genre is valid.
        if not genre in self._genres:
            return await context.send(
                user.get_mention() + ', ' +
                lib.get_string('project:err:genre', user.get_guild()).format(
                    genre, ', '.join(self._genres)))

        project.set_genre(genre)
        return await context.send(
            user.get_mention() + ', ' +
            lib.get_string('project:genre', user.get_guild()).format(
                lib.get_string('project:genre:' + genre, user.get_guild())))
Пример #28
0
    async def display(self, context):

        title = self.get_title()
        description = self.get_description()
        link = self.get_link()
        words = str("{:,}".format(self.get_words()))

        embed = discord.Embed(title=title,
                              color=discord.Color.green(),
                              description=description,
                              url=link)

        print(self.get_image())

        if self.get_image() is not None:
            embed.set_thumbnail(url=self.get_image())

        embed.add_field(
            name=lib.get_string('status', context.guild.id),
            value=self.get_status_emote() + ' ' + lib.get_string(
                'project:status:' + self.get_status(), context.guild.id),
            inline=True)

        if self.get_genre() is not None:
            embed.add_field(
                name=lib.get_string('genre', context.guild.id),
                value=self.get_genre_emote() + ' ' + lib.get_string(
                    'project:genre:' + self.get_genre(), context.guild.id),
                inline=True)

        embed.add_field(name=lib.get_string('wordcount', context.guild.id),
                        value=words,
                        inline=True)

        return await context.send(embed=embed)
Пример #29
0
    async def run_image(self, context, opts):
        """
        Update the image link of a project
        @param context:
        @param opts:
        @return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        shortname = opts[0].lower() if opts else None
        img = opts[1] if len(opts) > 1 else None

        # 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))

        # Check it's a valid image link.
        if not checkers.is_url(img) and img is not None:
            return await context.send(
                user.get_mention() + ', ' + lib.get_string(
                    'project:err:link', user.get_guild()).format(img))

        project.set_image(img)
        return await context.send(
            user.get_mention() + ', ' +
            lib.get_string('project:image', user.get_guild()))
Пример #30
0
    async def run_end(self, context):
        """
        Manually force the sprint to end (if the cron hasn't posted the message) and ask for final word counts
        :param context:
        :return:
        """
        user = User(context.message.author.id, context.guild.id, context)
        sprint = Sprint(user.get_guild())

        # If there is no active sprint, then just display an error
        if not sprint.exists():
            return await context.send(user.get_mention() + ', ' + lib.get_string('sprint:err:noexists', user.get_guild()))

        # If they do not have permission to cancel this sprint, display an error
        if int(sprint.get_createdby()) != user.get_id() and context.message.author.permissions_in(context.message.channel).manage_messages is not True:
            return await context.send(user.get_mention() + ', ' + lib.get_string('sprint:err:cannotend', user.get_guild()))

        # If the sprint hasn't started yet, it can't be ended.
        if not sprint.has_started():
            return await context.send(user.get_mention() + ', ' + lib.get_string('sprint:err:notstarted', user.get_guild()))

        # Change the end reference to now, otherwise wpm calculations will be off, as it will use the time in the future when it was supposed to end.
        sprint.update_end_reference(int(time.time()))

        # Since we are forcing the end, we should cancel any pending tasks for this sprint
        Task.cancel('sprint', sprint.get_id())

        # We need to set the bot into the sprint object, as we will need it when trying to get the guild object
        sprint.set_bot(self.bot)
        return await sprint.end(context)