📝 Cogs and utils
Improved code style and added comments and docstrings to cogs and utils.
This commit is contained in:
112
cogs/GameCogs.py
112
cogs/GameCogs.py
@ -1,155 +1,177 @@
|
||||
from discord.ext import commands
|
||||
from discord_slash import cog_ext
|
||||
"""Contains all the cogs that deal with game commands."""
|
||||
from discord.ext import commands # Has the cog class
|
||||
from discord_slash import cog_ext # Used for slash commands
|
||||
|
||||
from utils import getParams
|
||||
from utils import getParams # pylint: disable=import-error
|
||||
|
||||
params = getParams()
|
||||
|
||||
|
||||
class GamesCog(commands.Cog):
|
||||
def __init__(self,bot):
|
||||
"""Runs game stuff."""
|
||||
"""Contains miscellaneous game commands."""
|
||||
|
||||
def __init__(self, bot):
|
||||
"""Initialize the cog."""
|
||||
self.bot = bot
|
||||
|
||||
# Checks user balance
|
||||
@cog_ext.cog_slash(**params["balance"])
|
||||
async def balance(self, ctx):
|
||||
"""Check user balance."""
|
||||
await self.bot.money.sendBalance(ctx)
|
||||
|
||||
# Gives another user an amount of GwendoBucks
|
||||
@cog_ext.cog_slash(**params["give"])
|
||||
async def give(self, ctx, user, amount):
|
||||
"""Give another user an amount of GwendoBucks."""
|
||||
await self.bot.money.giveMoney(ctx, user, amount)
|
||||
|
||||
# Invest GwendoBucks in the stock market
|
||||
@cog_ext.cog_slash(**params["invest"])
|
||||
async def invest(self, ctx, parameters = "check"):
|
||||
async def invest(self, ctx, parameters="check"):
|
||||
"""Invest GwendoBucks in the stock market."""
|
||||
await self.bot.games.invest.parseInvest(ctx, parameters)
|
||||
|
||||
# Runs a game of trivia
|
||||
@cog_ext.cog_slash(**params["trivia"])
|
||||
async def trivia(self, ctx, answer = ""):
|
||||
async def trivia(self, ctx, answer=""):
|
||||
"""Run a game of trivia."""
|
||||
await self.bot.games.trivia.triviaParse(ctx, answer)
|
||||
|
||||
|
||||
class BlackjackCog(commands.Cog):
|
||||
def __init__(self,bot):
|
||||
"""Runs game stuff."""
|
||||
"""Contains the blackjack commands."""
|
||||
|
||||
def __init__(self, bot):
|
||||
"""Initialize the cog."""
|
||||
self.bot = bot
|
||||
|
||||
# Starts a game of blackjack
|
||||
@cog_ext.cog_subcommand(**params["blackjackStart"])
|
||||
async def blackjackStart(self, ctx):
|
||||
"""Start a game of blackjack."""
|
||||
await self.bot.games.blackjack.start(ctx)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackBet"])
|
||||
async def blackjackBet(self, ctx, bet):
|
||||
"""Enter the game of blackjack with a bet."""
|
||||
await self.bot.games.blackjack.playerDrawHand(ctx, bet)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackStand"])
|
||||
async def blackjackStand(self, ctx, hand = ""):
|
||||
async def blackjackStand(self, ctx, hand=""):
|
||||
"""Stand on your hand in blackjack."""
|
||||
await self.bot.games.blackjack.stand(ctx, hand)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackHit"])
|
||||
async def blackjackHit(self, ctx, hand = 0):
|
||||
async def blackjackHit(self, ctx, hand=0):
|
||||
"""Hit on your hand in blackjack."""
|
||||
await self.bot.games.blackjack.hit(ctx, hand)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackDouble"])
|
||||
async def blackjackDouble(self, ctx, hand = 0):
|
||||
async def blackjackDouble(self, ctx, hand=0):
|
||||
"""Double in blackjack."""
|
||||
await self.bot.games.blackjack.double(ctx, hand)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackSplit"])
|
||||
async def blackjackSplit(self, ctx, hand = 0):
|
||||
async def blackjackSplit(self, ctx, hand=0):
|
||||
"""Split your hand in blackjack."""
|
||||
await self.bot.games.blackjack.split(ctx, hand)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackHilo"])
|
||||
async def blackjackHilo(self, ctx):
|
||||
"""Get the hilo value for the deck in blackjack."""
|
||||
await self.bot.games.blackjack.hilo(ctx)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackShuffle"])
|
||||
async def blackjackShuffle(self, ctx):
|
||||
"""Shuffle the blackjack game."""
|
||||
await self.bot.games.blackjack.shuffle(ctx)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackCards"])
|
||||
async def blackjackCards(self, ctx):
|
||||
"""Get the amount of cards left in the blackjack deck."""
|
||||
await self.bot.games.blackjack.cards(ctx)
|
||||
|
||||
|
||||
class ConnectFourCog(commands.Cog):
|
||||
def __init__(self,bot):
|
||||
"""Runs game stuff."""
|
||||
"""Contains all the connect four commands."""
|
||||
|
||||
def __init__(self, bot):
|
||||
"""Initialize the cog."""
|
||||
self.bot = bot
|
||||
|
||||
# Start a game of connect four against a user
|
||||
@cog_ext.cog_subcommand(**params["connectFourStartUser"])
|
||||
async def connectFourStartUser(self, ctx, user):
|
||||
"""Start a game of connect four against another user."""
|
||||
await self.bot.games.connectFour.start(ctx, user)
|
||||
|
||||
# Start a game of connect four against gwendolyn
|
||||
@cog_ext.cog_subcommand(**params["connectFourStartGwendolyn"])
|
||||
async def connectFourStartGwendolyn(self, ctx, difficulty = 3):
|
||||
async def connectFourStartGwendolyn(self, ctx, difficulty=3):
|
||||
"""Start a game of connect four against Gwendolyn."""
|
||||
await self.bot.games.connectFour.start(ctx, difficulty)
|
||||
|
||||
# Stop the current game of connect four
|
||||
@cog_ext.cog_subcommand(**params["connectFourSurrender"])
|
||||
async def connectFourSurrender(self, ctx):
|
||||
"""Surrender the game of connect four."""
|
||||
await self.bot.games.connectFour.surrender(ctx)
|
||||
|
||||
|
||||
class HangmanCog(commands.Cog):
|
||||
def __init__(self,bot):
|
||||
"""Runs game stuff."""
|
||||
"""Contains all the hangman commands."""
|
||||
|
||||
def __init__(self, bot):
|
||||
"""Initialize the cog."""
|
||||
self.bot = bot
|
||||
|
||||
# Starts a game of Hangman
|
||||
@cog_ext.cog_subcommand(**params["hangmanStart"])
|
||||
async def hangmanStart(self, ctx):
|
||||
"""Start a game of hangman."""
|
||||
await self.bot.games.hangman.start(ctx)
|
||||
|
||||
# Stops a game of Hangman
|
||||
@cog_ext.cog_subcommand(**params["hangmanStop"])
|
||||
async def hangmanStop(self, ctx):
|
||||
"""Stop the current game of hangman."""
|
||||
await self.bot.games.hangman.stop(ctx)
|
||||
|
||||
|
||||
class HexCog(commands.Cog):
|
||||
def __init__(self,bot):
|
||||
"""Runs game stuff."""
|
||||
self.bot = bot
|
||||
"""Contains all the hex commands."""
|
||||
|
||||
def __init__(self, bot):
|
||||
"""Initialize the cog."""
|
||||
self.bot = bot
|
||||
self.hex = self.bot.games.hex
|
||||
|
||||
# Start a game of Hex against another user
|
||||
@cog_ext.cog_subcommand(**params["hexStartUser"])
|
||||
async def hexStartUser(self, ctx, user):
|
||||
await self.bot.games.hex.start(ctx, user)
|
||||
"""Start a game of hex against another player."""
|
||||
await self.hex.start(ctx, user)
|
||||
|
||||
# Start a game of Hex against Gwendolyn
|
||||
@cog_ext.cog_subcommand(**params["hexStartGwendolyn"])
|
||||
async def hexStartGwendolyn(self, ctx, difficulty = 2):
|
||||
await self.bot.games.hex.start(ctx, difficulty)
|
||||
async def hexStartGwendolyn(self, ctx, difficulty=2):
|
||||
"""Start a game of hex against Gwendolyn."""
|
||||
await self.hex.start(ctx, difficulty)
|
||||
|
||||
# Place a piece in the hex game
|
||||
@cog_ext.cog_subcommand(**params["hexPlace"])
|
||||
async def hexPlace(self, ctx, coordinates):
|
||||
await self.bot.games.hex.placeHex(ctx, coordinates, f"#{ctx.author.id}")
|
||||
"""Place a piece in the hex game."""
|
||||
await self.hex.placeHex(ctx, coordinates, f"#{ctx.author.id}")
|
||||
|
||||
# Undo your last hex move
|
||||
@cog_ext.cog_subcommand(**params["hexUndo"])
|
||||
async def hexUndo(self, ctx):
|
||||
await self.bot.games.hex.undo(ctx)
|
||||
"""Undo your last hex move."""
|
||||
await self.hex.undo(ctx)
|
||||
|
||||
# Perform a hex swap
|
||||
@cog_ext.cog_subcommand(**params["hexSwap"])
|
||||
async def hexSwap(self, ctx):
|
||||
await self.bot.games.hex.swap(ctx)
|
||||
"""Perform a hex swap."""
|
||||
await self.hex.swap(ctx)
|
||||
|
||||
# Surrender the hex game
|
||||
@cog_ext.cog_subcommand(**params["hexSurrender"])
|
||||
async def hexSurrender(self, ctx):
|
||||
await self.bot.games.hex.surrender(ctx)
|
||||
"""Surrender the hex game."""
|
||||
await self.hex.surrender(ctx)
|
||||
|
||||
|
||||
def setup(bot):
|
||||
"""Add all the cogs to the bot."""
|
||||
bot.add_cog(GamesCog(bot))
|
||||
bot.add_cog(BlackjackCog(bot))
|
||||
bot.add_cog(ConnectFourCog(bot))
|
||||
bot.add_cog(HangmanCog(bot))
|
||||
bot.add_cog(HexCog(bot))
|
||||
bot.add_cog(HexCog(bot))
|
||||
|
Reference in New Issue
Block a user