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())))
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()))
async def run_top(self, context): """ Get the leaderboard of words written for this event :param context: :return: """ user = User(context.message.author.id, context.guild.id, context) # First try and get the event as if its running event = Event.get_by_guild(user.get_guild()) # If that fails, get the last run one if event is None: event = Event.get_by_guild(user.get_guild(), include_ended=True) # If there is still not one, then just stop if event is None: return await context.send( user.get_mention() + ', ' + lib.get_string('event:err:noexists', user.get_guild())) event.set_context(context) event.set_guild_object(context.guild) return await context.send( embed=await event.get_leaderboard(Event.LEADERBOARD_LIMIT))
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)
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))
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()))
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))
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()))
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)
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}')
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()))
async def todo(self, context): """ Displays current TODO list """ user = User(context.message.author.id, context.guild.id, context) todo = lib.get_asset('todo', user.get_guild()) output = '```ini\n' for type in todo.keys(): output += '********** ' + lib.get_string( 'todo:' + str(type), user.get_guild()) + ' **********\n' items = todo[type] if len(items): n = 1 for item in items: output += str(n) + '. ' + item + '\n' n += 1 else: output += '-' output += '\n\n' output += '```' return await context.send(output)
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))
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)
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))
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))
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()))
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()))
async def ask(self, context, type=None): """ Asks you a random question about your character or your world, to get the creative juices flowing. Initial questions taken from (novel-software). Examples: !ask c(haracter) - Asks you a question about your character !ask w(orld) - Asks you a question about your world """ user = User(context.message.author.id, context.guild.id, context) # 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, type=type) if not args: return # Overwrite the variables passed in, with the values from the prompt and convert to lowercase type = args['type'].lower() if type in ('c', 'char', 'character'): options = lib.get_asset('q_char', user.get_guild()) elif type in ('w', 'world'): options = lib.get_asset('q_world', user.get_guild()) max = len(options) - 1 rand = random.randint(1, max) question = options[rand] await context.send(f'[{rand}] {question}')
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()))
async def run_start(self, context, length=None, start=None): """ Try to start a sprint on the server :param context :param length: Length of time (in minutes) the sprint should last :param start: Time in minutes from now, that the sprint should start :return: """ user = User(context.message.author.id, context.guild.id, context) sprint = Sprint(user.get_guild()) # Check if sprint is finished but not marked as completed, in which case we can mark it as complete if sprint.is_finished(): # Mark the sprint as complete await sprint.complete() # Reload the sprint object, as now there shouldn't be a pending one sprint = Sprint(user.get_guild()) # If a sprint is currently running, we cannot start a new one if sprint.exists(): return await context.send(user.get_mention() + ', ' + lib.get_string('sprint:err:alreadyexists', user.get_guild())) # Must be okay to continue # # If the length argument is not valid, use the default if length is None or lib.is_number(length) is False or lib.is_number(length) <= 0 or lib.is_number(length) > self.MAX_LENGTH: length = self.DEFAULT_LENGTH # Same goes for the start argument if start is None or lib.is_number(start) is False or lib.is_number(start) < 0 or lib.is_number(start) > self.MAX_DELAY: start = self.DEFAULT_DELAY # Make sure we are using ints and not floats passed through in the command length = int(length) start = int(start) # Calculate the start and end times based on the current timestamp now = int(time.time()) start_time = now + (start * 60) end_time = start_time + (length * 60) # Create the sprint sprint = Sprint.create(guild=user.get_guild(), channel=context.message.channel.id, start=start_time, end=end_time, end_reference=end_time, length=length, createdby=user.get_id(), created=now) # Join the sprint sprint.join(user.get_id()) # Increment the user's stat for sprints created user.add_stat('sprints_started', 1) # Are we starting immediately or after a delay? if start == 0: # Immediately. That means we need to schedule the end task. Task.schedule(sprint.TASKS['end'], end_time, 'sprint', sprint.get_id()) return await sprint.post_start(context) else: # Delay. That means we need to schedule the start task, which will in turn schedule the end task once it's run. Task.schedule(sprint.TASKS['start'], start_time, 'sprint', sprint.get_id()) return await sprint.post_delayed_start(context)
async def my_setting(self, context, setting=None, value=None): """ Lets you update a setting for your user account. **Note:** For the timezone setting, make sure the value you specify is a valid TZ Database Name from this wikipedia page: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones Examples: !mysetting timezone Europe/London !mysetting timezone America/Phoenix """ user = User(context.message.author.id, context.guild.id, context) # If we want to list the setting, do that instead. if setting is not None and setting.lower() == 'list': settings = user.get_settings() output = '```ini\n' if settings: for setting, value in settings.items(): output += setting + '=' + str(value) + '\n' else: output += lib.get_string('setting:none', guild.get_id()) output += '```' return await context.send(user.get_mention() + ',\n' + output) # Check the arguments are valid args = await self.check_arguments(context, setting=setting, value=value) if not args: return setting = args['setting'].lower() value = args['value'] # If the setting is timezone convert the value if setting == 'timezone': try: timezone = pytz.timezone(value) time = datetime.now(timezone) offset = datetime.now(timezone).strftime('%z') await context.send( lib.get_string('event:timezoneupdated', user.get_guild()).format( value, time.ctime(), offset)) except pytz.exceptions.UnknownTimeZoneError: await context.send( lib.get_string('mysetting:timezone:help', user.get_guild())) return # Update the setting and post the success message user.update_setting(setting, value) await context.send(user.get_mention() + ', ' + lib.get_string( 'mysetting:updated', user.get_guild()).format(setting, value))
async def run_cancel(self, context): user = User(context.message.author.id, context.guild.id, context) challenge = user.get_challenge() if challenge: user.delete_challenge() output = lib.get_string('challenge:givenup', user.get_guild()) else: output = lib.get_string('challenge:noactive', user.get_guild()) await context.send(f'{context.message.author.mention}, {output}')
async def run_purge(self, context): """ Purge any users who asked for notifications but aren't on the server any more. @param context: @return: """ user = User(context.message.author.id, context.guild.id, context) purged = await Sprint.purge_notifications(context) if purged > 0: return await context.send(lib.get_string('sprint:purged', user.get_guild()).format(purged)) else: return await context.send(lib.get_string('sprint:purged:none', user.get_guild()))
async def profile(self, context): """ Displays your Writer-Bot profile information and statistics. """ user = User(context.message.author.id, context.guild.id, context) goals = {'daily': user.get_goal_progress('daily')} profile = { 'lvlxp': user.get_xp_bar(), 'words': user.get_stat('total_words_written'), 'words_sprints': user.get_stat('sprints_words_written'), 'sprints_started': user.get_stat('sprints_started'), 'sprints_completed': user.get_stat('sprints_completed'), 'sprints_won': user.get_stat('sprints_won'), 'challenges_completed': user.get_stat('challenges_completed'), 'daily_goals_completed': user.get_stat('daily_goals_completed'), 'goal_progress': str(goals['daily']['percent']) + '%' } embed = discord.Embed(title=user.get_name(), color=3066993) embed.add_field(name=lib.get_string('profile:lvlxp', user.get_guild()), value=profile['lvlxp'], inline=True) embed.add_field(name=lib.get_string('profile:words', user.get_guild()), value=profile['words'], inline=True) embed.add_field(name=lib.get_string('profile:wordssprints', user.get_guild()), value=profile['words_sprints'], inline=True) embed.add_field(name=lib.get_string('profile:sprintsstarted', user.get_guild()), value=profile['sprints_started'], inline=True) embed.add_field(name=lib.get_string('profile:sprintscompleted', user.get_guild()), value=profile['sprints_completed'], inline=True) embed.add_field(name=lib.get_string('profile:sprintswon', user.get_guild()), value=profile['sprints_won'], inline=True) embed.add_field(name=lib.get_string('profile:challengescompleted', user.get_guild()), value=profile['challenges_completed'], inline=True) embed.add_field(name=lib.get_string('profile:dailygoalscompleted', user.get_guild()), value=profile['daily_goals_completed'], inline=True) embed.add_field(name=lib.get_string('profile:goalprogress', user.get_guild()), value=profile['goal_progress'], inline=True) # Send the message await context.send(embed=embed)
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 reset(self, context, what=None, confirm=None): """ Lets you reset your statistics/records. Examples: !reset pb: Resets your wpm personal best !reset wc: Resets your total word count !reset xp: Resets your xp/level to 0 !reset all: Resets your xp/levels, stats, records, goals and challenges """ if not Guild(context.guild).is_command_enabled('reset'): return await context.send( lib.get_string('err:disabled', context.guild.id)) user = User(context.message.author.id, context.guild.id, context) # Check the arguments are valid args = await self.check_arguments(context, what=what, confirm=confirm) if not args: return what = args['what'].lower() confirm = args['confirm'].lower() # Make sure they confirmed it, otherwise just stop and display an OK message if confirm not in ('y', 'yes'): output = 'OK' return await context.send(user.get_mention() + ', ' + output) # Personal Best if what == 'pb': user.update_record('wpm', 0) output = lib.get_string('reset:pb', user.get_guild()) elif what == 'wc': user.update_stat('total_words_written', 0) output = lib.get_string('reset:wc', user.get_guild()) elif what == 'xp': await user.update_xp(0) output = lib.get_string('reset:xp', user.get_guild()) elif what == 'projects': user.reset_projects() output = lib.get_string('reset:projects', user.get_guild()) elif what == 'all': user.reset() output = lib.get_string('reset:done', user.get_guild()) return await context.send(user.get_mention() + ', ' + output)
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))
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()))
async def run_cancel(self, context, type): user = User(context.message.author.id, context.guild.id, context) user.delete_goal(type) return await context.send( user.get_mention() + ', ' + lib.get_string('goal:givenup', user.get_guild()))