Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DorianAarno committed Feb 6, 2023
1 parent 4a4e9db commit c1846d8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
48 changes: 42 additions & 6 deletions cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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")
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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))
17 changes: 17 additions & 0 deletions cogs/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit c1846d8

Please sign in to comment.