wOxlf/src/discord/mod.rs

60 lines
1.7 KiB
Rust

use serenity::client::Context;
use serenity::framework::standard::macros::{help, hook};
use serenity::framework::standard::{
help_commands, Args, CommandGroup, CommandResult, HelpOptions,
};
use serenity::framework::StandardFramework;
use serenity::model::channel::Message;
use serenity::model::id::UserId;
use std::collections::HashSet;
pub mod event_handler;
pub mod helper;
mod host;
mod players;
#[help]
#[individual_command_tip = "If you want more information about a specific command, just pass the command as argument."]
#[command_not_found_text = "Could not find: `{}`."]
#[max_levenshtein_distance(3)]
#[indention_prefix = "+"]
#[lacking_role = "Strike"]
#[wrong_channel = "Strike"]
async fn help(
context: &Context,
msg: &Message,
args: Args,
help_options: &'static HelpOptions,
groups: &[&'static CommandGroup],
owners: HashSet<UserId>,
) -> CommandResult {
let _ = help_commands::with_embeds(context, msg, args, help_options, groups, owners).await;
Ok(())
}
#[hook]
async fn handle_errors(
ctx: &Context,
msg: &Message,
command_name: &str,
command_result: CommandResult,
) {
match command_result {
Ok(()) => println!("Successfully processed command '{}'", command_name),
Err(err) => {
let reply_msg = format!("Command '{}' returned an error. {}", command_name, err,);
println!("{}", reply_msg);
msg.reply(&ctx.http, reply_msg).await.unwrap();
}
};
}
pub fn command_framework() -> StandardFramework {
StandardFramework::new()
.configure(|c| c.prefix('$'))
.group(&host::HOST_GROUP)
.group(&players::PLAYER_GROUP)
.help(&HELP)
.after(handle_errors)
}