refactor(fun): cogs into one group

Combined all fun commands into a single 'fun' GroupCog with subcommands, replacing individual cogs for coinflip, eightball, minesweeper, randomfact, and rockpaperscissors. Updated bot.py to load the fun cog as a package and adjusted help.py to reflect the new command structure. This improves organization and discoverability of fun commands.
This commit is contained in:
neoarz
2025-09-28 22:48:10 -04:00
parent 6ed3b0d378
commit e7ee97074b
8 changed files with 114 additions and 93 deletions

55
cogs/fun/__init__.py Normal file
View File

@@ -0,0 +1,55 @@
import discord
from discord.ext import commands
from discord.ext.commands import Context
from .coinflip import coinflip_command
from .eightball import eightball_command
from .minesweeper import minesweeper_command
from .randomfact import randomfact_command
from .rockpaperscissors import rps_command
class Fun(commands.GroupCog, name="fun"):
def __init__(self, bot) -> None:
self.bot = bot
super().__init__()
@commands.hybrid_command(
name="coinflip",
description="Make a coin flip, but give your bet before."
)
async def coinflip(self, context):
return await coinflip_command()(self, context)
@commands.hybrid_command(
name="8ball",
description="Ask any question to the bot.",
)
async def eight_ball(self, context, *, question: str):
return await eightball_command()(self, context, question=question)
@commands.hybrid_command(
name="minesweeper",
description="Play a buttoned minesweeper mini-game."
)
async def minesweeper(self, context):
return await minesweeper_command()(self, context)
@commands.hybrid_command(name="randomfact", description="Get a random fact.")
async def randomfact(self, context):
return await randomfact_command()(self, context)
@commands.hybrid_command(
name="rps", description="Play the rock paper scissors game against the bot."
)
async def rock_paper_scissors(self, context):
return await rps_command()(self, context)
async def setup(bot) -> None:
cog = Fun(bot)
await bot.add_cog(cog)
bot.logger.info("Loaded extension 'fun.coinflip'")
bot.logger.info("Loaded extension 'fun.8ball'")
bot.logger.info("Loaded extension 'fun.minesweeper'")
bot.logger.info("Loaded extension 'fun.randomfact'")
bot.logger.info("Loaded extension 'fun.rps'")

View File

@@ -1,7 +1,6 @@
import random
import discord
from discord.ext import commands
from discord.ext.commands import Context
class Choice(discord.ui.View):
def __init__(self) -> None:
@@ -22,18 +21,12 @@ class Choice(discord.ui.View):
self.value = "tails"
self.stop()
class CoinFlip(commands.Cog, name="coinflip"):
def __init__(self, bot) -> None:
self.bot = bot
def coinflip_command():
@commands.hybrid_command(
name="coinflip", description="Make a coin flip, but give your bet before."
name="coinflip",
description="Make a coin flip, but give your bet before."
)
async def coinflip(self, context: Context) -> None:
"""
Make a coin flip, but give your bet before.
:param context: The hybrid command context.
"""
async def coinflip(self, context):
buttons = Choice()
embed = discord.Embed(
title="Coinflip",
@@ -59,6 +52,5 @@ class CoinFlip(commands.Cog, name="coinflip"):
)
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
await message.edit(embed=embed, view=None, content=None)
async def setup(bot) -> None:
await bot.add_cog(CoinFlip(bot))
return coinflip

View File

@@ -1,26 +1,12 @@
import random
import discord
from discord import app_commands
from discord.ext import commands
from discord.ext.commands import Context
class EightBall(commands.Cog, name="8ball"):
def __init__(self, bot) -> None:
self.bot = bot
def eightball_command():
@commands.hybrid_command(
name="8ball",
description="Ask any question to the bot.",
)
@app_commands.describe(question="The question you want to ask.")
async def eight_ball(self, context: Context, *, question: str) -> None:
"""
Ask any question to the bot.
:param context: The hybrid command context.
:param question: The question that should be asked by the user.
"""
async def eight_ball(self, context, *, question: str):
answers = [
"It is certain.",
"It is decidedly so.",
@@ -51,7 +37,5 @@ class EightBall(commands.Cog, name="8ball"):
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
embed.set_footer(text=f"The question was: {question}")
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(EightBall(bot))
return eight_ball

View File

@@ -2,8 +2,6 @@ import random
from itertools import repeat
import discord
from discord.ext import commands
from discord.ext.commands import Context
class RowButton(discord.ui.Button):
def __init__(self, ctx, label, custom_id, bombs, board):
@@ -66,7 +64,6 @@ class RowButton(discord.ui.Button):
await interaction.edit_original_response(view=view)
class MsView(discord.ui.View):
def __init__(self, ctx, options, bombs, board):
super().__init__()
@@ -155,21 +152,13 @@ class MsView(discord.ui.View):
self.GetBoardPos(pos)
] = bombemo
class Minesweeper(commands.Cog, name="minesweeper"):
def __init__(self, bot) -> None:
self.bot = bot
def minesweeper_command():
@commands.hybrid_command(
name="minesweeper",
description="Play a buttoned minesweeper mini-game."
)
async def minesweeper(self, context: Context) -> None:
"""
Play a buttoned minesweeper mini-game.
:param context: The hybrid command context.
"""
board = [[" "] * 5 for _ in range(5)] # Unicode block character, usually doesnt show up in Discord or github, search up invisible character on google
async def minesweeper(self, context):
board = [[" "] * 5 for _ in range(5)]
bombs = 0
bombpositions = []
for x in repeat(None, random.randint(4, 11)):
@@ -197,7 +186,5 @@ class Minesweeper(commands.Cog, name="minesweeper"):
view = MsView(context, ExtractBlocks(), bombpositions, board)
message = await context.send(embed=embed, view=view)
view.message = message
async def setup(bot) -> None:
await bot.add_cog(Minesweeper(bot))
return minesweeper

View File

@@ -1,15 +1,10 @@
import aiohttp
import discord
from discord.ext import commands
from discord.ext.commands import Context
class RandomFact(commands.Cog, name="randomfact"):
def __init__(self, bot) -> None:
self.bot = bot
def randomfact_command():
@commands.hybrid_command(name="randomfact", description="Get a random fact.")
async def randomfact(self, context: Context) -> None:
async def randomfact(self, context):
async with aiohttp.ClientSession() as session:
async with session.get(
"https://uselessfacts.jsph.pl/random.json?language=en"
@@ -30,7 +25,5 @@ class RandomFact(commands.Cog, name="randomfact"):
)
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(RandomFact(bot))
return randomfact

View File

@@ -1,7 +1,6 @@
import random
import discord
from discord.ext import commands
from discord.ext.commands import Context
class RockPaperScissors(discord.ui.Select):
def __init__(self) -> None:
@@ -39,7 +38,6 @@ class RockPaperScissors(discord.ui.Select):
winner = (3 + user_choice_index - bot_choice_index) % 3
# Get the user mention
user_mention = interaction.user.mention
if winner == 0:
@@ -61,14 +59,11 @@ class RockPaperScissorsView(discord.ui.View):
super().__init__()
self.add_item(RockPaperScissors())
class RPS(commands.Cog, name="rps"):
def __init__(self, bot) -> None:
self.bot = bot
def rps_command():
@commands.hybrid_command(
name="rps", description="Play the rock paper scissors game against the bot."
)
async def rock_paper_scissors(self, context: Context) -> None:
async def rock_paper_scissors(self, context):
view = RockPaperScissorsView()
embed = discord.Embed(
title="Rock Paper Scissors",
@@ -77,6 +72,5 @@ class RPS(commands.Cog, name="rps"):
)
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
await context.send(embed=embed, view=view)
async def setup(bot) -> None:
await bot.add_cog(RPS(bot))
return rock_paper_scissors