11import discord
22from discord .ext import commands
3- from bot .utils .DButil import get_db_connection , initialize_db , add_predefined_weapons
3+ from discord import app_commands
4+ import aiosqlite
5+ from bot .utils .DButil import get_db_path , get_db_connection , initialize_db , add_predefined_weapons , async_get_db_connection
46
7+ # Ensure DB is initialized on import (safe)
58initialize_db ()
69add_predefined_weapons ()
710
@@ -10,29 +13,29 @@ class Duel(commands.Cog):
1013 def __init__ (self , bot ):
1114 self .bot = bot
1215
13- @commands .command (name = 'dm_register' )
14- async def register_user (self , ctx ):
15- user_id = str (ctx . author .id )
16- conn = get_db_connection ()
17- c = conn . cursor ( )
18- c . execute ( 'INSERT OR IGNORE INTO users (user_id) VALUES (?)' , ( user_id ,) )
19- conn . commit ()
20- conn . close ( )
21- await ctx . send ( f" { ctx . author . mention } , you have been registered!" )
22-
23- @ commands . command ( name = 'dm_balance' )
24- async def check_balance ( self , ctx ):
25- user_id = str ( ctx . author . id )
26- conn = get_db_connection ()
27- c = conn . cursor ()
28- c . execute ( 'SELECT gold FROM users WHERE user_id = ?' , ( user_id ,) )
29- user_data = c . fetchone ()
30- conn . close ()
31- if user_data :
32- await ctx . send (f"{ ctx . author .mention } , you have { user_data [ ' gold' ] } gold." )
16+ @app_commands .command (name = 'dm_register' , description = 'Register for duel economy ' )
17+ async def register_user (self , interaction : discord . Interaction ):
18+ user_id = str (interaction . user .id )
19+ db = await async_get_db_connection ()
20+ await db . execute ( 'INSERT OR IGNORE INTO users (user_id) VALUES (?)' , ( user_id ,) )
21+ await db . commit ( )
22+ await db . close ()
23+ await interaction . response . send_message ( f" { interaction . user . mention } , you have been registered!" , ephemeral = True )
24+
25+ @ app_commands . command ( name = 'dm_balance' , description = 'Check your duel balance' )
26+ async def check_balance ( self , interaction : discord . Interaction ):
27+ user_id = str ( interaction . user . id )
28+ db = await async_get_db_connection ( )
29+ async with db . execute ( 'SELECT gold FROM users WHERE user_id = ?' , ( user_id ,)) as cursor :
30+ row = await cursor . fetchone ()
31+ await db . close ( )
32+
33+ if row :
34+ gold = row [ 0 ]
35+ await interaction . response . send_message (f"{ interaction . user .mention } , you have { gold } gold." , ephemeral = True )
3336 else :
34- await ctx . send (f"{ ctx . author .mention } , you need to register first by using /dm_register." )
35-
37+ await interaction . response . send_message (f"{ interaction . user .mention } , you need to register first by using /dm_register." , ephemeral = True )
38+
3639 @commands .command (name = 'dm_storage' )
3740 async def view_storage (self , ctx ):
3841 user_id = ctx .author .id
0 commit comments