summaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/basic_games.py73
-rw-r--r--commands/economy.py42
2 files changed, 115 insertions, 0 deletions
diff --git a/commands/basic_games.py b/commands/basic_games.py
new file mode 100644
index 0000000..0b594ba
--- /dev/null
+++ b/commands/basic_games.py
@@ -0,0 +1,73 @@
+from discord.ext.commands import Bot, Cog
+from discord_slash import cog_ext, SlashContext
+from discord_slash.utils.manage_commands import create_option, create_choice
+from base import config
+from models.user import User
+import random
+import yaml
+
+
+class BasicGames(Cog):
+ def __init__(self, bot: Bot):
+ self.bot = bot
+ with open("config.yaml", "r") as yamlfile:
+ config = yaml.load(yamlfile, Loader=yaml.CLoader)
+ print("Read config successful")
+ self.config = config
+
+ @cog_ext.cog_slash(
+ name="coin_flip",
+ description="Flip a coin",
+ guild_ids=[config["discord_server_id"]],
+ options=[
+ create_option(
+ name="num_coins",
+ description="coins to bet",
+ option_type=4,
+ required=True,
+ ),
+ create_option(
+ name="choice",
+ description="heads or tails?",
+ option_type=3,
+ required=True,
+ choices=[
+ create_choice(name="Heads", value="Heads"),
+ create_choice(name="Tails", value="Tails"),
+ ],
+ ),
+ ],
+ )
+ async def coin_flip(self, ctx: SlashContext, num_coins: int, choice: int):
+ user = User.get(User.discord_id == ctx.author_id)
+
+ await ctx.send(content=f"{user.username} is betting {num_coins} coins on {choice}")
+ result = random.randrange(0, 1)
+ choices = ["Heads", "Tails"]
+ await ctx.send(content=f"Coin flip lands on {choices[result]}")
+ if choice == choices[result]:
+ await ctx.send(content=f"You win {num_coins * 2} coins!")
+ user.add_coins(num_coins * 2)
+ else:
+ await ctx.send(content=f"You lose {num_coins} coins :(")
+ user.remove_coins(num_coins)
+
+ user.save()
+
+ @cog_ext.cog_slash(
+ name="dice",
+ description="Roll some dice.",
+ guild_ids=[config["discord_server_id"]],
+ )
+ async def dice(self, ctx: SlashContext):
+ print("dice")
+ user = User.get(User.discord_id == ctx.author_id)
+ result = random.randrange(1, 6)
+ await ctx.send(content=f"{user.display_name}, you roll a {result}")
+
+
+def setup(bot):
+ bot.add_cog(BasicGames(bot))
+
+ print("Loaded BasicGames")
+ print(config["discord_server_id"])
diff --git a/commands/economy.py b/commands/economy.py
new file mode 100644
index 0000000..1960827
--- /dev/null
+++ b/commands/economy.py
@@ -0,0 +1,42 @@
+from discord.ext.commands import Bot, Cog
+from discord_slash import cog_ext, SlashContext
+from base import config
+from models.user import User
+import random
+import yaml
+
+
+class Economy(Cog):
+ def __init__(self, bot: Bot):
+ self.bot = bot
+ with open("config.yaml", "r") as yamlfile:
+ config = yaml.load(yamlfile, Loader=yaml.CLoader)
+ print("Read config successful")
+ self.config = config
+ print(config["discord_server_id"])
+
+ @cog_ext.cog_slash(
+ name="daily",
+ description="Get some coins.",
+ guild_ids=[config["discord_server_id"]],
+ )
+ async def daily(self, ctx: SlashContext):
+ user = User.get(User.discord_id == ctx.author_id)
+ num_coins = random.randrange(50, 100)
+ user.add_coins(num_coins)
+ user.save()
+ await ctx.send(content="Here have some coins")
+
+ @cog_ext.cog_slash(
+ name="coins",
+ description="Check your coins.",
+ guild_ids=[config["discord_server_id"]],
+ )
+ async def coins(self, ctx: SlashContext):
+ user = User.get(User.discord_id == ctx.author_id)
+ await ctx.send(content=f"{user.display_name}, you have {user.currency} coins")
+
+
+def setup(bot):
+ bot.add_cog(Economy(bot))
+ print("Loaded Economy")