diff --git a/cogs/fun.py b/cogs/fun.py index 8e3325a..50864b3 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -28,57 +28,6 @@ async def decide_command(interaction): choice = "No" await interaction.response.send(f"{choice}\n-# note: this is completely randomized. use some common sense!!") -@discohook.command.slash('rps', description = 'Play RPS against the bot!',options=[discohook.Option.string("choice", "Your choice", required=True, choices=[ - discohook.Choice("Rock","rock"), - discohook.Choice("Paper", "paper"), - discohook.Choice("Scissors","scissors") -])]) -async def rps_command(interaction, choice): - bot_choice = random.randint(1,3) - if bot_choice == 1: - bot_choice = "rock" - elif bot_choice == 2: - bot_choice = "paper" - elif bot_choice == 3: - bot_choice = "scissors" - - if bot_choice == choice: - # tie (any) - win = "That's a tie!" - elif choice == "rock" and bot_choice == "paper": - # paper vs rock (bot win) - win = "Bot wins!" - elif choice == "rock" and bot_choice == "scissors": - # scissors vs rock (you win) - win = "You win!" - elif choice == "paper" and bot_choice == "scissors": - # scissors vs paper (bot wins) - win = "Bot wins!" - elif choice == "scissors" and bot_choice == "paper": - # scissors vs paper (you win) - win = "You win!" - elif choice == "paper" and bot_choice == "rock": - # paper vs rock (you win) - win = "You win!" - elif choice == "scissors" and bot_choice == "rock": - # scissors vs rock (bot win) - win = "Bot wins!" - - text = '\n'.join([ - f"You chose {choice}", - f"Bot chose {bot_choice}", - win - ]) - await interaction.response.send(text) - -@discohook.command.slash('gtn', description = 'Guess the number! It\'s completely random every single time you run this command, so... good luck!', options=[discohook.Option.integer("num", "The number to guess", required=True, min_value=0, max_value=9999)]) -async def gtn_command(interaction, num: int): - number = random.randint(0,9999) - if int(num) == number: - await interaction.response.send("Somehow, with a 1/9999 chance, you guessed the number!") - else: - await interaction.response.send(f"You didn't guess the number. Try again! The number was {number} by the way.") - @discohook.command.slash('factoftheday', description="Fun facts!") async def funfact_cmd(interaction): async with aiohttp.ClientSession(base_url="https://uselessfacts.jsph.pl") as session: diff --git a/cogs/games.py b/cogs/games.py new file mode 100644 index 0000000..76b6805 --- /dev/null +++ b/cogs/games.py @@ -0,0 +1,57 @@ +""" +This is a cog with simple games in it. +""" + +import random +import discohook + +@discohook.command.slash('gtn', description = 'Guess the number! It\'s completely random every single time you run this command, so... good luck!', options=[discohook.Option.integer("num", "The number to guess", required=True, min_value=0, max_value=9999)]) +async def gtn_command(interaction, num: int): + number = random.randint(0,9999) + if int(num) == number: + await interaction.response.send("Somehow, with a 1/9999 chance, you guessed the number!") + else: + await interaction.response.send(f"You didn't guess the number. Try again! The number was {number} by the way.") + +@discohook.command.slash('rps', description = 'Play RPS against the bot!',options=[discohook.Option.string("choice", "Your choice", required=True, choices=[ + discohook.Choice("Rock","rock"), + discohook.Choice("Paper", "paper"), + discohook.Choice("Scissors","scissors") +])]) +async def rps_command(interaction, choice): + bot_choice = random.randint(1,3) + if bot_choice == 1: + bot_choice = "rock" + elif bot_choice == 2: + bot_choice = "paper" + elif bot_choice == 3: + bot_choice = "scissors" + + if bot_choice == choice: + # tie (any) + msg = "That's a tie!" + elif choice == "rock" and bot_choice == "paper": + # paper vs rock (bot win) + msg = "Bot wins!" + elif choice == "rock" and bot_choice == "scissors": + # scissors vs rock (you win) + msg = "You win!" + elif choice == "paper" and bot_choice == "scissors": + # scissors vs paper (bot wins) + msg = "Bot wins!" + elif choice == "scissors" and bot_choice == "paper": + # scissors vs paper (you win) + msg = "You win!" + elif choice == "paper" and bot_choice == "rock": + # paper vs rock (you win) + msg = "You win!" + elif choice == "scissors" and bot_choice == "rock": + # scissors vs rock (bot win) + msg = "Bot wins!" + + text = '\n'.join([ + f"You chose {choice}", + f"Bot chose {bot_choice}", + msg + ]) + await interaction.response.send(text) diff --git a/main.py b/main.py index 584c6e0..7e30ff3 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,8 @@ import aiohttp import discohook from starlette.responses import JSONResponse from cogs.utils import ping_command, timestamp_command, info_command -from cogs.fun import dice_command, decide_command, rps_command, gtn_command, funfact_cmd, randomgif_cmd, old_dice_command +from cogs.fun import dice_command, decide_command, funfact_cmd, randomgif_cmd, old_dice_command +from cogs.games import rps_command, gtn_command def run(): @contextlib.asynccontextmanager @@ -49,11 +50,12 @@ def run(): ### --- Cog: Fun --- ### dice_command, decide_command, - rps_command, - gtn_command, funfact_cmd, randomgif_cmd, - old_dice_command + old_dice_command, + ### --- Cog: Games --- ### + rps_command, + gtn_command ) return app