1
1
import { ApplicationCommandOptionType , CommandInteraction } from 'discord.js' ;
2
2
import { Discord , Guard , Slash , SlashOption } from 'discordx' ;
3
3
4
- import { devicePermission , wake } from '../deviceManager' ;
4
+ import { devicePermission , wake , sendPing , ActionResult } from '../deviceManager' ;
5
5
import { RateLimit , TIME_UNIT } from '@discordx/utilities' ;
6
6
import { deviceAutoComplete , rateLimitMessage } from '../utils' ;
7
7
import { commandLocalisation , commandDescription } from '../utils' ;
8
8
import { getTfunc } from '../i18n' ;
9
9
import config from '../config.json' ;
10
+ import logger from '../logger' ;
10
11
11
12
const requiredPermissions : devicePermission = {
12
13
wol : true
13
14
} ;
14
15
16
+ const requiredPingPermissions : devicePermission = {
17
+ ping : true
18
+ } ;
19
+
15
20
@Discord ( )
16
21
@Guard (
17
22
RateLimit ( TIME_UNIT . seconds , 30 , {
@@ -41,8 +46,9 @@ export class WakeOnLan {
41
46
searchText : string ,
42
47
interaction : CommandInteraction
43
48
) : Promise < void > {
49
+ const isEphemeral = interaction . guild ? true : false ;
44
50
// Command Handler
45
- await interaction . deferReply ( { ephemeral : interaction . guild ? true : false } ) ;
51
+ await interaction . deferReply ( { ephemeral : isEphemeral } ) ;
46
52
47
53
const t = getTfunc ( interaction . locale ) ;
48
54
@@ -54,5 +60,36 @@ export class WakeOnLan {
54
60
mac : result . mac
55
61
} )
56
62
) ;
63
+
64
+ if ( config . checkPingAfterWake ) {
65
+ // Wait 30 seconds, ping check
66
+ setTimeout ( async ( ) => {
67
+ const pingResult = await sendPing ( searchText , interaction , requiredPingPermissions ) ;
68
+ if ( typeof pingResult !== 'object' ) {
69
+ if ( pingResult === ActionResult . PermissionDenied ) {
70
+ // Permission denied
71
+ return ;
72
+ }
73
+ interaction . followUp ( {
74
+ content : t ( `common:command.errorTitle` , {
75
+ error : t ( `commands:ping.error` , { context : pingResult } )
76
+ } ) ,
77
+ ephemeral : isEphemeral
78
+ } ) ;
79
+ } else {
80
+ logger . debug ( `${ pingResult . alive } _false` ) ;
81
+ interaction . followUp ( {
82
+ content : t ( `commands:ping.deviceResponse` , {
83
+ context : `${ pingResult . alive } _false` ,
84
+ avg : pingResult . avg ,
85
+ max : pingResult . max ,
86
+ min : pingResult . min ,
87
+ packetLoss : pingResult . packetLoss
88
+ } ) ,
89
+ ephemeral : isEphemeral
90
+ } ) ;
91
+ }
92
+ } , config . waitTimeAfterWake * 1000 ) ;
93
+ }
57
94
}
58
95
}
0 commit comments