@@ -27,6 +27,7 @@ import {
2727 checkIfGuildIsTrackingUserAlready ,
2828 discordAddGuildTrackingUser ,
2929 discordGetAllTrackedInGuild ,
30+ discordRemoveGuildTrackingChannel ,
3031} from "./db/discord" ;
3132import { Platform , YouTubeContentType } from "./types/types.d" ;
3233import searchTwitch from "./utils/twitch/searchTwitch" ;
@@ -477,10 +478,25 @@ const commands: Record<string, Command> = {
477478 trackedChannels . data
478479 ) {
479480 // If the channel is already being tracked in the guild, we can just return
480- await interaction . reply ( {
481- flags : MessageFlags . Ephemeral ,
482- content : `This channel is already being tracked in ${ trackedChannels . data . map ( ( channel , index ) => `${ index > 0 && index === trackedChannels . data . length - 1 ? "and " : "" } <#${ channel . guild_channel_id } >` ) . join ( ", " ) } !` ,
483- } ) ;
481+ if ( Array . isArray ( trackedChannels . data ) ) {
482+ const channelList = trackedChannels . data
483+ . map (
484+ ( channel , index , arr ) =>
485+ `${ index > 0 && index === arr . length - 1 ? "and " : "" } <#${ channel . notificationChannelId } >` ,
486+ )
487+ . join ( ", " ) ;
488+
489+ await interaction . reply ( {
490+ flags : MessageFlags . Ephemeral ,
491+ content : `This channel is already being tracked in ${ channelList } !` ,
492+ } ) ;
493+ } else {
494+ await interaction . reply ( {
495+ flags : MessageFlags . Ephemeral ,
496+ content :
497+ "This channel is already being tracked, but the data format is invalid." ,
498+ } ) ;
499+ }
484500
485501 return ;
486502 }
@@ -590,10 +606,25 @@ const commands: Record<string, Command> = {
590606 trackedChannels . data
591607 ) {
592608 // If the channel is already being tracked in the guild, we can just return
593- await interaction . reply ( {
594- flags : MessageFlags . Ephemeral ,
595- content : `This channel is already being tracked in ${ trackedChannels . data . map ( ( channel , index ) => `${ index > 0 && index === trackedChannels . data . length - 1 ? "and " : "" } <#${ channel . guild_channel_id } >` ) . join ( ", " ) } !` ,
596- } ) ;
609+ if ( Array . isArray ( trackedChannels . data ) ) {
610+ const channelList = trackedChannels . data
611+ . map (
612+ ( channel , index , arr ) =>
613+ `${ index > 0 && index === arr . length - 1 ? "and " : "" } <#${ channel . notificationChannelId } >` ,
614+ )
615+ . join ( ", " ) ;
616+
617+ await interaction . reply ( {
618+ flags : MessageFlags . Ephemeral ,
619+ content : `This channel is already being tracked in ${ channelList } !` ,
620+ } ) ;
621+ } else {
622+ await interaction . reply ( {
623+ flags : MessageFlags . Ephemeral ,
624+ content :
625+ "This channel is already being tracked, but the data format is invalid." ,
626+ } ) ;
627+ }
597628
598629 return ;
599630 }
@@ -775,9 +806,7 @@ const commands: Record<string, Command> = {
775806 } ,
776807 execute : async ( interaction : CommandInteraction ) => {
777808 // Get the YouTube Channel ID
778- const youtubeChannelId = interaction . options . get ( "user_id" )
779- ?. value as string ;
780- const platform = interaction . options . get ( "platform" )
809+ const platformUserId = interaction . options . get ( "user_id" )
781810 ?. value as string ;
782811 const guildId = interaction . guildId ;
783812
@@ -807,110 +836,22 @@ const commands: Record<string, Command> = {
807836 return ;
808837 }
809838
810- // Platform check (to shut up TS)
811- if ( platform != "youtube" && platform != "twitch" ) {
839+ // Remove the guild from the database
840+ const trackingDeleteSuccess =
841+ await discordRemoveGuildTrackingChannel ( platformUserId ) ;
842+
843+ if ( ! trackingDeleteSuccess || ! trackingDeleteSuccess . success ) {
812844 await interaction . reply ( {
813845 flags : MessageFlags . Ephemeral ,
814- content :
815- "Platform not supported! Please select a platform to track!" ,
846+ content : "Failed to stop tracking the channel." ,
816847 } ) ;
817848
818849 return ;
819850 }
820851
821- // Remove the guild from the database
822- switch ( platform ) {
823- case "youtube" :
824- // Check if the channel is not being tracked in the guild
825- if (
826- ! ( await checkIfGuildIsTrackingUserAlready (
827- youtubeChannelId ,
828- guildId ,
829- ) )
830- ) {
831- await interaction . reply ( {
832- flags : MessageFlags . Ephemeral ,
833- content :
834- "This channel is not being tracked in this guild!" ,
835- } ) ;
836-
837- return ;
838- }
839- if (
840- await stopGuildTrackingChannel (
841- guildId ,
842- youtubeChannelId ,
843- )
844- ) {
845- await interaction . reply ( {
846- flags : MessageFlags . Ephemeral ,
847- content :
848- "Successfully stopped tracking the channel!" ,
849- } ) ;
850- } else {
851- await interaction . reply ( {
852- flags : MessageFlags . Ephemeral ,
853- content :
854- "An error occurred while trying to stop tracking the channel! Please report this error!" ,
855- } ) ;
856- }
857-
858- return ;
859- case "twitch" : {
860- // get the twitch id for the streamer
861- const platformUserId =
862- await getplatformUserId ( youtubeChannelId ) ;
863-
864- if ( ! platformUserId ) {
865- await interaction . reply ( {
866- flags : MessageFlags . Ephemeral ,
867- content :
868- "An error occurred while trying to get the streamer ID! Please report this error!" ,
869- } ) ;
870-
871- return ;
872- }
873-
874- // check if the channel is not being tracked in the guild
875- if (
876- ! ( await checkIfGuildIsTrackingUserAlready (
877- platformUserId ,
878- guildId ,
879- ) )
880- ) {
881- await interaction . reply ( {
882- flags : MessageFlags . Ephemeral ,
883- content :
884- "This streamer is not being tracked in this guild!" ,
885- } ) ;
886-
887- return ;
888- }
889-
890- if (
891- await twitchStopGuildTrackingChannel (
892- guildId ,
893- platformUserId ,
894- )
895- ) {
896- await interaction . reply ( {
897- flags : MessageFlags . Ephemeral ,
898- content :
899- "Successfully stopped tracking the streamer!" ,
900- } ) ;
901- } else {
902- await interaction . reply ( {
903- flags : MessageFlags . Ephemeral ,
904- content :
905- "An error occurred while trying to stop tracking the streamer! Please report this error!" ,
906- } ) ;
907- }
908-
909- return ;
910- }
911- default :
912- return ;
913- }
852+ await interaction . reply ( {
853+ content : "Successfully stopped tracking the channel." ,
854+ } ) ;
914855 } ,
915856 autoComplete : async ( interaction : AutocompleteInteraction ) => {
916857 const trackedChannels = await discordGetAllTrackedInGuild (
@@ -940,12 +881,12 @@ const commands: Record<string, Command> = {
940881 trackedYouTubeChannels
941882 . map ( ( channel ) => ( {
942883 name : `YouTube: ${ channel . youtubeChannel . youtubeChannelName } (${ channel . youtubeChannel . youtubeChannelId } ) | <#${ channel . subscription . notificationChannelId } >` ,
943- value : String ( channel . subscription . id ) ,
884+ value : `youtube. ${ String ( channel . subscription . id ) } ` ,
944885 } ) )
945886 . concat (
946887 trackedTwitchChannels . map ( ( channel ) => ( {
947888 name : `Twitch: ${ channel . twitchChannel . twitchChannelName } (${ channel . twitchChannel . twitchChannelId } ) | <#${ channel . subscription . notificationChannelId } >` ,
948- value : String ( channel . subscription . id ) ,
889+ value : `twitch. ${ String ( channel . subscription . id ) } ` ,
949890 } ) ) ,
950891 ) ,
951892 ) ;
0 commit comments