@@ -25,95 +25,46 @@ function removeExpiredInactivity() {
2525 writeFileSync ( "data/inactivity.json" , JSON . stringify ( inactivity , null , 2 ) ) ;
2626}
2727
28- /** @param {import("discord.js").ModalSubmitInteraction } interaction **/
29- async function handleInactivitySubmit ( interaction ) {
30- const linkedData = readFileSync ( "data/linked.json" ) ;
31- if ( ! linkedData ) {
32- throw new HypixelDiscordChatBridgeError ( "The linked data file does not exist. Please contact an administrator." ) ;
33- }
34-
35- const linked = JSON . parse ( linkedData . toString ( ) ) ;
36- if ( ! linked ) {
37- throw new HypixelDiscordChatBridgeError ( "The linked data file is malformed. Please contact an administrator." ) ;
38- }
39-
40- const uuid = Object . entries ( linked ) . find ( ( [ , value ] ) => value === interaction . user . id ) ?. [ 0 ] ;
41- if ( ! uuid ) {
42- throw new HypixelDiscordChatBridgeError ( "You are not linked to a Minecraft account." ) ;
43- }
44- const username = await getUsername ( uuid ) ;
45-
46- const inactivityData = readFileSync ( "data/inactivity.json" ) ;
47- if ( ! inactivityData ) {
48- throw new HypixelDiscordChatBridgeError ( "The inactivity data file does not exist. Please contact an administrator." ) ;
49- }
50-
51- const inactivity = JSON . parse ( inactivityData ) ;
52- if ( ! inactivity ) {
53- throw new HypixelDiscordChatBridgeError ( "The inactivity data file is malformed. Please contact an administrator." ) ;
54- }
55-
56- if ( inactivity [ uuid ] ) {
57- const embed = new Embed ( )
58- . setTitle ( "Inactivity Failed" )
59- . setDescription ( `You are already inactive until <t:${ inactivity [ uuid ] . expire } :F> (<t:${ inactivity [ uuid ] . expire } :R>)` )
60- . setFooter ( {
61- text : `by @.kathund | /help [command] for more information` ,
62- iconURL : "https://i.imgur.com/uUuZx2E.png"
63- } ) ;
64- return await interaction . followUp ( { embeds : [ embed ] } ) ;
65- }
66-
67- const time = Math . floor ( ms ( interaction . fields . getTextInputValue ( "inactivityTime" ) ) / 1000 ) ;
68- if ( isNaN ( time ) ) throw new HypixelDiscordChatBridgeError ( "Please input a valid time" ) ;
69-
70- if ( time > config . verification . inactivity . maxInactivityTime * 86400 ) {
71- throw new HypixelDiscordChatBridgeError (
72- `You can only request inactivity for ${ config . verification . inactivity . maxInactivityTime } day(s) or less. Please contact an administrator if you need more time.`
73- ) ;
74- }
75-
76- const reason = interaction . fields . getTextInputValue ( "inactivityReason" ) || "None" ;
77- const expire = Math . floor ( Date . now ( ) / 1000 ) + time ;
78- const date = Math . floor ( new Date ( ) . getTime ( ) / 1000 ) ;
79- if ( date > expire ) throw new HypixelDiscordChatBridgeError ( "Time can't be in the past" ) ;
80- const inactivityEmbed = new Embed ( )
81- . setTitle ( "Inactivity Request" )
82- . setDescription (
83- `\`User:\` <@${ interaction . user . id } >\n\`Username:\` ${ username } \n\`Requested:\` <t:${ date } :F> (<t:${ date } :R>)\n\`Expiration:\` <t:${ expire } :F> (<t:${ expire } :R>)\n\`Reason:\` ${ reason } `
84- )
85- . setThumbnail ( `https://www.mc-heads.net/avatar/${ username } ` )
86- . setFooter ( {
87- text : `by @.kathund | /help [command] for more information` ,
88- iconURL : "https://i.imgur.com/uUuZx2E.png"
89- } ) ;
90-
91- const channel = interaction . client . channels . cache . get ( config . verification . inactivity . channel ) ;
92- if ( channel === undefined ) {
93- throw new HypixelDiscordChatBridgeError ( "Inactivity channel not found. Please contact an administrator." ) ;
94- }
95-
96- inactivity [ uuid ] = { id : interaction . user . id , reason, expire } ;
97- writeFileSync ( "data/inactivity.json" , JSON . stringify ( inactivity , null , 2 ) ) ;
98- await channel . send ( { embeds : [ inactivityEmbed ] } ) ;
99- const inactivityResponse = new SuccessEmbed ( `Inactivity request has been successfully sent to the guild staff.` ) . setFooter ( {
100- text : `by @.kathund | /help [command] for more information` ,
101- iconURL : "https://i.imgur.com/uUuZx2E.png"
102- } ) ;
103- await interaction . followUp ( { embeds : [ inactivityResponse ] , ephemeral : true } ) ;
104- }
105-
10628module . exports = {
10729 name : "inactivity" ,
10830 description : "Send an inactivity notice to the guild staff" ,
10931 inactivityCommand : true ,
11032 guildOnly : true ,
11133 linkedOnly : true ,
11234 verifiedOnly : true ,
113- handleInactivitySubmit,
11435 removeExpiredInactivity,
36+ options : [
37+ {
38+ name : "time" ,
39+ description : "The time you are inactive for. (eg 2d, 2w)" ,
40+ type : 3 ,
41+ required : true
42+ } ,
43+ {
44+ name : "reason" ,
45+ description : "The reason you are going away" ,
46+ type : 3 ,
47+ required : false
48+ }
49+ ] ,
11550
11651 execute : async ( interaction ) => {
52+ const linkedData = readFileSync ( "data/linked.json" ) ;
53+ if ( ! linkedData ) {
54+ throw new HypixelDiscordChatBridgeError ( "The linke data file does not exist. Please contact an administrator." ) ;
55+ }
56+
57+ const linked = JSON . parse ( linkedData . toString ( ) ) ;
58+ if ( ! linked ) {
59+ throw new HypixelDiscordChatBridgeError ( "The linked data file is malformed. Please contact an administrator." ) ;
60+ }
61+
62+ const uuid = Object . entries ( linked ) . find ( ( [ , value ] ) => value === interaction . user . id ) ?. [ 0 ] ;
63+ if ( ! uuid ) {
64+ throw new HypixelDiscordChatBridgeError ( "You are not linked to a Minecraft account." ) ;
65+ }
66+ const username = await getUsername ( uuid ) ;
67+
11768 const inactivityData = readFileSync ( "data/inactivity.json" ) ;
11869 if ( ! inactivityData ) {
11970 throw new HypixelDiscordChatBridgeError ( "The inactivity data file does not exist. Please contact an administrator." ) ;
@@ -124,37 +75,53 @@ module.exports = {
12475 throw new HypixelDiscordChatBridgeError ( "The inactivity data file is malformed. Please contact an administrator." ) ;
12576 }
12677
127- if ( inactivity [ interaction . user . id ] ) {
78+ if ( inactivity [ uuid ] ) {
12879 const embed = new Embed ( )
12980 . setTitle ( "Inactivity Failed" )
130- . setDescription ( `You are already inactive until <t:${ inactivity [ interaction . user . id ] . expire } :F> (<t:${ inactivity [ interaction . user . id ] . expire } :R>)` )
81+ . setDescription ( `You are already inactive until <t:${ inactivity [ uuid ] . expire } :F> (<t:${ inactivity [ uuid ] . expire } :R>)` )
13182 . setFooter ( {
13283 text : `by @.kathund | /help [command] for more information` ,
13384 iconURL : "https://i.imgur.com/uUuZx2E.png"
13485 } ) ;
135- return await interaction . reply ( { embeds : [ embed ] } ) ;
86+ return await interaction . followUp ( { embeds : [ embed ] } ) ;
13687 }
13788
138- const time = new TextInputBuilder ( )
139- . setCustomId ( "inactivityTime" )
140- . setLabel ( "How long are you gonna be inactive for?" )
141- . setStyle ( TextInputStyle . Paragraph )
142- . setMinLength ( 1 )
143- . setMaxLength ( 16 )
144- . setPlaceholder ( "1d = 1 day, 1w = 1 week. Please format like this or you wont set your inactivity!" ) ;
145-
146- const reason = new TextInputBuilder ( )
147- . setCustomId ( "inactivityReason" )
148- . setLabel ( "Why are you going to be offline (optional)?" )
149- . setStyle ( TextInputStyle . Paragraph )
150- . setMaxLength ( 512 )
151- . setRequired ( false ) ;
152-
153- const modal = new ModalBuilder ( )
154- . setCustomId ( "inactivityForm" )
155- . setTitle ( "Inactivity Form" )
156- . addComponents ( new ActionRowBuilder ( ) . addComponents ( time ) , new ActionRowBuilder ( ) . addComponents ( reason ) ) ;
157-
158- await interaction . showModal ( modal ) ;
89+ const time = Math . floor ( ms ( interaction . options . getString ( "time" ) ) / 1000 ) ;
90+ if ( isNaN ( time ) ) throw new HypixelDiscordChatBridgeError ( "Please input a valid time" ) ;
91+
92+ if ( time > config . verification . inactivity . maxInactivityTime * 86400 ) {
93+ throw new HypixelDiscordChatBridgeError (
94+ `You can only request inactivity for ${ config . verification . inactivity . maxInactivityTime } day(s) or less. Please contact an administrator if you need more time.`
95+ ) ;
96+ }
97+
98+ const reason = interaction . options . getString ( "reason" ) || "None" ;
99+ const expire = Math . floor ( Date . now ( ) / 1000 ) + time ;
100+ const date = Math . floor ( new Date ( ) . getTime ( ) / 1000 ) ;
101+ if ( date > expire ) throw new HypixelDiscordChatBridgeError ( "Time can't be in the past" ) ;
102+ const inactivityEmbed = new Embed ( )
103+ . setTitle ( "Inactivity Request" )
104+ . setDescription (
105+ `\`User:\` <@${ interaction . user . id } >\n\`Username:\` ${ username } \n\`Requested:\` <t:${ date } :F> (<t:${ date } :R>)\n\`Expiration:\` <t:${ expire } :F> (<t:${ expire } :R>)\n\`Reason:\` ${ reason } `
106+ )
107+ . setThumbnail ( `https://www.mc-heads.net/avatar/${ username } ` )
108+ . setFooter ( {
109+ text : `by @.kathund | /help [command] for more information` ,
110+ iconURL : "https://i.imgur.com/uUuZx2E.png"
111+ } ) ;
112+
113+ const channel = interaction . client . channels . cache . get ( config . verification . inactivity . channel ) ;
114+ if ( channel === undefined ) {
115+ throw new HypixelDiscordChatBridgeError ( "Inactivity channel not found. Please contact an administrator." ) ;
116+ }
117+
118+ inactivity [ uuid ] = { id : interaction . user . id , reason, expire } ;
119+ writeFileSync ( "data/inactivity.json" , JSON . stringify ( inactivity , null , 2 ) ) ;
120+ await channel . send ( { embeds : [ inactivityEmbed ] } ) ;
121+ const inactivityResponse = new SuccessEmbed ( `Inactivity request has been successfully sent to the guild staff.` ) . setFooter ( {
122+ text : `by @.kathund | /help [command] for more information` ,
123+ iconURL : "https://i.imgur.com/uUuZx2E.png"
124+ } ) ;
125+ await interaction . followUp ( { embeds : [ inactivityResponse ] } ) ;
159126 }
160127} ;
0 commit comments