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_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()))