diff options
author | NatrixAeria <upezu@student.kit.edu> | 2020-09-18 19:05:50 +0200 |
---|---|---|
committer | NatrixAeria <upezu@student.kit.edu> | 2020-09-18 19:05:50 +0200 |
commit | 2cafc2afbc27910db23c0b007d3bc2c93b8e8bce (patch) | |
tree | 4efbdbf88d2ec5ddf921a0715fd19c9c29440cd9 | |
parent | 0fc260a7f4ba61d0677da20cf44cc728c661469e (diff) |
Add the help command
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | src/config.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 55 |
4 files changed, 58 insertions, 6 deletions
@@ -507,6 +507,7 @@ name = "lovefinderrz" version = "0.1.0" dependencies = [ "serenity", + "tokio", ] [[package]] @@ -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 <https://git.kobert.dev/lovefinderrz.git/>!"; 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"); } |