✨
This commit is contained in:
@@ -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
|
from gwendolyn.utils import PARAMS as params
|
||||||
|
|
||||||
|
|
||||||
|
if typing.TYPE_CHECKING:
|
||||||
|
from gwendolyn_client import Gwendolyn
|
||||||
|
|
||||||
class GamesExtension(Extension):
|
class GamesExtension(Extension):
|
||||||
"""Contains the game commands."""
|
"""Contains the game commands."""
|
||||||
|
|
||||||
|
def dummy(self):
|
||||||
|
# For type checking:
|
||||||
|
self.bot: "Gwendolyn"
|
||||||
|
|
||||||
@slash_command(**params["games"]["money"]["balance"])
|
@slash_command(**params["games"]["money"]["balance"])
|
||||||
async def balance(self, ctx: SlashContext):
|
async def balance(self, ctx: SlashContext):
|
||||||
await self.bot.money.sendBalance(ctx)
|
await self.bot.money.sendBalance(ctx)
|
||||||
|
|
||||||
@slash_command(**params["games"]["money"]["give"])
|
@slash_command(**params["games"]["money"]["give"])
|
||||||
async def give(self, ctx: SlashContext):
|
async def give(self, ctx: SlashContext, user: User, amount: int):
|
||||||
await self.bot.money.giveMoney(ctx)
|
await self.bot.money.giveMoney(ctx, user, amount)
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ class BetterNetflix():
|
|||||||
await ctx.send("```"+message_text[:cut_off_index]+"```")
|
await ctx.send("```"+message_text[:cut_off_index]+"```")
|
||||||
await send_long_message(ctx,message_text[cut_off_index+1:])
|
await send_long_message(ctx,message_text[cut_off_index+1:])
|
||||||
|
|
||||||
ctx.defer()
|
await ctx.defer()
|
||||||
|
|
||||||
message_text = await self._generate_download_list()
|
message_text = await self._generate_download_list()
|
||||||
if not message_text.startswith("```"):
|
if not message_text.startswith("```"):
|
||||||
|
|||||||
@@ -6,8 +6,12 @@ Contains the code that deals with money.
|
|||||||
Money
|
Money
|
||||||
Deals with money.
|
Deals with money.
|
||||||
"""
|
"""
|
||||||
|
import typing
|
||||||
|
|
||||||
import interactions # Used for typehints
|
import interactions # Used for typehints
|
||||||
|
|
||||||
|
if typing.TYPE_CHECKING:
|
||||||
|
from gwendolyn_client import Gwendolyn
|
||||||
|
|
||||||
class Money():
|
class Money():
|
||||||
"""
|
"""
|
||||||
@@ -29,7 +33,7 @@ class Money():
|
|||||||
The mongo database
|
The mongo database
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot: "Gwendolyn"):
|
||||||
"""Initialize the class."""
|
"""Initialize the class."""
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.database = bot.database
|
self.database = bot.database
|
||||||
@@ -70,34 +74,35 @@ class Money():
|
|||||||
response = self.checkBalance("#"+str(ctx.author.id))
|
response = self.checkBalance("#"+str(ctx.author.id))
|
||||||
user_name = ctx.author.display_name
|
user_name = ctx.author.display_name
|
||||||
if response == 1:
|
if response == 1:
|
||||||
new_message = f"{user_name} has {response} GwendoBuck"
|
new_message = f"{user_name} has 1 GwendoBuck"
|
||||||
else:
|
else:
|
||||||
new_message = f"{user_name} has {response} GwendoBucks"
|
new_message = f"{user_name} has {response} GwendoBucks"
|
||||||
await ctx.send(new_message)
|
await ctx.send(new_message)
|
||||||
|
|
||||||
# Adds money to the account of a user
|
# 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.
|
Add money to a user account.
|
||||||
|
|
||||||
*Parameters*
|
*Parameters*
|
||||||
------------
|
------------
|
||||||
user: str
|
user: User
|
||||||
The id of the user to give money.
|
The user to give money.
|
||||||
amount: int
|
amount: int
|
||||||
The amount to add to the user's account.
|
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:
|
if user_data is not None:
|
||||||
updater = {"$inc": {"money": amount}}
|
updater = {"$inc": {"money": amount}}
|
||||||
self.database["users"].update_one({"_id": user}, updater)
|
self.database["users"].update_one({"_id": user_id}, updater)
|
||||||
else:
|
else:
|
||||||
new_user = {
|
new_user = {
|
||||||
"_id": user,
|
"_id": user_id,
|
||||||
"user name": self.bot.database_funcs.get_name(user),
|
"user name": user.display_name,
|
||||||
"money": amount
|
"money": amount
|
||||||
}
|
}
|
||||||
self.database["users"].insert_one(new_user)
|
self.database["users"].insert_one(new_user)
|
||||||
@@ -119,32 +124,17 @@ class Money():
|
|||||||
"""
|
"""
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
username = user.display_name
|
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}"
|
userid = f"#{ctx.author.id}"
|
||||||
user_data = self.database["users"].find_one({"_id": userid})
|
user_data = self.database["users"].find_one({"_id": userid})
|
||||||
targetUser = self.bot.database_funcs.get_id(username)
|
|
||||||
|
|
||||||
if amount <= 0:
|
if amount <= 0:
|
||||||
self.bot.log("They tried to steal")
|
self.bot.log("They tried to steal")
|
||||||
await ctx.send("Yeah, no. You can't do that")
|
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:
|
elif user_data is None or user_data["money"] < amount:
|
||||||
self.bot.log("They didn't have enough GwendoBucks")
|
self.bot.log("They didn't have enough GwendoBucks")
|
||||||
await ctx.send("You don't have that many GwendoBuck")
|
await ctx.send("You don't have that many GwendoBuck")
|
||||||
else:
|
else:
|
||||||
self.addMoney(f"#{ctx.author.id}", -1 * amount)
|
self.addMoney(ctx.author, -1 * amount)
|
||||||
self.addMoney(targetUser, amount)
|
self.addMoney(user, amount)
|
||||||
await ctx.send(f"Transferred {amount} GwendoBucks to {username}")
|
await ctx.send(f"Transferred {amount} GwendoBucks to {username}")
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ class Gwendolyn(Client):
|
|||||||
"""Add all the client, option and credentials objects."""
|
"""Add all the client, option and credentials objects."""
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
self.testing = getenv("GWENDOLYN_TESTING", "False").lower() in ('true', '1', 't')
|
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.enable_nework_services = getenv("NETWORK_SERVICES", "False").lower() in ('true', '1', 't')
|
||||||
|
|
||||||
self.bot_token = getenv("DISCORD_TOKEN")
|
self.bot_token = getenv("DISCORD_TOKEN")
|
||||||
|
|||||||
Reference in New Issue
Block a user