(tickets): Small bugfixes.

Only allow one interactive ticket display per user per channel.
Fix guild filtering for ticket display and ticket pardon.
This commit is contained in:
2021-10-01 08:21:51 +03:00
parent 6ef6c757fb
commit 421c13fb72

View File

@@ -107,7 +107,7 @@ async def cmd_tickets(ctx, flags):
filter_active = flags['active'] filter_active = flags['active']
# Build the filter arguments # Build the filter arguments
filters = {} filters = {'guildid': ctx.guild.id}
if filter_userid: if filter_userid:
filters['targetid'] = filter_userid filters['targetid'] = filter_userid
if filter_type: if filter_type:
@@ -248,11 +248,15 @@ async def cmd_tickets(ctx, flags):
# Run output with cancellation and listener # Run output with cancellation and listener
out_msg = await ctx.pager(embeds, add_cancel=True) out_msg = await ctx.pager(embeds, add_cancel=True)
display_task = asyncio.create_task(_ticket_display(ctx, ticket_map)) old_task = _displays.pop((ctx.ch.id, ctx.author.id), None)
if old_task:
old_task.cancel()
_displays[(ctx.ch.id, ctx.author.id)] = display_task = asyncio.create_task(_ticket_display(ctx, ticket_map))
ctx.tasks.append(display_task) ctx.tasks.append(display_task)
await ctx.cancellable(out_msg, add_reaction=False) await ctx.cancellable(out_msg, add_reaction=False)
_displays = {} # (channelid, userid) -> Task
async def _ticket_display(ctx, ticket_map): async def _ticket_display(ctx, ticket_map):
""" """
Display tickets when the ticket number is entered. Display tickets when the ticket number is entered.
@@ -268,7 +272,8 @@ async def _ticket_display(ctx, ticket_map):
check=lambda msg: (msg.author == ctx.author check=lambda msg: (msg.author == ctx.author
and msg.channel == ctx.ch and msg.channel == ctx.ch
and msg.content.isdigit() and msg.content.isdigit()
and int(msg.content) in ticket_map) and int(msg.content) in ticket_map),
timeout=60
) )
except asyncio.TimeoutError: except asyncio.TimeoutError:
return return
@@ -337,13 +342,14 @@ async def cmd_pardon(ctx, flags):
# Parse provided tickets or filters # Parse provided tickets or filters
targetid = None targetid = None
ticketids = [] ticketids = []
args = {'guildid': ctx.guild.id}
if ',' in ctx.args: if ',' in ctx.args:
# Assume provided numbers are ticketids. # Assume provided numbers are ticketids.
items = [item.strip() for item in ctx.args.split(',')] items = [item.strip() for item in ctx.args.split(',')]
if not all(item.isdigit() for item in items): if not all(item.isdigit() for item in items):
return await ctx.error_reply(usage) return await ctx.error_reply(usage)
ticketids = [int(item) for item in items] ticketids = [int(item) for item in items]
args = {'guild_ticketid': ticketids} args['guild_ticketid'] = ticketids
else: else:
# Guess whether the provided numbers were ticketids or not # Guess whether the provided numbers were ticketids or not
idstr = ctx.args.strip('<@!&> ') idstr = ctx.args.strip('<@!&> ')
@@ -354,7 +360,7 @@ async def cmd_pardon(ctx, flags):
if maybe_id > 4194304: # Testing whether it is greater than the minimum snowflake id if maybe_id > 4194304: # Testing whether it is greater than the minimum snowflake id
# Assume userid # Assume userid
targetid = maybe_id targetid = maybe_id
args = {'targetid': maybe_id} args['targetid'] = maybe_id
# Add the type filter if provided # Add the type filter if provided
if flags['type']: if flags['type']:
@@ -367,7 +373,7 @@ async def cmd_pardon(ctx, flags):
else: else:
# Assume guild ticketid # Assume guild ticketid
ticketids = [maybe_id] ticketids = [maybe_id]
args = {'guild_ticketid': maybe_id} args['guild_ticketid'] = maybe_id
# Fetch the matching tickets # Fetch the matching tickets
tickets = Ticket.fetch_tickets(**args) tickets = Ticket.fetch_tickets(**args)