started adding commands

This commit is contained in:
jude 2020-08-09 23:59:31 +01:00
parent 6de542264a
commit 27c62e6ac2
6 changed files with 69 additions and 5 deletions

54
src/commands/info_cmds.rs Normal file
View File

@ -0,0 +1,54 @@
use regex_command_attr::command;
use serenity::{
client::Context,
model::{
channel::{
Message,
},
},
framework::standard::{
Args, CommandResult,
},
};
use crate::THEME_COLOR;
#[command]
async fn help(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
msg.channel_id.send_message(ctx, |m| m
.embed(|e| e
.title("Help")
.description("Help Description")
.color(THEME_COLOR)
)
).await?;
Ok(())
}
#[command]
async fn info(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
msg.channel_id.send_message(ctx, |m| m
.embed(|e| e
.title("Info")
.description("Info Description")
.color(THEME_COLOR)
)
).await?;
Ok(())
}
#[command]
async fn donate(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
msg.channel_id.send_message(ctx, |m| m
.embed(|e| e
.title("Donate")
.description("Donate Description")
.color(THEME_COLOR)
)
).await?;
Ok(())
}

3
src/commands/mod.rs Normal file
View File

@ -0,0 +1,3 @@
pub mod info_cmds;
pub mod reminder_cmds;
pub mod todo_cmds;

View File

View File

View File

@ -36,7 +36,6 @@ use std::{
};
use crate::SQLPool;
use serenity::model::id::RoleId;
#[derive(Debug)]
pub enum PermissionLevel {
@ -162,8 +161,8 @@ impl RegexFramework {
self
}
pub fn add_command(mut self, name: String, command: &'static Command) -> Self {
self.commands.insert(name, command);
pub fn add_command(mut self, name: &str, command: &'static Command) -> Self {
self.commands.insert(name.to_string(), command);
self
}
@ -269,7 +268,7 @@ impl Framework for RegexFramework {
}
Err(sqlx::Error::RowNotFound) => {
sqlx::query!("INSERT INTO guilds (guild, name) VALUES (?, ?)", guild.id.as_u64(), guild.name)
let _ = sqlx::query!("INSERT INTO guilds (guild, name) VALUES (?, ?)", guild.id.as_u64(), guild.name)
.execute(&pool)
.await;

View File

@ -1,4 +1,5 @@
mod framework;
mod commands;
use serenity::{
client::{
@ -34,6 +35,11 @@ use std::{
};
use crate::framework::RegexFramework;
use crate::commands::{
info_cmds,
reminder_cmds,
todo_cmds,
};
struct SQLPool;
@ -56,7 +62,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let framework = RegexFramework::new(env::var("CLIENT_ID").expect("Missing CLIENT_ID from environment").parse()?)
.ignore_bots(true)
.default_prefix("$")
.add_command("look".to_string(), &LOOK_COMMAND)
.add_command("help", &info_cmds::HELP_COMMAND)
.add_command("info", &info_cmds::INFO_COMMAND)
.add_command("donate", &info_cmds::DONATE_COMMAND)
.build();
let mut client = Client::new(&env::var("DISCORD_TOKEN").expect("Missing DISCORD_TOKEN from environment"))