33import client from '.' ;
44import { ActionRowBuilder , ButtonBuilder , ButtonStyle , type CommandInteraction , ChannelType , type APIApplicationCommandOption , GuildMember , AttachmentBuilder , ComponentType } from 'discord.js' ;
55import { heapStats } from 'bun:jsc' ;
6- import { getGuildLeaderboard , makeGETRequest , getRoles , removeRole , addRole , enableUpdates , disableUpdates , getCooldown , setCooldown , checkIfGuildHasUpdatesEnabled } from './utils/requestAPI' ;
6+ import { getGuildLeaderboard , makeGETRequest , getRoles , removeRole , addRole , enableUpdates , disableUpdates , getCooldown , setCooldown , getUpdatesChannel , setUpdatesChannel } from './utils/requestAPI' ;
77import convertToLevels from './utils/convertToLevels' ;
88import quickEmbed from './utils/quickEmbed' ;
99import { Font , RankCardBuilder } from 'canvacord' ;
@@ -161,7 +161,7 @@ const commands: Record<string, Command> = {
161161 . setDisplayName ( member . displayName )
162162 . setAvatar ( member . displayAvatarURL ( { forceStatic : true , size : 4096 } ) ) // user avatar
163163 . setCurrentXP ( xp . xp ) // current xp
164- . setRequiredXP ( xp . xp_needed_next_level ) // required xp
164+ . setRequiredXP ( xp . xp + xp . xp_needed_next_level ) // required xp
165165 . setLevel ( xp . level ) // user level
166166 . setRank ( rank ) // user rank
167167 . setOverlay ( member . user . banner ? 95 : 90 ) // overlay percentage. Overlay is a semi-transparent layer on top of the background
@@ -450,24 +450,37 @@ const commands: Record<string, Command> = {
450450 data : {
451451 options : [ {
452452 name : 'action' ,
453- description : 'Note that enabling is in THIS channel and will override the current updates channel! ' ,
453+ description : 'Select an action ' ,
454454 type : 3 ,
455455 required : true ,
456456 choices : [
457457 {
458- name : 'check ' ,
458+ name : 'Check ' ,
459459 value : 'check' ,
460460 } ,
461461 {
462- name : 'enable ' ,
462+ name : 'Enable ' ,
463463 value : 'enable' ,
464464 } ,
465465 {
466- name : 'disable ' ,
466+ name : 'Disable ' ,
467467 value : 'disable' ,
468- }
468+ } ,
469+ {
470+ name : 'Set' ,
471+ value : 'set' ,
472+ } ,
473+ {
474+ name : 'Reset to Default' ,
475+ value : 'reset' ,
476+ } ,
469477 ]
470- } , ] ,
478+ } , {
479+ name : 'channel' ,
480+ description : 'Enter the channel ID. Required for set action.' ,
481+ type : 7 ,
482+ required : false ,
483+ } ] ,
471484 name : 'updates' ,
472485 description : 'Get the latest updates on the bot!' ,
473486 integration_types : [ 0 ] ,
@@ -494,6 +507,14 @@ const commands: Record<string, Command> = {
494507 let data
495508
496509 switch ( action ) {
510+ case 'enable' :
511+ success = await enableUpdates ( interaction . guildId as string ) ;
512+ if ( ! success ) {
513+ await interaction . reply ( { ephemeral : true , content : 'Error enabling updates for this server' } ) . catch ( console . error ) ;
514+ return ;
515+ }
516+ await interaction . reply ( { ephemeral : true , content : `Updates are now enabled for this server` } ) . catch ( console . error ) ;
517+ return ;
497518 case 'disable' :
498519 success = await disableUpdates ( interaction . guildId as string ) ;
499520 if ( ! success ) {
@@ -502,22 +523,54 @@ const commands: Record<string, Command> = {
502523 }
503524 await interaction . reply ( { ephemeral : true , content : 'Updates are now disabled for this server' } ) . catch ( console . error ) ;
504525 return ;
505- case 'enable' :
506- success = await enableUpdates ( interaction . guildId as string , channelId as string ) ;
526+ case 'set' :
527+ if ( ! channelId ) {
528+ await interaction . reply ( { ephemeral : true , content : 'ERROR: Channel was not specified!' } ) ;
529+ return ;
530+ }
531+ success = await setUpdatesChannel ( interaction . guildId as string , channelId ) ;
507532 if ( ! success ) {
508- await interaction . reply ( { ephemeral : true , content : 'Error enabling updates for this server' } ) . catch ( console . error ) ;
533+ await interaction . reply ( { ephemeral : true , content : 'Error setting updates channel for this server' } ) . catch ( console . error ) ;
509534 return ;
510535 }
511- await interaction . reply ( { ephemeral : true , content : `Updates are now enabled for this server in <#${ channelId } >` } ) . catch ( console . error ) ;
536+ await interaction . reply ( { ephemeral : true , content : `Updates channel has been set to <#${ channelId } >` } ) . catch ( console . error ) ;
512537 return ;
538+ case 'reset' :
539+ success = await setUpdatesChannel ( interaction . guildId as string , null ) ;
540+ if ( ! success ) {
541+ await interaction . reply ( { ephemeral : true , content : 'Error resetting updates channel for this server' } ) . catch ( console . error ) ;
542+ return ;
543+ }
544+ await interaction . reply ( { ephemeral : true , content : `Updates channel has been reset to default` } ) . catch ( console . error ) ;
545+ return
513546 default :
514- data = await checkIfGuildHasUpdatesEnabled ( interaction . guildId as string ) ;
547+ data = await getUpdatesChannel ( interaction . guildId as string ) ;
515548 if ( ! data || Object . keys ( data ) . length === 0 ) {
516549 await interaction . reply ( { ephemeral : true , content : 'No data found' } ) . catch ( console . error ) ;
517550 return ;
518551 }
519- // TODO: Format in embed
520- await interaction . reply ( { ephemeral : true , content : JSON . stringify ( data , null , 2 ) } ) . catch ( console . error ) ;
552+ await interaction . reply ( {
553+ embeds : [
554+ quickEmbed ( {
555+ color : 'Blurple' ,
556+ title : 'Updates' ,
557+ description : 'Updates for this server' ,
558+ } , interaction )
559+ . addFields (
560+ {
561+ name : 'Enabled' ,
562+ value : data . enabled ? 'Yes' : 'No' ,
563+ inline : true ,
564+ } ,
565+ {
566+ name : 'Channel' ,
567+ value : data . channel ? `<#${ data . channel } >` : 'N/A' ,
568+ inline : true ,
569+ } ,
570+ )
571+ ] ,
572+ ephemeral : true
573+ } ) . catch ( console . error ) ;
521574 return ;
522575 }
523576 } ,
0 commit comments