@@ -3,8 +3,26 @@ const { loadConfigVar, loadChnlMap } = require('./../../backend/loadvar.js');
33const fetch = require ( 'node-fetch' ) ;
44const fs = require ( 'node:fs' ) ;
55const path = require ( 'path' ) ;
6+ const { create } = require ( 'node:domain' ) ;
67const configPath = path . resolve ( __dirname , '../../config.json' ) ;
78
9+ async function createChannel ( guild , name , categoryid ) {
10+ const discordChannelName = name ;
11+
12+ let discordChannel = guild . channels . cache . find (
13+ ( channel ) => channel . type === 0 && channel . name === discordChannelName
14+ ) ;
15+
16+ if ( ! discordChannel ) {
17+ discordChannel = await guild . channels . create ( {
18+ name : discordChannelName ,
19+ type : 0 ,
20+ parent : categoryid ,
21+ } ) ;
22+ console . log ( `Channel created: ${ discordChannelName } , ID: ${ discordChannel . id } ` ) ;
23+ }
24+ return discordChannel . id
25+ }
826
927module . exports = {
1028 category : 'mud' ,
@@ -55,6 +73,18 @@ module.exports = {
5573 . setRequired ( true )
5674 )
5775 ) ,
76+ /* Not Fully Implemented Yet
77+ .addSubcommand(subcommand =>
78+ subcommand
79+ .setName('ping-detection')
80+ .setDescription(`Will ping @everone when one of your ingame users get @'ed inside a message`)
81+ .addBooleanOption((option) =>
82+ option
83+ .setname('value')
84+ .setDescription('value')
85+ .setRequired(true)
86+ )
87+ )*/
5888 async execute ( interaction ) {
5989 const option = interaction . options . getSubcommand ( ) ;
6090
@@ -78,7 +108,6 @@ module.exports = {
78108 if ( result . ok == true ) {
79109 const chatToken = result . chat_token ;
80110
81- const configPath = './config.json' ;
82111 let config = { } ;
83112
84113 if ( fs . existsSync ( configPath ) ) {
@@ -87,6 +116,7 @@ module.exports = {
87116 }
88117
89118 config . mudtoken = chatToken ;
119+ config . mudtokendate =
90120
91121 fs . writeFileSync ( configPath , JSON . stringify ( config , null , 4 ) ) ;
92122 console . log ( 'New mudtoken has been set:' , chatToken )
@@ -144,25 +174,14 @@ module.exports = {
144174 }
145175
146176 const channelMapping = { } ;
147-
177+ channelMapping [ '.sanitize' ] = await createChannel ( guild , 'hmcc-search' , chatCategory . id )
148178 for ( const user of Object . keys ( users ) ) {
149- const discordChannelName = user ;
150-
151- let discordChannel = guild . channels . cache . find (
152- ( channel ) => channel . type === 0 && channel . name === discordChannelName
153- ) ;
154-
155- if ( ! discordChannel ) {
156- discordChannel = await guild . channels . create ( {
157- name : discordChannelName ,
158- type : 0 ,
159- parent : chatCategory . id ,
160- } ) ;
161- console . log ( `Channel created: ${ discordChannelName } , ID: ${ discordChannel . id } ` ) ;
162- }
163-
164- channelMapping [ user ] = discordChannel . id ;
179+
180+ let chnlid = await createChannel ( guild , user , chatCategory . id )
181+ channelMapping [ user ] = chnlid ;
165182 }
183+
184+
166185
167186 const mappingsPath = path . resolve ( __dirname , '../../channelMappings.json' ) ;
168187
@@ -187,7 +206,7 @@ module.exports = {
187206 const pullHistory = interaction . options . getBoolean ( 'pull' ) ;
188207
189208 try {
190- const config = JSON . parse ( fs . readFileSync ( configPath , 'utf-8' ) ) ;
209+ let config = JSON . parse ( fs . readFileSync ( configPath , 'utf-8' ) ) ;
191210
192211 if ( ! Array . isArray ( config . pullusers ) ) {
193212 config . pullusers = [ ] ;
@@ -215,7 +234,7 @@ module.exports = {
215234 if ( option === 'color' ) {
216235 const cmdcolorval = interaction . options . getString ( 'value' ) ;
217236 if ( cmdcolorval . match ( / ^ [ a - z A - Z 0 - 9 ] $ / ) || cmdcolorval == "reset" ) {
218- const config = JSON . parse ( fs . readFileSync ( configPath , 'utf-8' ) ) ;
237+ let config = JSON . parse ( fs . readFileSync ( configPath , 'utf-8' ) ) ;
219238
220239 if ( cmdcolorval == "reset" ) {
221240 config . setcolor = null ;
@@ -230,5 +249,18 @@ module.exports = {
230249 await interaction . reply ( { content : 'Invalid color value. Please use a single alphanumeric character or "reset"' , flags : MessageFlags . Ephemeral } ) ;
231250 }
232251 }
252+ if ( option === 'ping-detection' ) {
253+ const value = interaction . options . getBoolean ( 'value' ) ;
254+ try {
255+ let config = JSON . parse ( fs . readFileSync ( configPath , 'utf-8' ) ) ;
256+ config . pd = value
257+ fs . writeFileSync ( configPath , JSON . stringify ( config , null , 4 ) , 'utf-8' ) ;
258+
259+ await interaction . reply ( { content : `Successfully updated setting. Ping Detection: **${ value ? 'Enabled' : 'Disabled' } **` , flags : MessageFlags . Ephemeral } ) ;
260+ } catch ( error ) {
261+ console . error ( error ) ;
262+ await interaction . reply ( { content : 'An error occurred while setting this option. Check console for details.' , flags : MessageFlags . Ephemeral } ) ;
263+ }
264+ }
233265 }
234266} ;
0 commit comments