From ed1ea1f7afd85f99e3b88bd9101207f5fd96cba4 Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Tue, 28 Oct 2025 17:34:32 +0100 Subject: [PATCH] :sparkles: --- gwendolyn/ext/games.py | 17 +++++-- .../funcs/better_netflix/better_netflix.py | 2 +- gwendolyn/funcs/games/money.py | 44 +++++++------------ gwendolyn/gwendolyn_client.py | 3 ++ 4 files changed, 35 insertions(+), 31 deletions(-) diff --git a/gwendolyn/ext/games.py b/gwendolyn/ext/games.py index 4909c87..e06c7f8 100644 --- a/gwendolyn/ext/games.py +++ b/gwendolyn/ext/games.py @@ -1,12 +1,23 @@ -from interactions import Extension, slash_command, SlashContext +import typing + +from interactions import Extension, slash_command, SlashContext, User, Client from gwendolyn.utils import PARAMS as params + +if typing.TYPE_CHECKING: + from gwendolyn_client import Gwendolyn + class GamesExtension(Extension): """Contains the game commands.""" + + def dummy(self): + # For type checking: + self.bot: "Gwendolyn" + @slash_command(**params["games"]["money"]["balance"]) async def balance(self, ctx: SlashContext): await self.bot.money.sendBalance(ctx) @slash_command(**params["games"]["money"]["give"]) - async def give(self, ctx: SlashContext): - await self.bot.money.giveMoney(ctx) + async def give(self, ctx: SlashContext, user: User, amount: int): + await self.bot.money.giveMoney(ctx, user, amount) diff --git a/gwendolyn/funcs/better_netflix/better_netflix.py b/gwendolyn/funcs/better_netflix/better_netflix.py index ae3e96f..7e1c41a 100644 --- a/gwendolyn/funcs/better_netflix/better_netflix.py +++ b/gwendolyn/funcs/better_netflix/better_netflix.py @@ -289,7 +289,7 @@ class BetterNetflix(): await ctx.send("```"+message_text[:cut_off_index]+"```") await send_long_message(ctx,message_text[cut_off_index+1:]) - ctx.defer() + await ctx.defer() message_text = await self._generate_download_list() if not message_text.startswith("```"): diff --git a/gwendolyn/funcs/games/money.py b/gwendolyn/funcs/games/money.py index 3a1468a..9e6b222 100644 --- a/gwendolyn/funcs/games/money.py +++ b/gwendolyn/funcs/games/money.py @@ -6,8 +6,12 @@ Contains the code that deals with money. Money Deals with money. """ +import typing + import interactions # Used for typehints +if typing.TYPE_CHECKING: + from gwendolyn_client import Gwendolyn class Money(): """ @@ -29,7 +33,7 @@ class Money(): The mongo database """ - def __init__(self, bot): + def __init__(self, bot: "Gwendolyn"): """Initialize the class.""" self.bot = bot self.database = bot.database @@ -70,34 +74,35 @@ class Money(): response = self.checkBalance("#"+str(ctx.author.id)) user_name = ctx.author.display_name if response == 1: - new_message = f"{user_name} has {response} GwendoBuck" + new_message = f"{user_name} has 1 GwendoBuck" else: new_message = f"{user_name} has {response} GwendoBucks" await ctx.send(new_message) # Adds money to the account of a user - def addMoney(self, user: str, amount: int): + def addMoney(self, user: interactions.User, amount: int): """ Add money to a user account. *Parameters* ------------ - user: str - The id of the user to give money. + user: User + The user to give money. amount: int The amount to add to the user's account. """ - self.bot.log("adding "+str(amount)+" to "+user+"'s account") + self.bot.log(f"adding {amount} to {user}'s account") + user_id = f"#{user.id}" - user_data = self.database["users"].find_one({"_id": user}) + user_data = self.database["users"].find_one({"_id": user_id}) if user_data is not None: updater = {"$inc": {"money": amount}} - self.database["users"].update_one({"_id": user}, updater) + self.database["users"].update_one({"_id": user_id}, updater) else: new_user = { - "_id": user, - "user name": self.bot.database_funcs.get_name(user), + "_id": user_id, + "user name": user.display_name, "money": amount } self.database["users"].insert_one(new_user) @@ -119,32 +124,17 @@ class Money(): """ await ctx.defer() username = user.display_name - if self.bot.database_funcs.get_id(username) is None: - async for member in ctx.guild.fetch_members(limit=None): - if member.display_name.lower() == username.lower(): - username = member.display_name - user_id = f"#{member.id}" - new_user = { - "_id": user_id, - "user name": username, - "money": 0 - } - self.bot.database["users"].insert_one(new_user) userid = f"#{ctx.author.id}" user_data = self.database["users"].find_one({"_id": userid}) - targetUser = self.bot.database_funcs.get_id(username) if amount <= 0: self.bot.log("They tried to steal") await ctx.send("Yeah, no. You can't do that") - elif targetUser is None: - self.bot.log("They weren't in the system") - await ctx.send("The target doesn't exist") elif user_data is None or user_data["money"] < amount: self.bot.log("They didn't have enough GwendoBucks") await ctx.send("You don't have that many GwendoBuck") else: - self.addMoney(f"#{ctx.author.id}", -1 * amount) - self.addMoney(targetUser, amount) + self.addMoney(ctx.author, -1 * amount) + self.addMoney(user, amount) await ctx.send(f"Transferred {amount} GwendoBucks to {username}") diff --git a/gwendolyn/gwendolyn_client.py b/gwendolyn/gwendolyn_client.py index a4e59f9..a86093a 100644 --- a/gwendolyn/gwendolyn_client.py +++ b/gwendolyn/gwendolyn_client.py @@ -26,6 +26,9 @@ class Gwendolyn(Client): """Add all the client, option and credentials objects.""" load_dotenv() self.testing = getenv("GWENDOLYN_TESTING", "False").lower() in ('true', '1', 't') + if self.testing: + self.log("Testing mode", level=25) + self.enable_nework_services = getenv("NETWORK_SERVICES", "False").lower() in ('true', '1', 't') self.bot_token = getenv("DISCORD_TOKEN")