1- import aiohttp , discord , logging , utils
1+ import discord , json , logging , utils
22
33from discord .ext import commands , tasks
44from env import env
@@ -20,7 +20,9 @@ async def on_ready(self):
2020 @tasks .loop (seconds = 60.0 )
2121 async def pull_answers (self ):
2222 answers = await self .api .fetch_question_answers (env .TITO_QUESTION_SLUG )
23+ logging .debug (f"Received { len (answers )} answers in latest API response." )
2324 for a in answers :
25+ logging .debug (f"Stored answer for { a .response } " )
2426 self .attendees [a .response ] = a .ticket_id
2527
2628 # TODO: allow to be used as user command
@@ -63,16 +65,35 @@ async def ticketof(self, ctx: discord.ApplicationContext, user: discord.Member):
6365
6466 await ctx .respond (f"ℹ️ I found a ticket for `{ user .name } `. Their ticket ID is `{ ticket } `." , ephemeral = True )
6567
68+ @commands .slash_command (description = "A debug command to get the internal cache." )
69+ @commands .guild_only ()
70+ async def tickets (self , ctx : discord .ApplicationContext ):
71+ # Normal users can't do this
72+ if not utils .is_volunteer (ctx .author ):
73+ logging .warning (f"User { ctx .author .name } attempted to user a forbidden command." )
74+ return await ctx .respond ("✋ Only organisers can do this." , ephemeral = True )
75+
76+ tickets = json .dumps (
77+ self .attendees ,
78+ sort_keys = True ,
79+ indent = 4 ,
80+ separators = (',' , ': ' )
81+ )
82+ await ctx .respond (f"```json\n { tickets } \n ```" , ephemeral = True )
83+
6684 @commands .Cog .listener ()
6785 async def on_member_join (self , member : discord .Member ):
6886 if member .guild .id != env .DISCORD_GUILD_ID :
87+ logging .debug (f"Skipping automatic verification for { member .name } because they joined a different guild." )
6988 return
7089
7190 if member .bot :
91+ logging .debug (f"Skipping automatic verification for { member .name } because they are a bot." )
7292 return
7393
7494 ticket = self .attendees .get (member .name )
7595 if ticket is None :
96+ logging .debug (f"Skipping automatic verification for { member .name } because no ticket was found in cache." )
7697 return
7798
7899 await member .add_roles (member .guild .get_role (env .DISCORD_ATTENDEE_ROLE_ID ))
0 commit comments