1- import { CommandInteraction , Message , TextChannel } from "discord.js"
1+ import { CommandInteraction , Message } from "discord.js"
22
3- import Command from "../../utils/Command "
3+ import config from "../../data/config.json "
44import client from "../../main"
5+ import Command from "../../utils/Command"
56import { CommandSource , FollowCategory , SendMessage } from "../../utils/Types"
6- import { createTable , getUserID , sendMessage } from "../../utils/Utils"
7- import config from "../../data/config.json"
7+ import { createTable , getUserID , isNewsable , sendMessage } from "../../utils/Utils"
88
99const descriptions : { [ x in FollowCategory ] : string } = {
1010 "events" : "Get event reminders" ,
@@ -100,7 +100,7 @@ Example of adding news: \`${config.prefix}follow add news\``,
100100
101101 async runInteraction ( source : CommandInteraction ) : Promise < SendMessage | undefined > {
102102 const channel = await source . channel ?. fetch ( )
103- if ( ! ( channel instanceof TextChannel ) || source . guild == null )
103+ if ( ! channel || ! isNewsable ( channel ) || source . guild == null )
104104 return sendMessage ( source , "This command can only be executed in guild channels. You can invite this bot in your own server via `.invite`" , undefined , true )
105105
106106 if ( typeof source . member ?. permissions == "string" )
@@ -123,7 +123,7 @@ Example of adding news: \`${config.prefix}follow add news\``,
123123
124124 async runMessage ( source : Message , args : string [ ] ) : Promise < SendMessage | undefined > {
125125 const channel = await source . channel ?. fetch ( )
126- if ( ! ( channel instanceof TextChannel ) || source . guild == null )
126+ if ( ! channel || ! isNewsable ( channel ) || source . guild == null )
127127 return sendMessage ( source , "This command can only be executed in guild channels. You can invite this bot in your own server via `.invite`" , undefined , true )
128128
129129 if ( ! source . member ?. permissions . has ( "ADMINISTRATOR" ) && ! config . admins . includes ( getUserID ( source ) ) )
@@ -154,7 +154,8 @@ Example of adding news: \`${config.prefix}follow add news\``,
154154 }
155155
156156 async runList ( source : CommandSource , category ?: FollowCategory | null ) : Promise < SendMessage | undefined > {
157- if ( ! ( source . channel instanceof TextChannel ) || source . guild == null )
157+ const channel = await source . channel ?. fetch ( )
158+ if ( ! channel || ! isNewsable ( channel ) || source . guild == null )
158159 return sendMessage ( source , "Unable to check channel" , undefined , true )
159160
160161 const { followManager } = client
@@ -165,7 +166,7 @@ Example of adding news: \`${config.prefix}follow add news\``,
165166 for ( const follow of following )
166167 try {
167168 const channel = await client . channels . fetch ( follow . channelID )
168- if ( channel instanceof TextChannel )
169+ if ( isNewsable ( channel ) )
169170 channels . push ( {
170171 channelname : channel . name ,
171172 category : follow . category
@@ -183,7 +184,7 @@ ${createTable(
183184 ) ) } \`\`\``, undefined , true )
184185 }
185186
186- const follows = followManager . getFollows ( source . channel , category )
187+ const follows = followManager . getFollows ( channel , category )
187188 if ( follows . length == 0 ) return sendMessage ( source , `Not following ${ category } ` , undefined , true )
188189 return sendMessage ( source , follows . map ( k => `Following ${ category } since ${ new Date ( k . addedOn ) . toLocaleString ( "en-UK" , {
189190 timeZone : "GMT" ,
@@ -198,23 +199,25 @@ ${createTable(
198199 }
199200
200201 async runUnfollow ( source : CommandSource , category : FollowCategory ) : Promise < SendMessage | undefined > {
201- if ( ! ( source . channel instanceof TextChannel ) || source . guild == null )
202+ const channel = await source . channel ?. fetch ( )
203+ if ( ! channel || ! isNewsable ( channel ) || source . guild == null )
202204 return sendMessage ( source , "Unable to unfollow in this channel" , undefined , true )
203205
204206 const { followManager } = client
205207
206- followManager . unfollow ( source . channel , category )
208+ followManager . unfollow ( channel , category )
207209
208- return sendMessage ( source , `Unfollowed ${ category } in <#${ source . channel . id } >` , undefined , true )
210+ return sendMessage ( source , `Unfollowed ${ category } in <#${ channel . id } >` , undefined , true )
209211 }
210212 async runFollow ( source : CommandSource , category : FollowCategory ) : Promise < SendMessage | undefined > {
211- if ( ! ( source . channel instanceof TextChannel ) || source . guild == null )
213+ const channel = await source . channel ?. fetch ( )
214+ if ( ! channel || ! isNewsable ( channel ) || source . guild == null )
212215 return sendMessage ( source , "Unable to follow in this channel" , undefined , true )
213216
214217 const { followManager } = client
215218
216- followManager . addFollow ( source . guild , source . channel , category , getUserID ( source ) )
219+ followManager . addFollow ( source . guild , channel , category , getUserID ( source ) )
217220
218- return sendMessage ( source , `Now following ${ category } in <#${ source . channel . id } >` , undefined , true )
221+ return sendMessage ( source , `Now following ${ category } in <#${ channel . id } >` , undefined , true )
219222 }
220223}
0 commit comments