diff --git a/bot/cogs/karma.py b/bot/cogs/karma.py index 37adecc..fc98e19 100644 --- a/bot/cogs/karma.py +++ b/bot/cogs/karma.py @@ -1,8 +1,6 @@ import logging import os -import shutil from datetime import datetime -from pathlib import Path import discord import plotly.graph_objects as go @@ -11,6 +9,7 @@ from core.bot import Substiify from discord import app_commands from discord.ext import commands +from utils import util logger = logging.getLogger(__name__) @@ -81,7 +80,7 @@ async def list_votes(self, ctx: commands.Context): @app_commands.describe( channel="The channel to enable votes in" ) - async def start(self, ctx: commands.Context, channel: discord.TextChannel = None): + async def start(self, ctx: commands.Context, channel: discord.abc.GuildChannel = None): """ Enables votes in the current or specified channel. Requires Manage Channels permission. After enabling votes, the bot will add the upvote and downvote reactions to every message in the channel. @@ -98,7 +97,7 @@ async def start(self, ctx: commands.Context, channel: discord.TextChannel = None if not votes_enabled: stmt = '''INSERT INTO discord_channel (discord_channel_id, channel_name, discord_server_id, parent_discord_channel_id, upvote) VALUES ($1, $2, $3, $4, $5) ON CONFLICT (discord_channel_id) DO UPDATE SET upvote = $5''' - await self.bot.db.execute(stmt, channel.id, channel.name, channel.guild.id, channel.category_id, True) + await self.bot.db.execute(stmt, channel.id, channel.name, channel.guild.id, None, True) else: embed = discord.Embed( description=f'Votes are **already active** in {ctx.channel.mention}!', @@ -126,7 +125,7 @@ async def stop(self, ctx: commands.Context, channel: discord.TextChannel = None) channel = channel or ctx.channel stmt = '''INSERT INTO discord_channel (discord_channel_id, channel_name, discord_server_id, parent_discord_channel_id, upvote) VALUES ($1, $2, $3, $4, $5) ON CONFLICT (discord_channel_id) DO UPDATE SET upvote = $5''' - await self.bot.db.execute(stmt, channel.id, channel.name, channel.guild.id, channel.category_id, False) + await self.bot.db.execute(stmt, channel.id, channel.name, channel.guild.id, None, False) if channel.id in self.vote_channels: self.vote_channels.remove(channel.id) @@ -555,13 +554,16 @@ async def kasino_open(self, ctx: commands.Context, question: str, op_a: str, op_ """ Opens a karma kasino which allows people to bet on a question with two options. Check "karma" and "votes" commands for more info on karma. """ - if not ctx.interaction: - await ctx.message.delete() async with ctx.typing(): - kasino_id = await self.add_kasino(ctx, question, op_a, op_b) + to_embed = discord.Embed(description="Opening kasino, hold on tight...") + kasino_msg = await ctx.send(embed=to_embed) + stmt_kasino = '''INSERT INTO kasino (discord_server_id, discord_channel_id, discord_message_id, question, option1, option2) + VALUES ($1, $2, $3, $4, $5, $6) RETURNING id''' + kasino_id = await self.bot.db.fetchval(stmt_kasino, ctx.guild.id, ctx.channel.id, kasino_msg.id, question, op_a, op_b) # TODO: Add kasino backup - # self.create_kasino_backup(kasino.id) - await self.update_kasino_msg(ctx, kasino_id) + await _update_kasino_msg(ctx.bot, kasino_id) + if not ctx.interaction: + await ctx.message.delete() @kasino.command(name='close', usage="close ") @commands.check_any(commands.has_permissions(manage_channels=True), commands.is_owner()) @@ -574,7 +576,7 @@ async def kasino_close(self, ctx: commands.Context, kasino_id: int, winner: int) kasino = await self.bot.db.fetchrow('SELECT * FROM kasino WHERE id = $1', kasino_id) if kasino is None: - return await ctx.author.send(f'Kasino with ID {kasino_id} is not open.') + return await ctx.reply(f'Kasino with ID {kasino_id} is not open.') if kasino['discord_server_id'] != ctx.guild.id: return await ctx.send(f'Kasino with ID {kasino_id} is not in this server.', delete_after=120) @@ -594,98 +596,12 @@ async def kasino_close(self, ctx: commands.Context, kasino_id: int, winner: int) @kasino_close.error async def kasino_close_error(self, ctx: commands.Context, error): if isinstance(error, commands.errors.MissingRequiredArgument): - msg = f'You didn\'t provide a required argument! Correct usage is `{ctx.prefix}kasino close `' - await ctx.send(msg, delete_after=20) + msg = f'You didn\'t provide a required argument!\nCorrect usage is `{ctx.prefix}kasino close `' + msg += '\nUse option `3` to close and abort the kasino (no winner).' + embed = discord.Embed(description=msg, color=0xf66045) + await ctx.send(embed=embed, delete_after=30) elif isinstance(error, commands.errors.BadArgument): - await ctx.send('Bad argument.', delete_after=20) - if not ctx.interaction: - await ctx.message.delete() - - @kasino.command(name='lock', usage="lock ") - @commands.check_any(commands.has_permissions(manage_channels=True), commands.is_owner()) - @app_commands.describe( - kasino_id="The ID of the kasino you want to lock. The ID should be visible in the kasino message." - ) - async def kasino_lock(self, ctx: commands.Context, kasino_id: int): - """ Locks a karma kasino. Users can no longer bet on this kasino.""" - kasino = await self.bot.db.fetchrow('SELECT locked FROM kasino WHERE id = $1', kasino_id) - if kasino is None: - return await ctx.author.send(f'Kasino with ID `{kasino_id}` does not exist.') - if kasino['locked']: - return await ctx.author.send(f'Kasino with ID `{kasino_id}` is already locked.') - - await self.bot.db.execute('UPDATE kasino SET locked = True WHERE id = $1', kasino_id) - await self.update_kasino_msg(ctx, kasino_id) - if not ctx.interaction: - await ctx.message.delete() - - @kasino.command(name='bet', usage="bet