Skip to content

Commit

Permalink
Fix shuffle after ban
Browse files Browse the repository at this point in the history
  • Loading branch information
yiays committed Oct 29, 2024
1 parent 69fdf09 commit 1b5349f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
7 changes: 4 additions & 3 deletions babel/confessionbot_en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,15 @@ report_success = Your report has been sent successfully! For a status on your re
new_report = The following confession from {server} has been reported by {user} for the reason;
> {reason}
; ban
bansuccess = {user} has been blocked.
to unblock them, set the unblock parameter to true or {p:shuffle} ids.
bansuccess = Anon-{user} has been blocked.
To unblock them, use {p:block}` anonid:{user} unblock:true` or {p:shuffle} ids.
unbansuccess = {user} has been unblocked.
banlist = Here's a list of currently blocked anon-ids;
emptybanlist = There's nobody currently blocked on this server!
; shuffle
; this 'yes' must remain a 'yes' in translation.
shufflebanresetwarning = Shuffling will reset all active bans. Reply with 'yes' to continue.
shufflebanresetwarning = Shuffling will reset all active bans. Do you want to continue?
shufflebanresetconfirm = Continue
shufflesuccess = All anon-ids on this server have been shuffled!
; vetting
vetmessagecta = A pending message for {channel}.
Expand Down
9 changes: 8 additions & 1 deletion extensions/confessions_moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ async def report_button(self, inter:discord.Interaction, _:discord.Button):
)
await inter.delete_original_response()

async def on_timeout(self):
try:
await self.origin.delete_original_response()
except discord.HTTPException:
pass # Message was probably dismissed, don't worry about it

# Modals

class ReportModal(discord.ui.Modal):
Expand Down Expand Up @@ -351,8 +357,9 @@ async def block(
if not banlist_raw:
await inter.response.send_message(self.babel(inter, 'emptybanlist'))
return
printedlist = '\n```'+'\n'.join(banlist)+'```'
printedlist = '\n```\n' + ('\n'.join(banlist)) + '```'
await inter.response.send_message(self.babel(inter, 'banlist') + printedlist)
return

anonid = anonid.lower()
try:
Expand Down
48 changes: 35 additions & 13 deletions extensions/confessions_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,30 @@ async def on_timeout(self):
except discord.HTTPException:
pass

class BanResetView(discord.ui.View):
""" Warns user about the ban reset before shuffle is performed """
def __init__(self, parent:ConfessionsSetup, origin:discord.Interaction):
super().__init__(timeout=300)

self.parent = parent
self.origin = origin

self.continue_button.label = parent.babel(origin, 'shufflebanresetconfirm')

@discord.ui.button(style=discord.ButtonStyle.green, emoji='➡️', custom_id='shufflebanreset_yes')
async def continue_button(self, inter:discord.Interaction, _:discord.Button):
""" On click of continue button """
self.parent.config.pop(str(inter.guild.id)+'_banned')
self.parent.perform_shuffle(inter.guild_id)
await inter.response.send_message(self.parent.babel(inter, 'shufflesuccess'))
await self.origin.delete_original_response()

async def on_timeout(self):
try:
await self.origin.delete_original_response()
except discord.HTTPException:
pass # Message was probably dismissed, don't worry about it

# Events

@commands.Cog.listener('on_ready')
Expand Down Expand Up @@ -361,23 +385,21 @@ async def shuffle(self, inter:discord.Interaction):
Change all anon-ids on a server
"""
if str(inter.guild.id)+'_banned' in self.config:
await inter.response.send_message(self.babel(inter, 'shufflebanresetwarning'))
await inter.response.send_message(
self.babel(inter, 'shufflebanresetwarning'),
view=self.BanResetView(self, inter),
ephemeral=True
)
return

def check(m:discord.Message):
return m.channel == inter.channel and m.author == inter.user and m.content.lower() == 'yes'
try:
await self.bot.wait_for('message', check=check, timeout=30)
except asyncio.TimeoutError:
await inter.response.send_message(self.babel(inter, 'timeouterror'))
else:
self.config.pop(str(inter.guild.id)+'_banned')
self.perform_shuffle(inter.guild_id)
await inter.response.send_message(self.babel(inter, 'shufflesuccess'))

shuffle = int(self.config.get(f'{inter.guild.id}_shuffle', fallback=0))
self.bot.config.set(self.SCOPE, str(inter.guild.id)+'_shuffle', str(shuffle + 1))
def perform_shuffle(self, guild_id:int):
shuffle = int(self.config.get(str(guild_id) + '_shuffle', fallback=0))
self.bot.config.set(self.SCOPE, str(guild_id) + '_shuffle', str(shuffle + 1))
self.bot.config.save()

await inter.response.send_message(self.babel(inter, 'shufflesuccess'))


async def setup(bot:MerelyBot):
""" Bind this cog to the bot """
Expand Down

0 comments on commit 1b5349f

Please sign in to comment.