1
- import { ApplicationCommandOptionChoiceData , AutocompleteInteraction , CacheType , CommandInteraction } from "discord.js" ;
1
+ import {
2
+ ApplicationCommandOptionChoiceData ,
3
+ AutocompleteInteraction ,
4
+ CacheType ,
5
+ CommandInteraction ,
6
+ } from "discord.js" ;
2
7
import { Command } from "../../shared/command/command" ;
3
8
import { Subcommand } from "../../shared/command/subcommand" ;
4
9
import { getTextChannel } from "../.." ;
5
- import { batphoneChannelId , raiderRoleId } from "../../config" ;
10
+ import { batphoneChannelId , raiderRoleId , wakeupChannelId } from "../../config" ;
6
11
import { authorizeByMemberRoles } from "../../shared/command/util" ;
7
12
import { officerRoleId , modRoleId , knightRoleId } from "../../config" ;
8
13
import { kStringMaxLength } from "buffer" ;
9
14
import { error } from "console" ;
10
15
import { redisClient } from "../../redis/client" ;
11
16
import { redis } from "googleapis/build/src/apis/redis" ;
12
17
import { isObject } from "lodash" ;
18
+ import { container } from "tsyringe" ;
19
+ import { WakeupService } from "../wakeup/wakeup.service" ;
13
20
14
21
class sendBp extends Subcommand {
15
22
public async execute ( interaction : CommandInteraction < CacheType > ) {
16
-
17
23
// authorize
18
- authorizeByMemberRoles ( [
19
- officerRoleId , modRoleId , knightRoleId
20
- ] , interaction ) ;
24
+ authorizeByMemberRoles (
25
+ [ officerRoleId , modRoleId , knightRoleId ] ,
26
+ interaction
27
+ ) ;
21
28
22
29
const message = this . getOption ( "message" , interaction ) ?. value ;
23
30
const bpChannel = await getTextChannel ( batphoneChannelId ) ;
24
- if ( typeof ( message ) === "string" ) {
25
-
31
+ if ( typeof message === "string" ) {
26
32
await bpChannel . send ( {
27
- content : `[${ interaction . user } ] <@&${ raiderRoleId } > ${ message } `
28
- } )
29
- interaction . editReply ( "Batphone posted: " + message )
33
+ content : `[${ interaction . user } ] <@&${ raiderRoleId } > ${ message } ` ,
34
+ } ) ;
35
+ interaction . editReply ( "Batphone posted: " + message ) ;
36
+
37
+ // Wakeup
38
+ if ( wakeupChannelId ) {
39
+ const wakeupService = container . resolve ( WakeupService ) ;
40
+ wakeupService . runWakeup (
41
+ `Batphone. ${ interaction . user } sent ${ message } `
42
+ ) ;
43
+ }
30
44
} else {
31
45
interaction . editReply ( "Failed to post batphone." ) ;
32
46
}
33
-
34
47
}
35
- public async getOptionAutocomplete ( option : string , interaction : AutocompleteInteraction < CacheType > ) : Promise < ApplicationCommandOptionChoiceData < string | number > [ ] | undefined > {
48
+ public async getOptionAutocomplete (
49
+ option : string ,
50
+ interaction : AutocompleteInteraction < CacheType >
51
+ ) : Promise <
52
+ ApplicationCommandOptionChoiceData < string | number > [ ] | undefined
53
+ > {
36
54
const res = await getBpOptions ( ) ;
37
- if ( isObject ( res ) ) {
38
- const opts = Object . entries ( res ) . map (
39
- ( [ key , value ] ) => ( { name : value , value : value } )
40
- ) ;
55
+ if ( isObject ( res ) ) {
56
+ const opts = Object . entries ( res ) . map ( ( [ key , value ] ) => ( {
57
+ name : value ,
58
+ value : value ,
59
+ } ) ) ;
41
60
return opts ;
42
61
}
43
62
return [ ] ;
44
63
}
45
64
46
65
public get command ( ) {
47
- return super . command
48
- . addStringOption ( ( o ) =>
49
- o . setName ( "message" )
50
- . setDescription ( "BP Message" )
51
- . setRequired ( true )
52
- . setAutocomplete ( true )
53
- )
66
+ return super . command . addStringOption ( ( o ) =>
67
+ o
68
+ . setName ( "message" )
69
+ . setDescription ( "BP Message" )
70
+ . setRequired ( true )
71
+ . setAutocomplete ( true )
72
+ ) ;
54
73
}
55
74
}
56
75
57
76
class setBp extends Subcommand {
58
77
public async execute ( interaction : CommandInteraction < CacheType > ) {
59
-
60
78
// authorize
61
- authorizeByMemberRoles ( [
62
- officerRoleId , modRoleId , knightRoleId
63
- ] , interaction ) ;
79
+ authorizeByMemberRoles (
80
+ [ officerRoleId , modRoleId , knightRoleId ] ,
81
+ interaction
82
+ ) ;
64
83
65
84
const message = this . getOption ( "message" , interaction ) ?. value ;
66
85
try {
67
- if ( typeof ( message ) === "string" ) {
86
+ if ( typeof message === "string" ) {
68
87
let key = this . getOption ( "key" , interaction ) ?. value ;
69
- if ( ! key ) {
88
+ if ( ! key ) {
70
89
key = message . split ( " " ) [ 0 ] . toLowerCase ( ) ;
71
90
}
72
91
await redisClient . hSet ( "bp" , String ( key ) , message ) ;
73
- interaction . editReply ( "Saved preset message: " + message )
92
+ interaction . editReply ( "Saved preset message: " + message ) ;
74
93
} else {
75
94
throw error ;
76
95
}
77
- } catch ( err ) {
96
+ } catch ( err ) {
78
97
console . error ( err ) ;
79
98
interaction . editReply ( "Failed save batphone message." ) ;
80
99
}
81
-
82
100
}
83
- public async getOptionAutocomplete ( option : string , interaction : AutocompleteInteraction < CacheType > ) : Promise < ApplicationCommandOptionChoiceData < string | number > [ ] | undefined > {
101
+ public async getOptionAutocomplete (
102
+ option : string ,
103
+ interaction : AutocompleteInteraction < CacheType >
104
+ ) : Promise <
105
+ ApplicationCommandOptionChoiceData < string | number > [ ] | undefined
106
+ > {
84
107
return [ ] ;
85
108
}
86
109
87
110
public get command ( ) {
88
111
return super . command
89
112
. addStringOption ( ( o ) =>
90
- o . setName ( "message" )
113
+ o
114
+ . setName ( "message" )
91
115
. setDescription ( "BP Message" )
92
116
. setRequired ( true )
93
117
. setAutocomplete ( false )
94
- ) . addStringOption ( ( o ) =>
95
- o . setName ( "key" )
118
+ )
119
+ . addStringOption ( ( o ) =>
120
+ o
121
+ . setName ( "key" )
96
122
. setDescription ( "Key (optional" )
97
123
. setRequired ( false )
98
124
. setAutocomplete ( false )
99
- )
125
+ ) ;
100
126
}
101
127
}
102
128
103
129
class unsetBp extends Subcommand {
104
130
public async execute ( interaction : CommandInteraction < CacheType > ) {
105
-
106
131
// authorize
107
- authorizeByMemberRoles ( [
108
- officerRoleId , modRoleId , knightRoleId
109
- ] , interaction ) ;
132
+ authorizeByMemberRoles (
133
+ [ officerRoleId , modRoleId , knightRoleId ] ,
134
+ interaction
135
+ ) ;
110
136
111
137
const key = this . getOption ( "message" , interaction ) ?. value ;
112
138
try {
113
- if ( typeof ( key ) === "string" ) {
139
+ if ( typeof key === "string" ) {
114
140
await redisClient . hDel ( "bp" , String ( key ) ) ;
115
- interaction . editReply ( "Removed preset message: " + key )
141
+ interaction . editReply ( "Removed preset message: " + key ) ;
116
142
} else {
117
143
throw error ;
118
144
}
119
- } catch ( err ) {
145
+ } catch ( err ) {
120
146
console . error ( err ) ;
121
147
interaction . editReply ( "Failed save batphone message." ) ;
122
148
}
123
149
}
124
- public async getOptionAutocomplete ( option : string , interaction : AutocompleteInteraction < CacheType > ) : Promise < ApplicationCommandOptionChoiceData < string | number > [ ] | undefined > {
150
+ public async getOptionAutocomplete (
151
+ option : string ,
152
+ interaction : AutocompleteInteraction < CacheType >
153
+ ) : Promise <
154
+ ApplicationCommandOptionChoiceData < string | number > [ ] | undefined
155
+ > {
125
156
const res = await getBpOptions ( ) ;
126
- if ( isObject ( res ) ) {
127
- const opts = Object . entries ( res ) . map (
128
- ( [ key , value ] ) => ( { name : value , value : key } )
129
- ) ;
157
+ if ( isObject ( res ) ) {
158
+ const opts = Object . entries ( res ) . map ( ( [ key , value ] ) => ( {
159
+ name : value ,
160
+ value : key ,
161
+ } ) ) ;
130
162
return opts ;
131
163
}
132
164
return [ ] ;
133
165
}
134
166
135
167
public get command ( ) {
136
- return super . command
137
- . addStringOption ( ( o ) =>
138
- o . setName ( "message" )
139
- . setDescription ( "BP Message" )
140
- . setRequired ( true )
141
- . setAutocomplete ( true )
142
- )
168
+ return super . command . addStringOption ( ( o ) =>
169
+ o
170
+ . setName ( "message" )
171
+ . setDescription ( "BP Message" )
172
+ . setRequired ( true )
173
+ . setAutocomplete ( true )
174
+ ) ;
143
175
}
144
176
}
145
177
@@ -151,10 +183,14 @@ const getBpOptions = async () => {
151
183
console . error ( err ) ;
152
184
return [ ] ;
153
185
}
154
- }
155
-
156
- export const batphoneCommand = new Command ( 'bp' , 'set and send batphone messages' , [
157
- new sendBp ( "send" , "send batphone" ) ,
158
- new setBp ( "set" , "save a BP preset" ) ,
159
- new unsetBp ( "unset" , "remove BP preset" )
160
- ] )
186
+ } ;
187
+
188
+ export const batphoneCommand = new Command (
189
+ "bp" ,
190
+ "set and send batphone messages" ,
191
+ [
192
+ new sendBp ( "send" , "send batphone" ) ,
193
+ new setBp ( "set" , "save a BP preset" ) ,
194
+ new unsetBp ( "unset" , "remove BP preset" ) ,
195
+ ]
196
+ ) ;
0 commit comments