@@ -47,8 +47,7 @@ exports.getPrefix = async (serverID) => {
47
47
exports . getAllCommands = ( ) => registeredCommands ;
48
48
49
49
const getAllowedRoles = ( serverPermissions , userRoles , plugin ) => {
50
- // eslint-disable-next-line radix
51
- const roles = userRoles . flatMap ( x => parseInt ( x . id ) ) ;
50
+ const roles = userRoles . flatMap ( x => parseInt ( x . id , 10 ) ) ;
52
51
const allowedRoles = [ ] ;
53
52
for ( let x = 0 ; x < serverPermissions . length ; x += 1 ) {
54
53
const perm = serverPermissions [ x ] ;
@@ -59,21 +58,34 @@ const getAllowedRoles = (serverPermissions, userRoles, plugin) => {
59
58
return allowedRoles ;
60
59
} ;
61
60
61
+ const isAdmin = async ( serverID , userRoles ) => {
62
+ const roles = userRoles . flatMap ( x => parseInt ( x . id , 10 ) ) ;
63
+ const server = await Server . findOne ( { serverID } ) . exec ( ) ;
64
+ const { adminRole } = await Configuration . findOne ( {
65
+ server,
66
+ } ) . select ( {
67
+ adminRole : 1 ,
68
+ _id : 0 ,
69
+ } ) . exec ( ) ;
70
+ return roles . includes ( adminRole ) ;
71
+ } ;
72
+
62
73
client . on ( 'message' , async ( msg ) => {
63
74
const message = msg . content ;
64
75
if ( ! msg . guild && msg . author . id !== client . user . id ) return msg . reply ( 'I do not work in DMs' ) ;
65
76
if ( msg . author . id === client . user . id ) return false ;
66
77
const serverPrefix = await this . getPrefix ( msg . guild . id ) ;
67
78
const serverPermissions = await permissions . getServerPermissions ( msg . guild . id ) ;
79
+ const userRoles = msg . member . roles . array ( ) ;
80
+ const adminState = await isAdmin ( msg . guild . id , userRoles ) ;
68
81
for ( let i = 0 ; i < registeredCommands . length ; i += 1 ) {
69
82
const command = registeredCommands [ i ] ;
70
83
const regex = new RegExp ( `\\${ serverPrefix } ${ command . compiled } ` ) ;
71
84
const match = message . match ( regex ) ? message . match ( regex ) : [ ] ;
72
85
const pluginState = loader . commandState ( command ) ;
73
86
const plugin = loader . fromCommand ( command ) ;
74
- const userRoles = msg . member . roles . array ( ) ;
75
87
const allowedRoles = getAllowedRoles ( serverPermissions , userRoles , plugin ) ;
76
- if ( pluginState && ( `${ serverPrefix } ${ command . compiled } ` === message || match [ 1 ] ) && ( plugin . ignorePermissions || allowedRoles . length >= 1 ) ) {
88
+ if ( pluginState && ( `${ serverPrefix } ${ command . compiled } ` === message || match [ 1 ] ) && ( plugin . ignorePermissions || adminState || allowedRoles . length >= 1 ) ) {
77
89
return command . response ( msg , match ) ;
78
90
}
79
91
}
0 commit comments