PEP in utils

This commit is contained in:
Nikolaj
2021-06-16 14:12:21 +02:00
parent 8c253aca3d
commit b68d62cf6c
137 changed files with 1159 additions and 1251 deletions

View File

@ -0,0 +1,40 @@
"""Contains the EventCog, which runs code for specific bot events."""
from discord.ext import commands # Has the cog class
class EventCog(commands.Cog):
"""Handles bot events."""
def __init__(self, bot):
"""Initialize the bot."""
self.bot = bot
self.bot.on_error = self.on_error
@commands.Cog.listener()
async def on_ready(self):
"""Log and set bot status when bot logs in."""
await self.bot.event_handler.on_ready()
@commands.Cog.listener()
async def on_slash_command(self, ctx):
"""Log when a slash command is run."""
await self.bot.event_handler.on_slash_command(ctx)
@commands.Cog.listener()
async def on_slash_command_error(self, ctx, error):
"""Log when a slash error occurs."""
await self.bot.error_handler.on_slash_command_error(ctx, error)
async def on_error(self, method, *args, **kwargs): # pylint: disable=unused-argument
"""Log when an error occurs."""
await self.bot.error_handler.on_error(method)
@commands.Cog.listener()
async def on_reaction_add(self, reaction, user):
"""Handle when someone reacts to a message."""
await self.bot.event_handler.on_reaction_add(reaction, user)
def setup(bot):
"""Add the eventcog to the bot."""
bot.add_cog(EventCog(bot))

177
gwendolyn/cogs/game_cog.py Normal file
View File

@ -0,0 +1,177 @@
"""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 gwendolyn.utils import get_params # pylint: disable=import-error
params = get_params()
class GamesCog(commands.Cog):
"""Contains miscellaneous game commands."""
def __init__(self, bot):
"""Initialize the cog."""
self.bot = bot
@cog_ext.cog_slash(**params["balance"])
async def balance(self, ctx):
"""Check user balance."""
await self.bot.money.sendBalance(ctx)
@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)
@cog_ext.cog_slash(**params["invest"])
async def invest(self, ctx, parameters="check"):
"""Invest GwendoBucks in the stock market."""
await self.bot.games.invest.parseInvest(ctx, parameters)
@cog_ext.cog_slash(**params["trivia"])
async def trivia(self, ctx, answer=""):
"""Run a game of trivia."""
await self.bot.games.trivia.triviaParse(ctx, answer)
class BlackjackCog(commands.Cog):
"""Contains the blackjack commands."""
def __init__(self, bot):
"""Initialize the cog."""
self.bot = bot
@cog_ext.cog_subcommand(**params["blackjack_start"])
async def blackjack_start(self, ctx):
"""Start a game of blackjack."""
await self.bot.games.blackjack.start(ctx)
@cog_ext.cog_subcommand(**params["blackjack_bet"])
async def blackjack_bet(self, ctx, bet):
"""Enter the game of blackjack with a bet."""
await self.bot.games.blackjack.enterGame(ctx, bet)
@cog_ext.cog_subcommand(**params["blackjack_stand"])
async def blackjack_stand(self, ctx, hand=""):
"""Stand on your hand in blackjack."""
await self.bot.games.blackjack.stand(ctx, hand)
@cog_ext.cog_subcommand(**params["blackjack_hit"])
async def blackjack_hit(self, ctx, hand=0):
"""Hit on your hand in blackjack."""
await self.bot.games.blackjack.hit(ctx, hand)
@cog_ext.cog_subcommand(**params["blackjack_double"])
async def blackjack_double(self, ctx, hand=0):
"""Double in blackjack."""
await self.bot.games.blackjack.double(ctx, hand)
@cog_ext.cog_subcommand(**params["blackjack_split"])
async def blackjack_split(self, ctx, hand=0):
"""Split your hand in blackjack."""
await self.bot.games.blackjack.split(ctx, hand)
@cog_ext.cog_subcommand(**params["blackjack_hilo"])
async def blackjack_hilo(self, ctx):
"""Get the hilo value for the deck in blackjack."""
await self.bot.games.blackjack.hilo(ctx)
@cog_ext.cog_subcommand(**params["blackjack_shuffle"])
async def blackjack_shuffle(self, ctx):
"""Shuffle the blackjack game."""
await self.bot.games.blackjack.shuffle(ctx)
@cog_ext.cog_subcommand(**params["blackjack_cards"])
async def blackjack_cards(self, ctx):
"""Get the amount of cards left in the blackjack deck."""
await self.bot.games.blackjack.cards(ctx)
class ConnectFourCog(commands.Cog):
"""Contains all the connect four commands."""
def __init__(self, bot):
"""Initialize the cog."""
self.bot = bot
@cog_ext.cog_subcommand(**params["connect_four_start_user"])
async def connect_four_start_user(self, ctx, user):
"""Start a game of connect four against another user."""
await self.bot.games.connect_four.start(ctx, user)
@cog_ext.cog_subcommand(**params["connect_four_start_gwendolyn"])
async def connect_four_start_gwendolyn(self, ctx, difficulty=3):
"""Start a game of connect four against Gwendolyn."""
await self.bot.games.connect_four.start(ctx, difficulty)
@cog_ext.cog_subcommand(**params["connect_four_surrender"])
async def connect_four_surrender(self, ctx):
"""Surrender the game of connect four."""
await self.bot.games.connect_four.surrender(ctx)
class HangmanCog(commands.Cog):
"""Contains all the hangman commands."""
def __init__(self, bot):
"""Initialize the cog."""
self.bot = bot
@cog_ext.cog_subcommand(**params["hangman_start"])
async def hangman_start(self, ctx):
"""Start a game of hangman."""
await self.bot.games.hangman.start(ctx)
@cog_ext.cog_subcommand(**params["hangman_stop"])
async def hangman_stop(self, ctx):
"""Stop the current game of hangman."""
await self.bot.games.hangman.stop(ctx)
class HexCog(commands.Cog):
"""Contains all the hex commands."""
def __init__(self, bot):
"""Initialize the cog."""
self.bot = bot
self.hex = self.bot.games.hex
@cog_ext.cog_subcommand(**params["hex_start_user"])
async def hex_start_user(self, ctx, user):
"""Start a game of hex against another player."""
await self.hex.start(ctx, user)
@cog_ext.cog_subcommand(**params["hex_start_gwendolyn"])
async def hex_start_gwendolyn(self, ctx, difficulty=2):
"""Start a game of hex against Gwendolyn."""
await self.hex.start(ctx, difficulty)
@cog_ext.cog_subcommand(**params["hex_place"])
async def hex_place(self, ctx, coordinates):
"""Place a piece in the hex game."""
await self.hex.placeHex(ctx, coordinates, f"#{ctx.author.id}")
@cog_ext.cog_subcommand(**params["hex_undo"])
async def hex_undo(self, ctx):
"""Undo your last hex move."""
await self.hex.undo(ctx)
@cog_ext.cog_subcommand(**params["hex_swap"])
async def hex_swap(self, ctx):
"""Perform a hex swap."""
await self.hex.swap(ctx)
@cog_ext.cog_subcommand(**params["hex_surrender"])
async def hex_surrender(self, 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))

View File

@ -0,0 +1,32 @@
"""Contains the LookupCog, which deals with the lookup commands."""
from discord.ext import commands # Has the cog class
from discord_slash import cog_ext # Used for slash commands
from gwendolyn.utils import get_params # pylint: disable=import-error
params = get_params()
class LookupCog(commands.Cog):
"""Contains the lookup commands."""
def __init__(self, bot):
"""Initialize the cog."""
self.bot = bot
# Looks up a spell
@cog_ext.cog_slash(**params["spell"])
async def spell(self, ctx, query):
"""Look up a spell."""
await self.bot.lookup_funcs.spellFunc(ctx, query)
# Looks up a monster
@cog_ext.cog_slash(**params["monster"])
async def monster(self, ctx, query):
"""Look up a monster."""
await self.bot.lookup_funcs.monsterFunc(ctx, query)
def setup(bot):
"""Add the cog to the bot."""
bot.add_cog(LookupCog(bot))

View File

@ -0,0 +1,99 @@
"""Contains the MiscCog, which deals with miscellaneous commands."""
from discord.ext import commands # Has the cog class
from discord_slash import cog_ext # Used for slash commands
from gwendolyn.utils import get_params # pylint: disable=import-error
params = get_params()
class MiscCog(commands.Cog):
"""Contains the miscellaneous commands."""
def __init__(self, bot):
"""Initialize the cog."""
self.bot = bot
self.bot.remove_command("help")
self.generators = bot.other.generators
self.bedre_netflix = bot.other.bedre_netflix
self.nerd_shit = bot.other.nerd_shit
@cog_ext.cog_slash(**params["ping"])
async def ping(self, ctx):
"""Send the bot's latency."""
await ctx.send(f"Pong!\nLatency is {round(self.bot.latency * 1000)}ms")
@cog_ext.cog_slash(**params["stop"])
async def stop(self, ctx):
"""Stop the bot."""
await self.bot.stop(ctx)
@cog_ext.cog_slash(**params["help"])
async def help_command(self, ctx, command=""):
"""Get help for commands."""
await self.bot.other.helpFunc(ctx, command)
@cog_ext.cog_slash(**params["thank"])
async def thank(self, ctx):
"""Thank the bot."""
await ctx.send("You're welcome :blush:")
@cog_ext.cog_slash(**params["hello"])
async def hello(self, ctx):
"""Greet the bot."""
await self.bot.other.helloFunc(ctx)
@cog_ext.cog_slash(**params["roll"])
async def roll(self, ctx, dice="1d20"):
"""Roll dice."""
await self.bot.other.rollDice(ctx, dice)
@cog_ext.cog_slash(**params["image"])
async def image(self, ctx):
"""Get a random image from Bing."""
await self.bot.other.imageFunc(ctx)
@cog_ext.cog_slash(**params["movie"])
async def movie(self, ctx):
"""Get a random movie from the Plex server."""
await self.bot.other.movieFunc(ctx)
@cog_ext.cog_slash(**params["name"])
async def name(self, ctx):
"""Generate a random name."""
await self.generators.nameGen(ctx)
@cog_ext.cog_slash(**params["tavern"])
async def tavern(self, ctx):
"""Generate a random tavern name."""
await self.generators.tavernGen(ctx)
@cog_ext.cog_slash(**params["wiki"])
async def wiki(self, ctx, wiki_page=""):
"""Get a page on a fandom wiki."""
await self.bot.other.findWikiPage(ctx, wiki_page)
@cog_ext.cog_slash(**params["add_movie"])
async def add_movie(self, ctx, movie):
"""Search for a movie and add it to the Plex server."""
await self.bedre_netflix.requestMovie(ctx, movie)
@cog_ext.cog_slash(**params["add_show"])
async def add_show(self, ctx, show):
"""Search for a show and add it to the Plex server."""
await self.bedre_netflix.requestShow(ctx, show)
@cog_ext.cog_slash(**params["downloading"])
async def downloading(self, ctx, parameters="-d"):
"""Get the current downloading torrents."""
await self.bedre_netflix.downloading(ctx, parameters)
@cog_ext.cog_slash(**params["wolf"])
async def wolf(self, ctx, query):
"""Perform a search on Wolfram Alpha."""
await self.nerd_shit.wolfSearch(ctx, query)
def setup(bot):
"""Add the cog to the bot."""
bot.add_cog(MiscCog(bot))

View File

@ -0,0 +1,40 @@
"""Contains the StarWarsCog, which deals with Star Wars commands."""
from discord.ext import commands
from discord_slash import cog_ext
from gwendolyn.utils import get_params # pylint: disable=import-error
params = get_params()
class StarWarsCog(commands.Cog):
"""Contains the Star Wars commands."""
def __init__(self, bot):
"""Initialize the cog."""
self.bot = bot
@cog_ext.cog_slash(**params["star_wars_roll"])
async def star_wars_roll(self, ctx, dice=""):
"""Roll Star Wars dice."""
await self.bot.star_wars.roll.parseRoll(ctx, dice)
@cog_ext.cog_slash(**params["star_wars_destiny"])
async def star_wars_destiny(self, ctx, parameters=""):
"""Control Star Wars destiny points."""
await self.bot.star_wars.destiny.parseDestiny(ctx, parameters)
@cog_ext.cog_slash(**params["star_wars_crit"])
async def star_wars_crit(self, ctx, severity: int = 0):
"""Roll for critical injuries."""
await self.bot.star_wars.roll.critRoll(ctx, severity)
@cog_ext.cog_slash(**params["star_wars_character"])
async def star_wars_character(self, ctx, parameters=""):
"""Access and change Star Wars character sheet data."""
await self.bot.star_wars.character.parseChar(ctx, parameters)
def setup(bot):
"""Add the cog to the bot."""
bot.add_cog(StarWarsCog(bot))