✨ More converting
This commit is contained in:
36
cogs/EventCog.py
Normal file
36
cogs/EventCog.py
Normal file
@ -0,0 +1,36 @@
|
||||
from discord.ext import commands
|
||||
|
||||
class EventCog(commands.cog):
|
||||
def __init__(bot):
|
||||
self.bot = bot
|
||||
|
||||
# Sets the game and logs when the bot logs in
|
||||
@client.event
|
||||
async def on_ready():
|
||||
logThis("Logged in as "+client.user.name+", "+str(client.user.id))
|
||||
game = discord.Game("Some weeb shit")
|
||||
await client.change_presence(activity=game)
|
||||
|
||||
# Logs when user sends a command
|
||||
@client.event
|
||||
async def on_slash_command(ctx):
|
||||
logThis(f"{ctx.author.display_name} ran {ctx.name}")
|
||||
|
||||
# Logs if a command experiences an error
|
||||
@client.event
|
||||
async def on_slash_command_error(ctx, error):
|
||||
if isinstance(error, commands.CommandNotFound):
|
||||
await ctx.send("That's not a command (error code 001)")
|
||||
elif isinstance(error,commands.errors.MissingRequiredArgument):
|
||||
logThis(f"{error}",str(ctx.channel_id))
|
||||
await ctx.send("Missing command parameters (error code 002). Try using `!help [command]` to find out how to use the command.")
|
||||
else:
|
||||
exception = traceback.format_exception(type(error), error, error.__traceback__)
|
||||
stopAt = "\nThe above exception was the direct cause of the following exception:\n\n"
|
||||
if stopAt in exception:
|
||||
index = exception.index(stopAt)
|
||||
exception = exception[:index]
|
||||
|
||||
exceptionString = "".join(exception)
|
||||
logThis([f"exception in {ctx.name} command", f"{exceptionString}"],str(ctx.channel_id), 40)
|
||||
await ctx.send("Something went wrong (error code 000)")
|
@ -24,6 +24,7 @@ class GamesCog(commands.Cog):
|
||||
# Checks user balance
|
||||
@cog_ext.cog_slash(**params["balance"])
|
||||
async def balance(self, ctx):
|
||||
await ctx.defer()
|
||||
response = self.bot.money.checkBalance("#"+str(ctx.author.id))
|
||||
if response == 1:
|
||||
new_message = ctx.author.display_name + " has " + str(response) + " GwendoBuck"
|
||||
@ -34,6 +35,7 @@ class GamesCog(commands.Cog):
|
||||
# Gives another user an amount of GwendoBucks
|
||||
@cog_ext.cog_slash(**params["give"])
|
||||
async def give(self, ctx, parameters):
|
||||
await ctx.defer()
|
||||
commands = parameters.split(" ")
|
||||
amount = int(commands[-1])
|
||||
username = " ".join(commands[:-1])
|
||||
@ -49,6 +51,7 @@ class GamesCog(commands.Cog):
|
||||
# Invest GwendoBucks in the stock market
|
||||
@cog_ext.cog_slash(**params["invest"])
|
||||
async def invest(self, ctx, parameters = "check"):
|
||||
await ctx.defer()
|
||||
response = self.bot.invest.parseInvest(parameters,"#"+str(ctx.author.id))
|
||||
if response.startswith("**"):
|
||||
responses = response.split("\n")
|
||||
@ -60,6 +63,7 @@ class GamesCog(commands.Cog):
|
||||
# Runs a game of trivia
|
||||
@cog_ext.cog_slash(**params["trivia"])
|
||||
async def trivia(self, ctx, answer = ""):
|
||||
await ctx.defer()
|
||||
if answer == "":
|
||||
question, options, correctAnswer = self.bot.trivia.triviaStart(str(ctx.channel_id))
|
||||
if options != "":
|
||||
@ -93,16 +97,19 @@ class GamesCog(commands.Cog):
|
||||
# Runs a game of blackjack
|
||||
@cog_ext.cog_slash(**params["blackjack"])
|
||||
async def blackjack(self, ctx, parameters = ""):
|
||||
await ctx.defer()
|
||||
await self.bot.blackjack.parseBlackjack(parameters, ctx)
|
||||
|
||||
# Start a game of connect four against a user
|
||||
@cog_ext.cog_subcommand(**params["connectFourStartUser"])
|
||||
async def connectFourStartUser(self, ctx, user):
|
||||
await ctx.defer()
|
||||
await self.bot.gameLoops.connectFour(ctx, "start "+user.display_name)
|
||||
|
||||
# Start a game of connect four against gwendolyn
|
||||
@cog_ext.cog_subcommand(**params["connectFourStartGwendolyn"])
|
||||
async def connectFourStartGwendolyn(self, ctx, difficulty = 3):
|
||||
await ctx.defer()
|
||||
await self.bot.gameLoops.connectFour(ctx, "start "+str(difficulty))
|
||||
|
||||
# Stop the current game of connect four
|
||||
@ -118,6 +125,7 @@ class GamesCog(commands.Cog):
|
||||
# Starts a game of Hangman
|
||||
@cog_ext.cog_subcommand(**params["hangmanStart"])
|
||||
async def hangmanStart(self, ctx):
|
||||
await ctx.defer()
|
||||
await self.bot.gameLoops.runHangman(ctx.channel,"#"+str(ctx.author.id),"start", ctx)
|
||||
|
||||
# Stops a game of Hangman
|
||||
@ -128,11 +136,13 @@ class GamesCog(commands.Cog):
|
||||
# Start a game of Hex against another user
|
||||
@cog_ext.cog_subcommand(**params["hexStartUser"])
|
||||
async def hexStartUser(self, ctx, user):
|
||||
await ctx.defer()
|
||||
await self.bot.gameLoops.runHex(ctx, "start "+user.display_name, "#"+str(ctx.author.id))
|
||||
|
||||
# Start a game of Hex against Gwendolyn
|
||||
@cog_ext.cog_subcommand(**params["hexStartGwendolyn"])
|
||||
async def hexStartGwendolyn(self, ctx, difficulty = 2):
|
||||
await ctx.defer()
|
||||
await self.bot.gameLoops.runHex(ctx, "start "+str(difficulty), "#"+str(ctx.author.id))
|
||||
|
||||
# Undo your last hex move
|
||||
|
Reference in New Issue
Block a user