Skip to content

Commit 089759b

Browse files
committed
general improvements
1 parent a456ba5 commit 089759b

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/commands.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::state_machine::{CharacterSet, StateMachine};
1+
use crate::{
2+
api,
3+
state_machine::{CharacterSet, StateMachine},
4+
};
25
use reqwest::blocking::Client as HttpClient;
36
use serenity::{model::channel::Message, prelude::Context};
47
use 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
});

src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fn app() -> Result<()> {
147147

148148
let menu = cmds.menu();
149149
cmds.add("?help", move |args: Args| {
150-
let output = main_menu(&args, menu.as_ref().unwrap())?;
150+
let output = main_menu(&args, menu.as_ref().unwrap());
151151
api::send_reply(&args, &format!("```{}```", &output))?;
152152
Ok(())
153153
});
@@ -163,7 +163,7 @@ fn app() -> Result<()> {
163163
Ok(())
164164
}
165165

166-
fn main_menu(args: &Args, commands: &HashMap<&str, (&str, GuardFn)>) -> Result<String> {
166+
fn main_menu(args: &Args, commands: &HashMap<&str, (&str, GuardFn)>) -> String {
167167
let mut menu = format!("Commands:\n");
168168

169169
menu = commands
@@ -177,7 +177,7 @@ fn main_menu(args: &Args, commands: &HashMap<&str, (&str, GuardFn)>) -> Result<S
177177

178178
menu += &format!("\t{help:<12}This menu\n", help = "?help");
179179
menu += "\nType ?help command for more info on a command.";
180-
Ok(menu)
180+
menu
181181
}
182182

183183
fn main() {

0 commit comments

Comments
 (0)