1- import { ApplicationCommandOptionChoiceData , AutocompleteInteraction , CacheType , CommandInteraction } from "discord.js" ;
1+ import {
2+ ApplicationCommandOptionChoiceData ,
3+ AutocompleteInteraction ,
4+ CacheType ,
5+ CommandInteraction ,
6+ } from "discord.js" ;
27import { Command } from "../../shared/command/command" ;
38import { Subcommand } from "../../shared/command/subcommand" ;
49import { getTextChannel } from "../.." ;
5- import { batphoneChannelId , raiderRoleId } from "../../config" ;
10+ import { batphoneChannelId , raiderRoleId , wakeupChannelId } from "../../config" ;
611import { authorizeByMemberRoles } from "../../shared/command/util" ;
712import { officerRoleId , modRoleId , knightRoleId } from "../../config" ;
813import { kStringMaxLength } from "buffer" ;
914import { error } from "console" ;
1015import { redisClient } from "../../redis/client" ;
1116import { redis } from "googleapis/build/src/apis/redis" ;
1217import { isObject } from "lodash" ;
18+ import { container } from "tsyringe" ;
19+ import { WakeupService } from "../wakeup/wakeup.service" ;
1320
1421class sendBp extends Subcommand {
1522 public async execute ( interaction : CommandInteraction < CacheType > ) {
16-
1723 // authorize
18- authorizeByMemberRoles ( [
19- officerRoleId , modRoleId , knightRoleId
20- ] , interaction ) ;
24+ authorizeByMemberRoles (
25+ [ officerRoleId , modRoleId , knightRoleId ] ,
26+ interaction
27+ ) ;
2128
2229 const message = this . getOption ( "message" , interaction ) ?. value ;
2330 const bpChannel = await getTextChannel ( batphoneChannelId ) ;
24- if ( typeof ( message ) === "string" ) {
25-
31+ if ( typeof message === "string" ) {
2632 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+ }
3044 } else {
3145 interaction . editReply ( "Failed to post batphone." ) ;
3246 }
33-
3447 }
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+ > {
3654 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+ } ) ) ;
4160 return opts ;
4261 }
4362 return [ ] ;
4463 }
4564
4665 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+ ) ;
5473 }
5574}
5675
5776class setBp extends Subcommand {
5877 public async execute ( interaction : CommandInteraction < CacheType > ) {
59-
6078 // authorize
61- authorizeByMemberRoles ( [
62- officerRoleId , modRoleId , knightRoleId
63- ] , interaction ) ;
79+ authorizeByMemberRoles (
80+ [ officerRoleId , modRoleId , knightRoleId ] ,
81+ interaction
82+ ) ;
6483
6584 const message = this . getOption ( "message" , interaction ) ?. value ;
6685 try {
67- if ( typeof ( message ) === "string" ) {
86+ if ( typeof message === "string" ) {
6887 let key = this . getOption ( "key" , interaction ) ?. value ;
69- if ( ! key ) {
88+ if ( ! key ) {
7089 key = message . split ( " " ) [ 0 ] . toLowerCase ( ) ;
7190 }
7291 await redisClient . hSet ( "bp" , String ( key ) , message ) ;
73- interaction . editReply ( "Saved preset message: " + message )
92+ interaction . editReply ( "Saved preset message: " + message ) ;
7493 } else {
7594 throw error ;
7695 }
77- } catch ( err ) {
96+ } catch ( err ) {
7897 console . error ( err ) ;
7998 interaction . editReply ( "Failed save batphone message." ) ;
8099 }
81-
82100 }
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+ > {
84107 return [ ] ;
85108 }
86109
87110 public get command ( ) {
88111 return super . command
89112 . addStringOption ( ( o ) =>
90- o . setName ( "message" )
113+ o
114+ . setName ( "message" )
91115 . setDescription ( "BP Message" )
92116 . setRequired ( true )
93117 . setAutocomplete ( false )
94- ) . addStringOption ( ( o ) =>
95- o . setName ( "key" )
118+ )
119+ . addStringOption ( ( o ) =>
120+ o
121+ . setName ( "key" )
96122 . setDescription ( "Key (optional" )
97123 . setRequired ( false )
98124 . setAutocomplete ( false )
99- )
125+ ) ;
100126 }
101127}
102128
103129class unsetBp extends Subcommand {
104130 public async execute ( interaction : CommandInteraction < CacheType > ) {
105-
106131 // authorize
107- authorizeByMemberRoles ( [
108- officerRoleId , modRoleId , knightRoleId
109- ] , interaction ) ;
132+ authorizeByMemberRoles (
133+ [ officerRoleId , modRoleId , knightRoleId ] ,
134+ interaction
135+ ) ;
110136
111137 const key = this . getOption ( "message" , interaction ) ?. value ;
112138 try {
113- if ( typeof ( key ) === "string" ) {
139+ if ( typeof key === "string" ) {
114140 await redisClient . hDel ( "bp" , String ( key ) ) ;
115- interaction . editReply ( "Removed preset message: " + key )
141+ interaction . editReply ( "Removed preset message: " + key ) ;
116142 } else {
117143 throw error ;
118144 }
119- } catch ( err ) {
145+ } catch ( err ) {
120146 console . error ( err ) ;
121147 interaction . editReply ( "Failed save batphone message." ) ;
122148 }
123149 }
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+ > {
125156 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+ } ) ) ;
130162 return opts ;
131163 }
132164 return [ ] ;
133165 }
134166
135167 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+ ) ;
143175 }
144176}
145177
@@ -151,10 +183,14 @@ const getBpOptions = async () => {
151183 console . error ( err ) ;
152184 return [ ] ;
153185 }
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