1- use crate :: state_machine:: { CharacterSet , StateMachine } ;
1+ use crate :: {
2+ api,
3+ state_machine:: { CharacterSet , StateMachine } ,
4+ } ;
25use reqwest:: blocking:: Client as HttpClient ;
36use serenity:: { model:: channel:: Message , prelude:: Context } ;
47use std:: { collections:: HashMap , sync:: Arc } ;
@@ -145,8 +148,8 @@ impl Commands {
145148 handler : impl Fn ( Args ) -> Result < ( ) > + Send + Sync + ' static ,
146149 guard : GuardFn ,
147150 ) {
148- info ! ( "Adding command ?help {}" , & base_cmd) ;
149151 let base_cmd = & cmd[ 1 ..] ;
152+ info ! ( "Adding command ?help {}" , & base_cmd) ;
150153 let mut state = 0 ;
151154
152155 self . menu . as_mut ( ) . map ( |menu| {
@@ -173,6 +176,7 @@ impl Commands {
173176 let message = & msg. content ;
174177 if !msg. is_own ( & cx) && message. starts_with ( PREFIX ) {
175178 self . state_machine . process ( message) . map ( |matched| {
179+ info ! ( "Processing command: {}" , message) ;
176180 let args = Args {
177181 http : & self . client ,
178182 cx : & cx,
@@ -182,12 +186,19 @@ impl Commands {
182186 info ! ( "Checking permissions" ) ;
183187 match matched. handler . authorize ( & args) {
184188 Ok ( true ) => {
185- info ! ( "Executing command {}" , message ) ;
189+ info ! ( "Executing command" ) ;
186190 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) ;
188200 }
189201 }
190- Ok ( false ) => { }
191202 Err ( e) => error ! ( "{}" , e) ,
192203 }
193204 } ) ;
0 commit comments