async def stop(self, ctx, *, start={}, role="", game="", datestart=""): if ctx.invoked_with == 'start' or ctx.invoked_with == 'resume': if not self.timer.get_command( ctx.invoked_with).is_on_cooldown(ctx): await ctx.channel.send( content= f"There is no timer to stop or something went wrong with the timer! If you had a timer previously, try `{commandPrefix}timer resume` to resume a timer" ) return author = ctx.author user = author.display_name end = time.time() dateend = datetime.now( pytz.timezone(timezoneVar)).strftime("%I:%M %p") allRewardStrings = {} treasureString = "No Rewards" for startItemKey, startItemValue in start.items(): duration = end - startItemValue if role != "": treasureArray = calculateTreasure(duration, role) treasureString = f"{treasureArray[0]} CP, {treasureArray[1]} TP, and {treasureArray[2]} GP" allRewardStrings[ f"{startItemKey} - {timeConversion(duration)}"] = treasureString stopEmbed = discord.Embed() stopEmbed.title = f"Timer: {game} [END]" stopEmbed.description = f"{datestart} to {dateend} CDT" if role == "True": stopEmbed.colour = discord.Colour(0x9c3dca) elif role == "Elite": stopEmbed.colour = discord.Colour(0xa87fff) elif role == "Journey": stopEmbed.colour = discord.Colour(0x689eff) elif role == "": stopEmbed.colour = discord.Colour(0xffffff) else: stopEmbed.colour = discord.Colour(0x38ceff) stopEmbed.clear_fields() stopEmbed.set_footer(text=stopEmbed.Empty) for key, value in allRewardStrings.items(): stopEmbed.add_field(name=key, value=value, inline=False) await ctx.channel.send(embed=stopEmbed) self.timer.get_command('start').reset_cooldown(ctx) self.timer.get_command('resume').reset_cooldown(ctx) return
async def reward(self, ctx, timeString=None, tier=None): rewardCommand = f"`{commandPrefix}reward [XhYm] [tier]`" def convert_to_seconds(s): return int(s[:-1]) * seconds_per_unit[s[-1]] channel = ctx.channel if timeString is None: await channel.send(content=rewardCommand + " Time is required.") return if tier is None: await channel.send(content=rewardCommand + " Tier is required. The valid tiers are: " + ", ".join(roleArray)) return seconds_per_unit = {"m": 60, "h": 3600} lowerTimeString = timeString.lower() tierName = tier.lower().capitalize() if tierName not in roleArray: await channel.send( content=rewardCommand + " You did not type a valid tier. The valid tiers are: " + ", ".join(roleArray)) return l = list((re.findall('.*?[hm]', lowerTimeString))) totalTime = 0 for timeItem in l: totalTime += convert_to_seconds(timeItem) if totalTime == 0: await channel.send( content=rewardCommand + " You may have formatted the time incorrectly or calculated for 0. Try again with the correct format." ) return treasureArray = calculateTreasure(totalTime, tier) durationString = timeConversion(totalTime) treasureString = f"{treasureArray[0]} CP, {treasureArray[1]} TP, and {treasureArray[2]} GP" dmTreasureString = f"{treasureArray[3]} CP, {treasureArray[4]} TP, and {treasureArray[5]} GP" await channel.send( content= f"A {durationString} game would give a {tierName} Friend\n\n**Player:** {treasureString} \n**DM:** {dmTreasureString}" ) return
async def removeme(self, ctx, start={}, role="", user=""): if ctx.invoked_with == 'start' or ctx.invoked_with == 'resume': if user in start.keys(): duration = time.time() - start[user] del start[user] else: duration = time.time() - start[f"{role} Friend Rewards"] treasureArray = calculateTreasure(duration, role) treasureString = f"{treasureArray[0]} CP, {treasureArray[1]} TP, and {treasureArray[2]} GP" await ctx.channel.send( content= f"{user}, I've have removed you from the timer.\nSince you have played for {timeConversion(duration)}, your rewards are - {treasureString}" ) self.timer.get_command('addme').reset_cooldown(ctx) return start
async def reward(self, ctx, timeString=None, tier=None): rewardCommand = f"\nPlease follow this format:\n```yaml\n{commandPrefix}reward \"#h#m\" \"tier or character name\"```\n" def convert_to_seconds(s): return int(s[:-1]) * seconds_per_unit[s[-1]] channel = ctx.channel author = ctx.author charEmbed = discord.Embed() charEmbedmsg = None char = tier #this is mainly for my sanity if timeString is None: await channel.send( content= "Woops, you're forgetting the time duration for the command." + rewardCommand) return if tier is None: await channel.send( content= "Woops, you're forgetting the tier or character name for the command. Please try again with 1, 2, 3, or 4 or Junior, Journey, Elite, or True as the tier, or use a character name and" + rewardCommand) return seconds_per_unit = {"m": 60, "h": 3600} lowerTimeString = timeString.lower() # Converts the time given to data l = list((re.findall('.*?[hm]', lowerTimeString))) totalTime = 0 # protect from incorrect inputs like #h#m try: for timeItem in l: totalTime += convert_to_seconds(timeItem) except Exception as e: totalTime = 0 if totalTime == 0: charEmbed.description = "You may have formatted the time incorrectly or calculated for 0. Try again with the correct format." + rewardCommand await channel.send(embed=charEmbed) return characterPresent = False #base case: No character is given # Checks to see if a tier was given. If there wasn't, it then checks to see if a valid character was given. If not, error. if tier not in ('0', '1', '2', '3', '4', '5') and tier.lower() not in [ r.lower() for r in roleArray ]: charDict, charEmbedmsg = await checkForChar(ctx, char, charEmbed) if charDict == None: charEmbed.description = f"**{tier}** is not a valid tier or character name. Please try again with **New** or **0**, **Junior** or **1**, **Journey** or **2**, **Elite** or **3**, **True** or **4**, or **Ascended** or **5**, or input a valid character name." charEmbed.clear_fields() # reuse the message created by checkForChar if charEmbedmsg: await charEmbedmsg.edit(embed=charEmbed) else: await channel.send(embed=charEmbed) return else: characterPresent = True # Calculates rewards and output if a tier was given instead of a character if not characterPresent: tierName = "" if tier.isdigit(): tierName = roleArray[int(tier)] tier = tierName else: tierName = tier.capitalize() cp = ((totalTime) // 1800) / 2 tier = tier.lower() tierNum = 0 if tier == 'junior': tierNum = 0 elif tier == "journey": tierNum = 1 elif tier == "elite": tierNum = 2 elif tier == "true": tierNum = 3 elif tier == "ascended": tierNum = 4 gp = cp * tier_reward_dictionary[tierNum][0] tp = cp * tier_reward_dictionary[tierNum][1] treasureArray = [cp, tp, gp] durationString = timeConversion(totalTime) treasureString = f"{treasureArray[0]} CP, {treasureArray[1]} TP, and {treasureArray[2]} GP" charEmbed.description = f"A {durationString} game would give a **{tierName}** Friend\n{treasureString}" charEmbed.clear_fields() if charEmbedmsg: await charEmbedmsg.edit(embed=charEmbed) else: await channel.send(embed=charEmbed) return else: # Calculates rewards and output if a character was given. if charDict["Level"] < 5: tierNum = 0 elif charDict["Level"] < 11: tierNum = 1 elif charDict["Level"] < 17: tierNum = 2 elif charDict["Level"] < 20: tierNum = 3 else: tierNum = 4 # Uses calculateTreasure to determine the rewards from the quest based on the character treasureArray = calculateTreasure(charDict["Level"], charDict["CP"], tierNum, totalTime) durationString = timeConversion(totalTime) treasureString = f"{treasureArray[0]} CP, {sum(treasureArray[1].values())} TP, {treasureArray[2]} GP" resultLevel = charDict["Level"] resultCP = charDict["CP"] + treasureArray[0] # CP and level calculations if resultLevel < 5: maxCP = 4 else: maxCP = 10 while (resultCP >= maxCP and resultLevel < 20): resultCP -= maxCP resultLevel += 1 if resultLevel > 4: maxCP = 10 # A list comprehension that joins together the TP values with their names into one string. tpString = ", ".join( [f"{value} {key}" for key, value in treasureArray[1].items()]) + ", " totalGold = charDict["GP"] + treasureArray[2] # Final output plugs in the duration string, treasure string, tp string, and other variables to make a coherent output charEmbed.description = f"A {durationString} game would give **{charDict['Name']}** \n{treasureString}\n**{charDict['Name']}** will be level {resultLevel} with {resultCP} CP with an additional {tpString}and {totalGold} gold total!" charEmbed.clear_fields() if charEmbedmsg: await charEmbedmsg.edit(embed=charEmbed) else: await channel.send(embed=charEmbed) return