@@ -13,6 +13,7 @@ import {
1313 getActiveBoosters ,
1414 getTotalBoosts ,
1515 registerBoost ,
16+ ensureGuild ,
1617} from "../services/boosterService.js" ;
1718
1819const boosterCommand : Command = {
@@ -56,7 +57,7 @@ const boosterCommand: Command = {
5657 . setDescription ( "Amount to remove" )
5758 . setRequired ( true )
5859 . setMinValue ( 1 )
59- )
60+ )
6061 )
6162 . addSubcommand ( ( sub ) =>
6263 sub . setName ( "stats" ) . setDescription ( "View server boost statistics" )
@@ -65,53 +66,60 @@ const boosterCommand: Command = {
6566 async execute ( interaction : ChatInputCommandInteraction ) : Promise < void > {
6667 const sub = interaction . options . getSubcommand ( ) ;
6768
69+ // All subcommands need a guild — bail early if missing
70+ const discordGuild = interaction . guild ;
71+ if ( ! discordGuild ) {
72+ await interaction . reply ( { content : "This command can only be used in a server." , ephemeral : true } ) ;
73+ return ;
74+ }
75+
76+ await interaction . deferReply ( { ephemeral : true } ) ;
77+
6878 if ( sub === "check" ) {
6979 const user = interaction . options . getUser ( "user" , true ) ;
70- const record = getBooster ( user . id ) ;
80+ const result = await getBooster ( user . id , interaction ) ;
7181
72- if ( ! record ) {
73- await interaction . reply ( {
74- content : `No booster record found for ${ user . tag } .` ,
75- ephemeral : true ,
76- } ) ;
82+ if ( ! result ?. success || ! result . data ) {
83+ await interaction . editReply ( { content : `No booster record found for ${ user . tag } .` } ) ;
7784 return ;
7885 }
7986
87+ const booster = result . data ;
88+
8089 const embed = new EmbedBuilder ( )
81- . setColor ( record . boosting ? 0xf47fff : 0x99aab5 )
82- . setTitle ( `Booster Info: ${ record . username } ` )
90+ . setColor ( booster . active ? 0xf47fff : 0x99aab5 )
91+ . setTitle ( `Booster Info: ${ user . username } ` )
8392 . addFields (
84- { name : "Status" , value : record . boosting ? "Active" : "Inactive" , inline : true } ,
85- { name : "Boost Count" , value : String ( record . boostCount ) , inline : true } ,
86- { name : "Custom Role" , value : record . customRoleId ? `<@&${ record . customRoleId } >` : "None" , inline : true } ,
87- { name : "Private Channel" , value : record . privateChannelId ? `<#${ record . privateChannelId } >` : "None" , inline : true } ,
88- { name : "First Boosted" , value : new Date ( record . firstBoostAt ) . toLocaleDateString ( ) , inline : true } ,
89- { name : "Last Updated" , value : new Date ( record . lastUpdatedAt ) . toLocaleDateString ( ) , inline : true }
93+ { name : "Status" , value : booster . active ? "🟢 Active" : "🔴 Inactive" , inline : true } ,
94+ { name : "Boost Count" , value : String ( booster . boostCounts ?? 0 ) , inline : true } ,
95+ {
96+ name : "Custom Role" ,
97+ value : booster . customRole ? `<@&${ booster . customRole . discordRoleId } >` : "None" ,
98+ inline : true ,
99+ } ,
100+ { name : "First Boosted" , value : `<t:${ Math . floor ( booster . boostedAt . getTime ( ) / 1000 ) } :D>` , inline : true } ,
101+ { name : "Last Updated" , value : `<t:${ Math . floor ( booster . updatedAt . getTime ( ) / 1000 ) } :R>` , inline : true }
90102 )
91103 . setTimestamp ( ) ;
92104
93- await interaction . reply ( { embeds : [ embed ] , ephemeral : true } ) ;
105+ await interaction . editReply ( { embeds : [ embed ] } ) ;
94106 return ;
95107 }
96108
97109 if ( sub === "add" ) {
98110 const user = interaction . options . getUser ( "user" , true ) ;
99111 const amount = interaction . options . getInteger ( "amount" , true ) ;
100112
101- let record = getBooster ( user . id ) ;
102- if ( ! record ) {
103- record = registerBoost ( user . id , user . username ) ;
104- }
113+ await registerBoost ( user . id , discordGuild . id , discordGuild . name , discordGuild . iconURL ( ) ) ;
105114
106- const updated = addBoostCount ( user . id , amount ) ;
115+ const updated = await addBoostCount ( user . id , discordGuild . id , amount ) ;
107116 if ( ! updated ) {
108- await interaction . reply ( { content : "Failed to update boost count." , ephemeral : true } ) ;
117+ await interaction . editReply ( { content : "Failed to update boost count." } ) ;
109118 return ;
110119 }
111120
112- await interaction . reply ( {
113- content : `Added ${ amount } boost(s) to ${ user . tag } . New count: ${ updated . boostCount } .` ,
114- ephemeral : true ,
121+ await interaction . editReply ( {
122+ content : `Added **${ amount } ** boost(s) to ${ user . tag } . New count: **${ updated . boostCounts } **.` ,
115123 } ) ;
116124 return ;
117125 }
@@ -120,23 +128,24 @@ const boosterCommand: Command = {
120128 const user = interaction . options . getUser ( "user" , true ) ;
121129 const amount = interaction . options . getInteger ( "amount" , true ) ;
122130
123- const updated = removeBoostCount ( user . id , amount ) ;
131+ const updated = await removeBoostCount ( user . id , discordGuild . id , amount ) ;
124132 if ( ! updated ) {
125- await interaction . reply ( { content : `No booster record found for ${ user . tag } .` , ephemeral : true } ) ;
133+ await interaction . editReply ( { content : `No booster record found for ${ user . tag } .` } ) ;
126134 return ;
127135 }
128136
129- await interaction . reply ( {
130- content : `Removed ${ amount } boost(s) from ${ user . tag } . New count: ${ updated . boostCount } .` ,
131- ephemeral : true ,
137+ await interaction . editReply ( {
138+ content : `Removed **${ amount } ** boost(s) from ${ user . tag } . New count: **${ updated . boostCounts } **.` ,
132139 } ) ;
133140 return ;
134141 }
135142
136143 if ( sub === "stats" ) {
137- const activeBoosters = getActiveBoosters ( ) ;
138- const allBoosters = getAllBoosters ( ) ;
139- const totalBoosts = getTotalBoosts ( ) ;
144+ const [ activeBoosters , allBoosters , totalBoosts ] = await Promise . all ( [
145+ getActiveBoosters ( discordGuild . id ) ,
146+ getAllBoosters ( discordGuild . id ) ,
147+ getTotalBoosts ( discordGuild . id ) ,
148+ ] ) ;
140149
141150 const embed = new EmbedBuilder ( )
142151 . setColor ( 0xf47fff )
@@ -148,7 +157,7 @@ const boosterCommand: Command = {
148157 )
149158 . setTimestamp ( ) ;
150159
151- await interaction . reply ( { embeds : [ embed ] } ) ;
160+ await interaction . editReply ( { embeds : [ embed ] } ) ;
152161 return ;
153162 }
154163 } ,
0 commit comments