✨ Even more converting to slash commands
This commit is contained in:
141
cogs/GamesCog.py
141
cogs/GamesCog.py
@ -1,9 +1,19 @@
|
||||
import discord, asyncio
|
||||
import discord, asyncio, json
|
||||
from discord.ext import commands
|
||||
from discord_slash import cog_ext
|
||||
from discord_slash import SlashCommandOptionType as scot
|
||||
|
||||
from funcs import logThis
|
||||
from utils import Options
|
||||
|
||||
with open("resources/slashParameters.json", "r") as f:
|
||||
params = json.load(f)
|
||||
|
||||
options = Options()
|
||||
|
||||
if options.testing:
|
||||
for p in params:
|
||||
params[p]["guild_ids"] = options.guildIds
|
||||
|
||||
class GamesCog(commands.Cog):
|
||||
|
||||
@ -12,19 +22,19 @@ class GamesCog(commands.Cog):
|
||||
self.bot = bot
|
||||
|
||||
# Checks user balance
|
||||
@commands.command(aliases = ["b"])
|
||||
@cog_ext.cog_slash(**params["balance"])
|
||||
async def balance(self, ctx):
|
||||
response = self.bot.money.checkBalance("#"+str(ctx.message.author.id))
|
||||
response = self.bot.money.checkBalance("#"+str(ctx.author.id))
|
||||
if response == 1:
|
||||
new_message = ctx.message.author.display_name + " has " + str(response) + " GwendoBuck"
|
||||
new_message = ctx.author.display_name + " has " + str(response) + " GwendoBuck"
|
||||
else:
|
||||
new_message = ctx.message.author.display_name + " has " + str(response) + " GwendoBucks"
|
||||
new_message = ctx.author.display_name + " has " + str(response) + " GwendoBucks"
|
||||
await ctx.send(new_message)
|
||||
|
||||
# Gives another user an amount of GwendoBucks
|
||||
@commands.command()
|
||||
async def give(self, ctx, *, content):
|
||||
commands = content.split(" ")
|
||||
@cog_ext.cog_slash(**params["give"])
|
||||
async def give(self, ctx, parameters):
|
||||
commands = parameters.split(" ")
|
||||
amount = int(commands[-1])
|
||||
username = " ".join(commands[:-1])
|
||||
if self.bot.funcs.getID(username) == None:
|
||||
@ -33,13 +43,13 @@ class GamesCog(commands.Cog):
|
||||
username = member.display_name
|
||||
userID = "#" + str(member.id)
|
||||
self.bot.database["users"].insert_one({"_id":userID,"user name":username,"money":0})
|
||||
response = self.bot.money.giveMoney("#"+str(ctx.message.author.id),username,amount)
|
||||
response = self.bot.money.giveMoney("#"+str(ctx.author.id),username,amount)
|
||||
await ctx.send(response)
|
||||
|
||||
# Invest GwendoBucks in the stock market
|
||||
@commands.command(aliases=["i"])
|
||||
async def invest(self, ctx, *, content = "check"):
|
||||
response = self.bot.invest.parseInvest(content,"#"+str(ctx.message.author.id))
|
||||
@cog_ext.cog_slash(**params["invest"])
|
||||
async def invest(self, ctx, parameters = "check"):
|
||||
response = self.bot.invest.parseInvest(parameters,"#"+str(ctx.author.id))
|
||||
if response.startswith("**"):
|
||||
responses = response.split("\n")
|
||||
em = discord.Embed(title=responses[0],description="\n".join(responses[1:]),colour=0x00FF00)
|
||||
@ -48,57 +58,102 @@ class GamesCog(commands.Cog):
|
||||
await ctx.send(response)
|
||||
|
||||
# Runs a game of trivia
|
||||
@commands.command()
|
||||
async def trivia(self, ctx, *, content = ""):
|
||||
if content == "":
|
||||
question, answers, correctAnswer = self.bot.trivia.triviaStart(str(ctx.message.channel.id))
|
||||
if answers != "":
|
||||
@cog_ext.cog_slash(**params["trivia"])
|
||||
async def trivia(self, ctx, answer = ""):
|
||||
if answer == "":
|
||||
question, options, correctAnswer = self.bot.trivia.triviaStart(str(ctx.channel_id))
|
||||
if options != "":
|
||||
results = "**"+question+"**\n"
|
||||
for x, answer in enumerate(answers):
|
||||
results += chr(x+97) + ") "+answer+"\n"
|
||||
for x, option in enumerate(options):
|
||||
results += chr(x+97) + ") "+option+"\n"
|
||||
|
||||
await ctx.send(results)
|
||||
|
||||
await asyncio.sleep(60)
|
||||
|
||||
self.bot.trivia.triviaCountPoints(str(ctx.message.channel.id))
|
||||
self.bot.trivia.triviaCountPoints(str(ctx.channel_id))
|
||||
|
||||
self.bot.funcs.deleteGame("trivia questions",str(ctx.message.channel.id))
|
||||
self.bot.funcs.deleteGame("trivia questions",str(ctx.channel_id))
|
||||
|
||||
logThis("Time's up for the trivia question",str(ctx.message.channel.id))
|
||||
await ctx.send("Time's up The answer was \""+chr(correctAnswer)+") "+answers[correctAnswer-97]+"\". Anyone who answered that has gotten 1 GwendoBuck")
|
||||
logThis("Time's up for the trivia question",str(ctx.channel_id))
|
||||
await ctx.send("Time's up The answer was \""+chr(correctAnswer)+") "+options[correctAnswer-97]+"\". Anyone who answered that has gotten 1 GwendoBuck")
|
||||
else:
|
||||
await ctx.send(question)
|
||||
await ctx.send(question, hidden=True)
|
||||
|
||||
elif content in ["a","b","c","d"]:
|
||||
response = self.bot.trivia.triviaAnswer("#"+str(ctx.message.author.id),str(ctx.message.channel.id),content)
|
||||
elif answer in ["a","b","c","d"]:
|
||||
response = self.bot.trivia.triviaAnswer("#"+str(ctx.author.id),str(ctx.channel_id),answer)
|
||||
if response.startswith("Locked in "):
|
||||
await ctx.message.add_reaction("👍")
|
||||
await ctx.send(f"{ctx.author.display_name} answered {answer}")
|
||||
else:
|
||||
await ctx.send(response)
|
||||
else:
|
||||
logThis("I didn't understand that (error code 1101)",str(ctx.message.channel.id))
|
||||
logThis("I didn't understand that (error code 1101)",str(ctx.channel_id))
|
||||
await ctx.send("I didn't understand that (error code 1101)")
|
||||
|
||||
# Runs a game of blackjack
|
||||
@commands.command(aliases = ["bj"])
|
||||
async def blackjack(self, ctx, *, content = ""):
|
||||
await self.bot.blackjack.parseBlackjack(content,ctx)
|
||||
@cog_ext.cog_slash(**params["blackjack"])
|
||||
async def blackjack(self, ctx, parameters = ""):
|
||||
await self.bot.blackjack.parseBlackjack(parameters, ctx)
|
||||
|
||||
# Runs a game of Connect four
|
||||
@commands.command(aliases = ["fiar","connect4","connectfour","4iar","4inarow"])
|
||||
async def fourinarow(self, ctx, *, content = ""):
|
||||
await self.bot.gameLoops.fiar(ctx.message.channel,content,"#"+str(ctx.message.author.id))
|
||||
# Start a game of connect four against a user
|
||||
@cog_ext.cog_subcommand(**params["connectFourStartUser"])
|
||||
async def connectFourStartUser(self, ctx, user):
|
||||
await self.bot.gameLoops.connectFour(ctx, "start "+user.display_name)
|
||||
|
||||
# Runs a game of Hangman
|
||||
@commands.command(aliases = ["hm"])
|
||||
async def hangman(self, ctx, *, content = "start"):
|
||||
await self.bot.gameLoops.runHangman(ctx.message.channel,"#"+str(ctx.message.author.id),content)
|
||||
# Start a game of connect four against gwendolyn
|
||||
@cog_ext.cog_subcommand(**params["connectFourStartGwendolyn"])
|
||||
async def connectFourStartGwendolyn(self, ctx, difficulty = 3):
|
||||
await self.bot.gameLoops.connectFour(ctx, "start "+str(difficulty))
|
||||
|
||||
# Runs a game of Hex
|
||||
@commands.command(name="hex")
|
||||
async def hexCommand(self, ctx, *, content = ""):
|
||||
await self.bot.gameLoops.runHex(ctx.message.channel,content,"#"+str(ctx.message.author.id))
|
||||
# Stop the current game of connect four
|
||||
@cog_ext.cog_subcommand(**params["connectFourStop"])
|
||||
async def connectFourStop(self, ctx):
|
||||
await self.bot.gameLoops.connectFour(ctx, "stop")
|
||||
|
||||
# Place a piece in the current game of connect four
|
||||
@cog_ext.cog_subcommand(**params["connectFourPlace"])
|
||||
async def connectFourPlace(self, ctx, column):
|
||||
await self.bot.gameLoops.connectFour(ctx, "place "+str(column))
|
||||
|
||||
# Starts a game of Hangman
|
||||
@cog_ext.cog_subcommand(**params["hangmanStart"])
|
||||
async def hangmanStart(self, ctx):
|
||||
await self.bot.gameLoops.runHangman(ctx.channel,"#"+str(ctx.author.id),"start", ctx)
|
||||
|
||||
# Stops a game of Hangman
|
||||
@cog_ext.cog_subcommand(**params["hangmanStop"])
|
||||
async def hangmanStop(self, ctx):
|
||||
await self.bot.gameLoops.runHangman(ctx.channel,"#"+str(ctx.author.id),"stop", ctx)
|
||||
|
||||
# Start a game of Hex against another user
|
||||
@cog_ext.cog_subcommand(**params["hexStartUser"])
|
||||
async def hexStartUser(self, ctx, user):
|
||||
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 self.bot.gameLoops.runHex(ctx, "start "+str(difficulty), "#"+str(ctx.author.id))
|
||||
|
||||
# Undo your last hex move
|
||||
@cog_ext.cog_subcommand(**params["hexUndo"])
|
||||
async def hexUndo(self, ctx):
|
||||
await self.bot.gameLoops.runHex(ctx, "undo", "#"+str(ctx.author.id))
|
||||
|
||||
# Perform a hex swap
|
||||
@cog_ext.cog_subcommand(**params["hexSwap"])
|
||||
async def hexSwap(self, ctx):
|
||||
await self.bot.gameLoops.runHex(ctx, "swap", "#"+str(ctx.author.id))
|
||||
|
||||
# Surrender the hex game
|
||||
@cog_ext.cog_subcommand(**params["hexSurrender"])
|
||||
async def hexSurrender(self, ctx):
|
||||
await self.bot.gameLoops.runHex(ctx, "surrender", "#"+str(ctx.author.id))
|
||||
|
||||
# Place a piece in the hex game
|
||||
@cog_ext.cog_subcommand(**params["hexPlace"])
|
||||
async def hexPlace(self, ctx, coordinates):
|
||||
await self.bot.gameLoops.runHex(ctx, "place "+coordinates, "#"+str(ctx.author.id))
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(GamesCog(bot))
|
Reference in New Issue
Block a user