From 2cafc2afbc27910db23c0b007d3bc2c93b8e8bce Mon Sep 17 00:00:00 2001 From: NatrixAeria Date: Fri, 18 Sep 2020 19:05:50 +0200 Subject: Add the help command --- Cargo.lock | 1 + Cargo.toml | 4 ++++ src/config.rs | 4 ++++ src/main.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bacc6ed..b20c8a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -507,6 +507,7 @@ name = "lovefinderrz" version = "0.1.0" dependencies = [ "serenity", + "tokio", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index f260119..5053f9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,7 @@ edition = "2018" [dependencies] serenity = "0.9.0-rc.1" + +[dependencies.tokio] +version = "0.2.22" +features = ["rt-core", "macros"] diff --git a/src/config.rs b/src/config.rs index 1fde118..bb05d99 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1 +1,5 @@ use serenity::framework::standard::CommandGroup; + +pub const TOKEN_ENV: &str = "DISCORD_TOKEN"; +pub const HELP_TEXT: &str = "Cupido is a discord bot to get to know your people. +Cupido is open-source !"; diff --git a/src/main.rs b/src/main.rs index 86fa40d..79371f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,53 @@ +mod config; + use serenity::framework::StandardFramework; +use serenity::Client; + +fn configure(conf: &mut serenity::framework::standard::Configuration) { + conf.prefix("!<3").case_insensitivity(true); +} + +struct Handler; + +mod commands { + use serenity::client::Context; + use serenity::framework::standard::{macros::*, CommandResult}; + use serenity::model::channel::Message; + #[group] + #[description = "Commands for the cupido bot"] + #[default_command(help)] + #[commands(help)] + struct Group; + + #[command] + #[aliases("hepl", "?", "h")] + async fn help(ctx: &Context, msg: &Message) -> CommandResult { + msg.reply(ctx, crate::config::HELP_TEXT).await?; + Ok(()) + } +} + +impl serenity::client::EventHandler for Handler {} + +#[tokio::main] +async fn main() { + println!("crate framework"); + + let framework = StandardFramework::new() + .configure(|c| { + configure(c); + c + }) + .group(&commands::GROUP_GROUP); -fn configure(conf: &mut serenity::framework::standard::Configuration) {} + let token = std::env::var(config::TOKEN_ENV).expect("missing token"); + println!("crate a new client with token: \"{}\"", token); + let mut client = Client::new(token) + .framework(framework) + .event_handler(Handler) + .await + .expect("Error creating client"); -fn main() { - let framework = StandardFramework::new().configure(|c| { - configure(c); - c - }); + println!("starting the client"); + client.start().await.expect("client error"); } -- cgit v1.2.3-54-g00ecf