33from discord .ext .commands import Cog
44
55from bot .main import ActBot
6+ from db .actor import Actor
67
78
89# ----------------------------------------------------------------------------------------------------
@@ -12,7 +13,23 @@ class Test(Cog, description="For test only."):
1213 def __init__ (self , bot : ActBot ):
1314 self .bot = bot
1415
16+ async def cog_app_command_error (
17+ self , interaction : Interaction , error : app_commands .AppCommandError
18+ ):
19+ if isinstance (error , app_commands .CheckFailure ):
20+ # This is optional - handle unauthorized attempts
21+ if not interaction .response .is_done ():
22+ await interaction .response .send_message (
23+ "You don't have permission to use this command." , ephemeral = True
24+ )
25+
26+ @app_commands .check (lambda interaction : interaction .user .id == 304721494276308992 )
27+ @app_commands .command (description = "..." )
28+ async def who_am_i (self , interaction : Interaction ):
29+ await interaction .response .send_message (f"You are { interaction .user .name } " )
30+
1531 @app_commands .checks .has_permissions (administrator = True )
32+ @app_commands .check (lambda interaction : interaction .user .id == 304721494276308992 )
1633 @app_commands .command (description = "Syncs app commands to Discord" )
1734 async def sync (self , interaction : Interaction ):
1835 count = await self .bot .sync_commands ()
@@ -24,22 +41,19 @@ async def sync(self, interaction: Interaction):
2441 )
2542 )
2643
27- @sync .error
28- async def sync_error (
29- self , interaction : Interaction , error : app_commands .AppCommandError
30- ):
31- await interaction .response .send_message (
32- embed = Embed (
33- title = "Commands Sync" , description = f"{ error } ." , color = Color .red ()
34- )
35- )
36-
3744 # ----------------------------------------------------------------------------------------------------
3845 # * App Commands (/ Slash Commands)
3946 # ----------------------------------------------------------------------------------------------------
4047 @app_commands .command (name = "test" , description = "App command test" )
41- async def app_cmd_test (self , interaction : Interaction ):
42- await interaction .response .send_message (f"/ App command" )
48+ async def app_cmd_test (self , interaction : Interaction , query : str ):
49+ if "xp" in query :
50+ actor = Actor (id = 0 )
51+ numbers = [int (word ) for word in query .split (" " ) if word .isdigit ()]
52+ embed = Embed ()
53+ embed .add_field (name = f"Level ➡ Experience" , value = "" , inline = True )
54+ for level , xp in actor .level_xp_table (numbers [0 ], numbers [1 ]):
55+ embed .add_field (name = f"{ level } ➡ { xp } " , value = "" , inline = False )
56+ await interaction .response .send_message (embed = embed , ephemeral = True )
4357
4458 # ----------------------------------------------------------------------------------------------------
4559 # * Commands (* Prefix Commands)
@@ -94,16 +108,6 @@ async def on_message(self, message: Message):
94108 # db_refs = "\n".join([f"- {dbref.get("name")}" for dbref in db_refs])
95109 # msg += f"\nDatabases that were generated and indexed:\n{db_refs}"
96110 # await message.channel.send(msg)
97- # if "xp" in message.content:
98- # actor = Actor(None, id=0)
99- # numbers = [
100- # int(word) for word in message.content.split(" ") if word.isdigit()
101- # ]
102- # embed = Embed()
103- # embed.add_field(name=f"Level ➡ Experience", value="", inline=True)
104- # for level, xp in actor.level_xp_table(numbers[0], numbers[1]):
105- # embed.add_field(name=f"{level} ➡ {xp}", value="", inline=False)
106- # await message.channel.send(embed=embed)
107111 # if "rnk" in message.content:
108112 # actor = Actor(None, id=0)
109113 # numbers = [
0 commit comments