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 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_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_check(self, context, type): 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) if user_goal: progress = user.get_goal_progress(type) return await context.send(user.get_mention() + ', ' + lib.get_string('goal:status', user.get_guild()).format(progress['percent'], type_string, progress['current'], progress['goal'])) else: return await context.send(user.get_mention() + ', ' + lib.get_string('goal:nogoal', user.get_guild()).format(type_string, type))
async def run_check(self, context): user = User(context.message.author.id, context.guild.id, context) # Currently only daily goals implemented type = 'daily' user_goal = user.get_goal(type) if user_goal: progress = user.get_goal_progress(type) return await context.send( user.get_mention() + ', ' + lib.get_string('goal:status', user.get_guild()).format( progress['str'], progress['percent'], type, progress['current'], progress['goal'])) else: return await context.send( user.get_mention() + ', ' + lib.get_string('goal:nogoal', user.get_guild()).format(type))