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_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_challenge(self, context, flag, flag2=None): user = User(context.message.author.id, context.guild.id, context) challenge = user.get_challenge() if challenge: output = lib.get_string('challenge:current', user.get_guild()) + ': **' + \ challenge['challenge'] + '**\n' + \ lib.get_string('challenge:tocomplete', user.get_guild()) await context.send(f'{context.message.author.mention}, {output}') return # First create a random WPM and time and then adjust if they are actually specified wpm = random.randint(self.WPM['min'], self.WPM['max']) time = random.randint(self.TIMES['min'], self.TIMES['max']) if flag is not None: # Convert the flag to the corresponding WPM if flag == 'easy': wpm = 5 elif flag == 'normal': wpm = 10 elif flag == 'hard': wpm = 20 elif flag == 'hardcore': wpm = 40 elif flag == 'insane': wpm = 60 elif flag.isdigit(): # If it's just a digit, assume that's the WPM wpm = int(flag) elif flag.endswith('wpm'): # If it ends with 'wpm' remove that and convert to an int for the WPM wpm = int(re.sub(r'\D', '', flag)) elif flag.endswith('m'): # If it ends with 'm' remove that and convert to an int for the time time = int(re.sub(r'\D', '', flag)) # We can ask for a difficulty AND a time, using flag2. E.g. `normal 15m`. So if flag2 ends with 'm' calculate the time based on that. # If for some reason they do both flags as time, e.g. `challenge 15m 25m` the second one will overwrite the first. if flag2 is not None and flag2.endswith('m'): time = int(re.sub(r'\D', '', flag2)) goal = wpm * time xp = self.calculate_xp(wpm) challenge = lib.get_string('challenge:challenge', user.get_guild()).format(words=goal, mins=time, wpm=wpm) message = challenge + '\n' message += lib.get_string('challenge:decide', user.get_guild()) # Build a fake argument, as the argument is optional so isn't checked by the normal check_arguments method argument = { 'prompt': message, 'check': lambda resp: resp.lower() in ('y', 'yes', 'n', 'no') } # Print the challenge and ask for confirmation response response = await self.adhoc_prompt(context, argument, True) if not response: return response = response.content # If they accept it, set the challenge and print the message if response.lower() in ('y', 'yes'): user.set_challenge(challenge, xp) output = lib.get_string('challenge:accepted', user.get_guild( )) + ' **' + challenge + '**\n' + lib.get_string( 'challenge:tocomplete', user.get_guild()) else: # Otherwise, just print 'OK' output = 'OK' await context.send(context.message.author.mention + ', ' + output)