@@ -79,13 +79,14 @@ function handleCommand(message, command, server, ...args) {
79
79
if ( command . notLgsm ) {
80
80
if ( command . command === 'servers' ) {
81
81
for ( const server of gameservers ) {
82
- isReachable ( server . host , server . port ) . then ( online => {
83
- var status = online ? '✔ Online' : '❌ Offline' ;
84
- message . channel . send ( `**${ server . name } ** hosted at **${ server . host } :${ server . port } **: ${ status } ` ) ;
85
- } ) ;
82
+ if ( server . access . some ( ids => message . availableIds . indexOf ( ids ) > - 1 ) ) {
83
+ isReachable ( server . host , server . port ) . then ( online => {
84
+ var status = online ? '✔ Online' : '❌ Offline' ;
85
+ message . channel . send ( `**${ server . name } ** hosted at **${ server . host } :${ server . port } **: ${ status } ` ) ;
86
+ } ) ;
87
+ }
86
88
}
87
- } else if ( command . command === 'status' ) {
88
- if ( ! server ) return ;
89
+ } else if ( command . command === 'status' && server ) {
89
90
gamedig ( server . host , server . port , embed => {
90
91
if ( embed ) {
91
92
message . channel . send ( embed ) ;
@@ -94,7 +95,7 @@ function handleCommand(message, command, server, ...args) {
94
95
}
95
96
} ) ;
96
97
97
- } else if ( command . command === 'help' ) {
98
+ } else if ( command . command === 'help' && server ) {
98
99
message . channel . send ( helpMessage ( config . discord . prefix , commands ) ) ;
99
100
} else if ( command . command === 'rcon' ) {
100
101
if ( ! server ) return ;
@@ -181,16 +182,14 @@ function handleCommand(message, command, server, ...args) {
181
182
182
183
// Listen for commands
183
184
client . on ( 'message' , message => {
184
- const availableIds = [ ] ;
185
- availableIds . push ( message . member . user . id ) ;
186
- availableIds . push ( message . channel . id ) ;
185
+ message . availableIds = [ ] ;
186
+ message . availableIds . push ( message . member . user . id ) ;
187
+ message . availableIds . push ( message . channel . id ) ;
187
188
message . member . roles . cache . array ( ) . forEach ( role => {
188
- availableIds . push ( role . id ) ;
189
+ message . availableIds . push ( role . id ) ;
189
190
} ) ;
190
191
191
- const allowedIds = [ ...config . discord . access ] ;
192
-
193
- if ( ! allowedIds . some ( ids => availableIds . indexOf ( ids ) > - 1 ) ) return ;
192
+ const allowedIds = [ ] ;
194
193
195
194
// Parse (or try to at least) the incomming message.
196
195
let args = argParse ( message . content ) ;
@@ -212,9 +211,10 @@ client.on('message', message => {
212
211
} ) ;
213
212
214
213
// Check if user/channel has access to the server
214
+ config . discord . access ? allowedIds . push ( ...config . discord . access ) : '' ;
215
215
if ( server ) {
216
216
allowedIds . push ( ...server . access ) ;
217
- if ( ! allowedIds . some ( ids => availableIds . indexOf ( ids ) > - 1 ) ) return ;
217
+ if ( ! allowedIds . some ( ids => message . availableIds . indexOf ( ids ) > - 1 ) ) return ;
218
218
}
219
219
220
220
// Pass variables to handler if command is present
0 commit comments