async def setmile(cls, user, guild_id: int, time: str): session = Session() fitness = await cls.get_user(user.lower(), guild_id) fitness.mile = time session.add(fitness) session.commit() session.close()
async def auto_remove_event(cls, guild_id: int, event_id): session = Session() event = session.query(CountdownEvents).filter_by(id=event_id, guild_id=guild_id).first() session.delete(event) session.commit() session.close()
async def setohp(cls, user, guild_id: int, weight: float): session = Session() fitness = await cls.get_user(user.lower(), guild_id) fitness.ohp = weight session.add(fitness) session.commit() session.close()
async def setgender(cls, user, guild_id: int, gender: str): session = Session() fitness = await cls.get_user(user.lower(), guild_id) fitness.gender = gender.lower() session.add(fitness) session.commit() session.close()
async def setburpees(cls, user, guild_id: int, count: int): session = Session() fitness = await cls.get_user(user.lower(), guild_id) fitness.burpess_1m = count session.add(fitness) session.commit() session.close()
async def add_event(cls, guild_id: int, event_name: str, event_date: date): session = Session() event = CountdownEvents() event.guild_id = guild_id event.event_name = event_name event.event_date = event_date session.add(event) session.commit() session.close()
async def remove_event(cls, guild_id: int, event_name: str, event_date: date): session = Session() event = session.query(CountdownEvents).filter_by( guild_id=guild_id, event_name=event_name, event_date=event_date).first() if event is not None: session.delete(event) session.commit() session.close() return True return False
async def add_reminder(cls, guild_id, user, reminder_msg, channel, reminder_time): session = Session() reminder = Reminders() reminder.guild_id = guild_id reminder.user = user reminder.message = reminder_msg reminder.channel = channel reminder.when = reminder_time session.add(reminder) session.commit() session.close()
async def get_user(cls, user, guild_id: int): """ Checks to see if a user exists already. If not, it creates a new record. Returns user record. :param user: the user to fetch :param guild_id: the id of the discord server the user belongs to :return: the user record """ session = Session() fitness = session.query(Fitness).filter_by(user=user.lower(), guild_id=guild_id).first() if fitness is None: fitness = Fitness() fitness.user = user.lower() fitness.guild_id = guild_id session.close() return fitness session.close() return fitness
async def remove_reminder(cls, reminder_id): session = Session() reminder = session.query(Reminders).filter_by(id=reminder_id).first() session.delete(reminder) session.commit() session.close()