1
- import type { MessageChannel } from '../../index' ;
2
- import { ApplyOptions } from '@sapphire/decorators' ;
3
- import { Command , CommandOptions , container } from '@sapphire/framework' ;
4
- import type { GuildChannel } from 'discord.js' ;
5
- import { isTextBasedChannel } from '@sapphire/discord.js-utilities' ;
6
- import { notify } from '../../lib/utils/twitch/notifyChannel' ;
7
- import { trpcNode } from '../../trpc' ;
1
+ import { ApplyOptions } from "@sapphire/decorators" ;
2
+ import { isTextBasedChannel } from "@sapphire/discord.js-utilities" ;
3
+ import { Command , CommandOptions , container } from "@sapphire/framework" ;
4
+ import type { GuildChannel } from "discord.js" ;
5
+
6
+ import type { MessageChannel } from "../../index" ;
7
+ import { notify } from "../../lib/utils/twitch/notifyChannel" ;
8
+ import { trpcNode } from "../../trpc" ;
8
9
9
10
@ApplyOptions < CommandOptions > ( {
10
- name : ' add-streamer' ,
11
- description : ' Add a Stream alert from your favorite Twitch streamer' ,
12
- requiredUserPermissions : ' ModerateMembers' ,
13
- preconditions : [ ' GuildOnly' , ' isCommandDisabled' ]
11
+ name : " add-streamer" ,
12
+ description : " Add a Stream alert from your favorite Twitch streamer" ,
13
+ requiredUserPermissions : " ModerateMembers" ,
14
+ preconditions : [ " GuildOnly" , " isCommandDisabled" ] ,
14
15
} )
15
16
export class AddStreamerCommand extends Command {
16
17
public override async chatInputRun (
17
- interaction : Command . ChatInputCommandInteraction
18
+ interaction : Command . ChatInputCommandInteraction ,
18
19
) {
19
- const streamerName = interaction . options . getString ( ' streamer-name' , true ) ;
20
- const channelData = interaction . options . getChannel ( ' channel-name' , true ) ;
20
+ const streamerName = interaction . options . getString ( " streamer-name" , true ) ;
21
+ const channelData = interaction . options . getChannel ( " channel-name" , true ) ;
21
22
const { client } = container ;
22
23
23
24
let isError = false ;
24
25
let user ;
25
26
try {
26
27
user = await client . twitch . api . getUser ( {
27
28
login : streamerName ,
28
- token : client . twitch . auth . access_token
29
+ token : client . twitch . auth . access_token ,
29
30
} ) ;
30
31
} catch ( error : any ) {
31
32
isError = true ;
32
33
if ( error . status == 400 ) {
33
34
return await interaction . reply ( {
34
- content : `:x: "${ streamerName } " was Invalid, Please try again.`
35
+ content : `:x: "${ streamerName } " was Invalid, Please try again.` ,
35
36
} ) ;
36
37
}
37
38
if ( error . status === 401 ) {
38
39
return await interaction . reply ( {
39
- content : `:x: You are not authorized to use this command.`
40
+ content : `:x: You are not authorized to use this command.` ,
40
41
} ) ;
41
42
}
42
43
if ( error . status == 429 ) {
43
44
return await interaction . reply ( {
44
- content : ':x: Rate Limit exceeded. Please try again in a few minutes.'
45
+ content :
46
+ ":x: Rate Limit exceeded. Please try again in a few minutes." ,
45
47
} ) ;
46
48
}
47
49
if ( error . status == 500 ) {
48
50
return await interaction . reply ( {
49
- content : `:x: Twitch service's are currently unavailable. Please try again later.`
51
+ content : `:x: Twitch service's are currently unavailable. Please try again later.` ,
50
52
} ) ;
51
53
} else {
52
54
return await interaction . reply ( {
53
- content : `:x: Something went wrong.`
55
+ content : `:x: Something went wrong.` ,
54
56
} ) ;
55
57
}
56
58
}
57
59
58
60
if ( isError ) return ;
59
61
if ( ! user )
60
62
return await interaction . reply ( {
61
- content : `:x: ${ streamerName } was not Found`
63
+ content : `:x: ${ streamerName } was not Found` ,
62
64
} ) ;
63
65
if ( ! isTextBasedChannel ( channelData as GuildChannel ) )
64
66
return await interaction . reply ( {
65
- content : `:x: Can't send messages to ${ channelData . name } `
67
+ content : `:x: Can't send messages to ${ channelData . name } ` ,
66
68
} ) ;
67
69
68
70
const guildDB = await trpcNode . guild . getGuild . query ( {
69
- id : interaction . guild ! . id
71
+ id : interaction . guild ! . id ,
70
72
} ) ;
71
73
72
74
if ( ! guildDB . guild ) {
73
75
return await interaction . reply ( {
74
- content : `:x: Something went wrong.`
76
+ content : `:x: Something went wrong.` ,
75
77
} ) ;
76
78
}
77
79
78
80
// check if streamer is already on notify list
79
81
if ( guildDB ?. guild . notifyList . includes ( user . id ) )
80
82
return await interaction . reply ( {
81
- content : `:x: ${ user . display_name } is already on your Notification list`
83
+ content : `:x: ${ user . display_name } is already on your Notification list` ,
82
84
} ) ;
83
85
84
86
// make sure channel is not already on notify list
85
87
for ( const twitchChannel in client . twitch . notifyList ) {
86
- for ( const channelToMsg of client . twitch . notifyList [ twitchChannel ]
88
+ for ( const channelToMsg of client . twitch . notifyList [ twitchChannel ] !
87
89
. sendTo ) {
88
90
const query = client . channels . cache . get ( channelToMsg ) as MessageChannel ;
89
91
if ( query )
90
92
if ( query . guild . id == interaction . guild ?. id ) {
91
93
if ( twitchChannel == user . id )
92
94
return await interaction . reply ( {
93
- content : `:x: **${ user . display_name } ** is already has a notification in **#${ query . name } **`
95
+ content : `:x: **${ user . display_name } ** is already has a notification in **#${ query . name } **` ,
94
96
} ) ;
95
97
}
96
98
}
97
99
}
98
100
// make sure no one else is already sending alerts about this streamer
99
101
if ( client . twitch . notifyList [ user . id ] ?. sendTo . includes ( channelData . id ) )
100
102
return await interaction . reply ( {
101
- content : `:x: **${ user . display_name } ** is already messaging ${ channelData . name } `
103
+ content : `:x: **${ user . display_name } ** is already messaging ${ channelData . name } ` ,
102
104
} ) ;
103
105
104
106
let channelArray ;
105
107
if ( client . twitch . notifyList [ user . id ] )
106
108
channelArray = [
107
- ...client . twitch . notifyList [ user . id ] . sendTo ,
108
- ...[ channelData . id ]
109
+ ...client . twitch . notifyList [ user . id ] ! . sendTo ,
110
+ ...[ channelData . id ] ,
109
111
] ;
110
112
else channelArray = [ channelData . id ] ;
111
113
112
114
// add notification to twitch object on client
113
115
client . twitch . notifyList [ user . id ]
114
- ? ( client . twitch . notifyList [ user . id ] . sendTo = channelArray )
116
+ ? ( client . twitch . notifyList [ user . id ] ! . sendTo = channelArray )
115
117
: ( client . twitch . notifyList [ user . id ] = {
116
118
sendTo : [ channelData . id ] ,
117
119
live : false ,
118
120
logo : user . profile_image_url ,
119
121
messageSent : false ,
120
- messageHandler : { }
122
+ messageHandler : { } ,
121
123
} ) ;
122
124
123
125
// add notification to database
124
126
await trpcNode . twitch . create . mutate ( {
125
127
userId : user . id ,
126
128
userImage : user . profile_image_url ,
127
129
channelId : channelData . id ,
128
- sendTo : client . twitch . notifyList [ user . id ] . sendTo
130
+ sendTo : client . twitch . notifyList [ user . id ] ! . sendTo ,
129
131
} ) ;
130
132
131
133
// add notification to guild on database
@@ -137,11 +139,11 @@ export class AddStreamerCommand extends Command {
137
139
guildId : guild . id ,
138
140
notifyList : concatedArray ,
139
141
ownerId : guild . ownerId ,
140
- userId : interaction . user . id
142
+ userId : interaction . user . id ,
141
143
} ) ;
142
144
143
145
await interaction . reply ( {
144
- content : `**${ user . display_name } ** Stream Notification will be sent to **#${ channelData . name } **`
146
+ content : `**${ user . display_name } ** Stream Notification will be sent to **#${ channelData . name } **` ,
145
147
} ) ;
146
148
const newQuery : string [ ] = [ ] ;
147
149
// pickup newly added entries
@@ -153,30 +155,30 @@ export class AddStreamerCommand extends Command {
153
155
}
154
156
155
157
public override registerApplicationCommands (
156
- registry : Command . Registry
158
+ registry : Command . Registry ,
157
159
) : void {
158
160
if ( ! process . env . TWITCH_CLIENT_ID || ! process . env . TWITCH_CLIENT_SECRET ) {
159
161
return ;
160
162
}
161
163
162
- registry . registerChatInputCommand ( builder =>
164
+ registry . registerChatInputCommand ( ( builder ) =>
163
165
builder
164
166
. setName ( this . name )
165
167
. setDescription ( this . description )
166
- . addStringOption ( option =>
168
+ . addStringOption ( ( option ) =>
167
169
option
168
- . setName ( ' streamer-name' )
169
- . setDescription ( ' What is the name of the Twitch streamer?' )
170
- . setRequired ( true )
170
+ . setName ( " streamer-name" )
171
+ . setDescription ( " What is the name of the Twitch streamer?" )
172
+ . setRequired ( true ) ,
171
173
)
172
- . addChannelOption ( option =>
174
+ . addChannelOption ( ( option ) =>
173
175
option
174
- . setName ( ' channel-name' )
176
+ . setName ( " channel-name" )
175
177
. setDescription (
176
- ' What is the name of the Channel you would like the alert to be sent to?'
178
+ " What is the name of the Channel you would like the alert to be sent to?" ,
177
179
)
178
- . setRequired ( true )
179
- )
180
+ . setRequired ( true ) ,
181
+ ) ,
180
182
) ;
181
183
}
182
184
}
0 commit comments