feat: add !help and !source commands

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-02-10 23:32:02 -06:00
parent 509638580c
commit b6594ae083
1 changed files with 41 additions and 12 deletions

View File

@ -8,12 +8,15 @@ use log::{debug, error, info, warn};
use serenity::async_trait; use serenity::async_trait;
use serenity::client::{Client, Context, EventHandler}; use serenity::client::{Client, Context, EventHandler};
use serenity::framework::standard::{ use serenity::framework::standard::{
macros::{command, group}, help_commands,
CommandResult, StandardFramework, macros::{command, group, help},
Args, CommandGroup, CommandResult, HelpOptions, StandardFramework,
}; };
use serenity::model::channel::Message; use serenity::model::channel::Message;
use serenity::model::id::UserId;
use serenity::utils::Colour; use serenity::utils::Colour;
use std::env; use std::collections::HashSet;
use std::env::{self};
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
#[group] #[group]
@ -35,6 +38,7 @@ const BOT_SOURCE: &str = "https://git.paoda.moe/paoda/arona";
const GACHA_SOURCE: &str = "https://github.com/Paoda/bluearch-recruitment"; const GACHA_SOURCE: &str = "https://github.com/Paoda/bluearch-recruitment";
const IMG_SOURCE: &str = "https://thearchive.gg"; const IMG_SOURCE: &str = "https://thearchive.gg";
const BANNER_IMG_URL: &str = "https://static.wikia.nocookie.net/blue-archive/images/e/e0/Gacha_Banner_01.png/revision/latest/"; const BANNER_IMG_URL: &str = "https://static.wikia.nocookie.net/blue-archive/images/e/e0/Gacha_Banner_01.png/revision/latest/";
const BLUE_ARCHIVE_BLUE: Colour = Colour::from_rgb(0, 215, 251);
lazy_static! { lazy_static! {
static ref STUDENTS: Vec<Student> = serde_json::from_str(STUDENTS_JSON).unwrap(); static ref STUDENTS: Vec<Student> = serde_json::from_str(STUDENTS_JSON).unwrap();
@ -49,7 +53,8 @@ async fn main() {
let framework = StandardFramework::new() let framework = StandardFramework::new()
.configure(|c| c.prefix("!")) // set the bot's prefix to "!" .configure(|c| c.prefix("!")) // set the bot's prefix to "!"
.group(&GENERAL_GROUP) .group(&GENERAL_GROUP)
.group(&RECRUITMENTCOMMANDS_GROUP); .group(&RECRUITMENTCOMMANDS_GROUP)
.help(&MY_HELP);
debug!("Initialized the StandardFramework struct"); debug!("Initialized the StandardFramework struct");
@ -86,6 +91,7 @@ async fn main() {
} }
#[command] #[command]
#[aliases(response)]
async fn ping(ctx: &Context, msg: &Message) -> CommandResult { async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
let author_name = format!("{}#{}", msg.author.name, msg.author.discriminator); let author_name = format!("{}#{}", msg.author.name, msg.author.discriminator);
info!("Ping requested from {}", author_name); info!("Ping requested from {}", author_name);
@ -110,6 +116,7 @@ async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
} }
#[command] #[command]
#[aliases(pull)]
async fn roll(ctx: &Context, msg: &Message) -> CommandResult { async fn roll(ctx: &Context, msg: &Message) -> CommandResult {
let author_name = format!("{}#{}", msg.author.name, msg.author.discriminator); let author_name = format!("{}#{}", msg.author.name, msg.author.discriminator);
info!("{} requested a single roll", author_name); info!("{} requested a single roll", author_name);
@ -176,6 +183,7 @@ async fn banner(ctx: &Context, msg: &Message) -> CommandResult {
.image(BANNER_IMG_URL) .image(BANNER_IMG_URL)
.title(BANNER.name.clone()) .title(BANNER.name.clone())
.description(banner_eng) .description(banner_eng)
.colour(BLUE_ARCHIVE_BLUE)
}) })
}) })
.await?; .await?;
@ -184,19 +192,40 @@ async fn banner(ctx: &Context, msg: &Message) -> CommandResult {
} }
#[command] #[command]
#[aliases(github, code, dev)]
async fn source(ctx: &Context, msg: &Message) -> CommandResult { async fn source(ctx: &Context, msg: &Message) -> CommandResult {
msg.reply( let author_name = format!("{}#{}", msg.author.name, msg.author.discriminator);
ctx, info!("{} requested bot / gacha / image sources", author_name);
format!( let channel = msg.channel_id;
"Bot Source Code: {}\n Gacha Source Code: {}\n Image Source: {}",
BOT_SOURCE, GACHA_SOURCE, IMG_SOURCE channel
), .send_message(ctx, |m| {
) m.embed(|embed| {
embed
.field("Bot Source", BOT_SOURCE, false)
.field("Gacha Source", GACHA_SOURCE, false)
.field("Image Source", IMG_SOURCE, false)
.colour(BLUE_ARCHIVE_BLUE)
})
})
.await?; .await?;
Ok(()) Ok(())
} }
#[help]
async fn my_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(())
}
pub fn create_banner() -> Banner { pub fn create_banner() -> Banner {
let pool: Vec<Student> = STUDENTS let pool: Vec<Student> = STUDENTS
.iter() .iter()