1
- use crate :: state_machine:: { CharacterSet , StateMachine } ;
1
+ use crate :: {
2
+ api,
3
+ state_machine:: { CharacterSet , StateMachine } ,
4
+ } ;
2
5
use reqwest:: blocking:: Client as HttpClient ;
3
6
use serenity:: { model:: channel:: Message , prelude:: Context } ;
4
7
use std:: { collections:: HashMap , sync:: Arc } ;
@@ -145,8 +148,8 @@ impl Commands {
145
148
handler : impl Fn ( Args ) -> Result < ( ) > + Send + Sync + ' static ,
146
149
guard : GuardFn ,
147
150
) {
148
- info ! ( "Adding command ?help {}" , & base_cmd) ;
149
151
let base_cmd = & cmd[ 1 ..] ;
152
+ info ! ( "Adding command ?help {}" , & base_cmd) ;
150
153
let mut state = 0 ;
151
154
152
155
self . menu . as_mut ( ) . map ( |menu| {
@@ -173,6 +176,7 @@ impl Commands {
173
176
let message = & msg. content ;
174
177
if !msg. is_own ( & cx) && message. starts_with ( PREFIX ) {
175
178
self . state_machine . process ( message) . map ( |matched| {
179
+ info ! ( "Processing command: {}" , message) ;
176
180
let args = Args {
177
181
http : & self . client ,
178
182
cx : & cx,
@@ -182,12 +186,19 @@ impl Commands {
182
186
info ! ( "Checking permissions" ) ;
183
187
match matched. handler . authorize ( & args) {
184
188
Ok ( true ) => {
185
- info ! ( "Executing command {}" , message ) ;
189
+ info ! ( "Executing command" ) ;
186
190
if let Err ( e) = matched. handler . call ( args) {
187
- println ! ( "{}" , e) ;
191
+ error ! ( "{}" , e) ;
192
+ }
193
+ }
194
+ Ok ( false ) => {
195
+ info ! ( "Not executing command, unauthorized" ) ;
196
+ if let Err ( e) =
197
+ api:: send_reply ( & args, "You do not have permission to run this command" )
198
+ {
199
+ error ! ( "{}" , e) ;
188
200
}
189
201
}
190
- Ok ( false ) => { }
191
202
Err ( e) => error ! ( "{}" , e) ,
192
203
}
193
204
} ) ;
0 commit comments