From e80f2ec820c7b65083a3635ce006ed29c30744a1 Mon Sep 17 00:00:00 2001 From: Zed Date: Thu, 2 Mar 2023 17:49:27 -0600 Subject: [PATCH] Add clear command --- game/clear.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 game/clear.py diff --git a/game/clear.py b/game/clear.py new file mode 100644 index 0000000..1d320b7 --- /dev/null +++ b/game/clear.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +# Copyright 2022 - c0de +# Licensed under the MIT License (https://opensource.org/licenses/MIT) + +# pylint: disable=missing-module-docstring,too-few-public-methods + +from database.models import PlayerModel as Player +from game.base import BaseGameManager + + +class ClearManager(BaseGameManager): + """Commands that run when a player clears the session leaderboard""" + + def __init__(self): + super().__init__() + self.commands.append(("clear", self.clear)) + + async def clear(self): + """Clear command - Clears the session scoreboard""" + + players = Player.select(Player.total_points) + + for player in players: + player.total_points = 0 + + Player.bulk_update(players, Player.total_points) + + clear_message = "The score has been cleared!" + + recipient = await self.discord.fetch_user(self.message.author.id) + await recipient.send(clear_message)