diff --git a/cogs/admin.py b/cogs/admin.py index 50d4ad7..39b5078 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -5,6 +5,7 @@ from cogs.match import QueueButtons from cogs.win import Win from core.embeds import error, success +from core.buttons import ConfirmationButtons class Admin(Cog): @@ -368,11 +369,20 @@ async def leaderboard(self, ctx): data = await self.bot.fetch(f"SELECT * FROM points WHERE guild_id = {ctx.guild.id} ") if not data: return await ctx.send(embed=error("There are no records to be deleted")) - - await self.bot.execute(f"UPDATE mvp_points SET votes = 0 WHERE guild_id = {ctx.guild.id}") - await self.bot.execute(f"UPDATE points SET wins = 0, losses = 0 WHERE guild_id = {ctx.guild.id}") - await self.bot.execute(f"UPDATE mmr_rating SET counter = 0, mu = 25.0, sigma = 8.33333333333333 WHERE guild_id = {ctx.guild.id}") - await ctx.send(embed=success("Successfully reset all wins, mmr and mvp votes")) + + view = ConfirmationButtons(ctx.author.id) + await ctx.send( + "This will reset all member's wins, losses, MMR and MVP votes back to 0. Are you sure?", + view=view + ) + await view.wait() + if view.value: + await self.bot.execute(f"UPDATE mvp_points SET votes = 0 WHERE guild_id = {ctx.guild.id}") + await self.bot.execute(f"UPDATE points SET wins = 0, losses = 0 WHERE guild_id = {ctx.guild.id}") + await self.bot.execute(f"UPDATE mmr_rating SET counter = 0, mu = 25.0, sigma = 8.33333333333333 WHERE guild_id = {ctx.guild.id}") + await ctx.send(embed=success("Successfully reset all wins, mmr and mvp votes")) + else: + await ctx.send(emebd=success("Process aborted.")) @reset.command() async def queue(self, ctx, game_id): @@ -391,6 +401,26 @@ async def queue(self, ctx, game_id): else: await ctx.send(embed=error(f"Game **{game_id}** was not found.")) + @reset.command() + async def user(self, ctx, member: Member): + data = await self.bot.fetch(f"SELECT * FROM points WHERE guild_id = {ctx.guild.id} and user_id = {member.id}") + if not data: + return await ctx.send(embed=error("There are no records to be deleted")) + + view = ConfirmationButtons(ctx.author.id) + await ctx.send( + f"This will reset all {member.display_name}'s wins, losses, MMR and MVP votes back to 0. Are you sure?", + view=view + ) + await view.wait() + if view.value: + await self.bot.execute(f"UPDATE mvp_points SET votes = 0 WHERE guild_id = {ctx.guild.id} and user_id = {member.id}") + await self.bot.execute(f"UPDATE points SET wins = 0, losses = 0 WHERE guild_id = {ctx.guild.id} and user_id = {member.id}") + await self.bot.execute(f"UPDATE mmr_rating SET counter = 0, mu = 25.0, sigma = 8.33333333333333 WHERE guild_id = {ctx.guild.id} and user_id = {member.id}") + await ctx.send(embed=success(f"Successfully reset all wins, mmr and mvp votes of {member.display_name}")) + else: + await ctx.send(emebd=success("Process aborted.")) + # SLASH COMMANDS @slash_command(name="admin") @@ -469,7 +499,7 @@ async def disable( await ctx.send(embed=success(f"Command disabled for {role.mention} successfully.")) @admin_slash.sub_command(name="user_dequeue") - async def user_slash(self, ctx, member: Member): + async def user_dequeue_slash(self, ctx, member: Member): """ Remove a user from all queues. Rejoin the queue to refresh the Embed. """ @@ -595,6 +625,12 @@ async def queue_slash(self, ctx, game_id: str): """ await self.queue(ctx, game_id) + @reset_slash.sub_command(name="user") + async def user_slash(self, ctx, member: Member): + """ + Reset a member's Wins, Losses, MMR and MVP votes back to 0. + """ + await self.user(ctx, member) def setup(bot): bot.add_cog(Admin(bot)) diff --git a/cogs/events.py b/cogs/events.py index 0076ea2..837e524 100644 --- a/cogs/events.py +++ b/cogs/events.py @@ -11,6 +11,23 @@ class Events(Cog): def __init__(self, bot): self.bot = bot + @Cog.listener() + async def on_guild_channel_delete(self, channel): + deletions = [] + setchannel = await self.bot.fetch(f"SELECT * FROM queuechannels WHERE channel_id = {channel.id}") + if setchannel: + deletions.append("queuechannels") + log_channels = await self.bot.fetch(f"SELECT * FROM winner_log_channel WHERE channel_id = {channel.id}") + if log_channels: + deletions.append("winner_log_channel") + top_ten = await self.bot.fetch(f"SELECT * FROM persistent_lb WHERE channel_id = {channel.id}") + if top_ten: + deletions.append("persistent_lb") + + for deletion in deletions: + await self.bot.execute(f"DELETE FROM {deletion} WHERE channel_id = {channel.id}") + + @Cog.listener() async def on_message(self, msg): data = await self.bot.fetch("SELECT * FROM queuechannels")