mirror of
https://github.com/Noratrieb/widetom.git
synced 2026-01-15 09:25:03 +01:00
xp command
This commit is contained in:
parent
de4403a891
commit
456584c596
5 changed files with 100 additions and 27 deletions
32
src/lib.rs
32
src/lib.rs
|
|
@ -9,34 +9,34 @@ use serenity::model::id::EmojiId;
|
|||
use toml::Value;
|
||||
use fancy_regex::Regex;
|
||||
|
||||
pub static CONFIG_ERR: &'static str = "Invalid config file";
|
||||
|
||||
lazy_static! {
|
||||
static ref REACTION_EMOTES: HashMap<String, EmojiId> = {
|
||||
let err = "Invalid config file";
|
||||
let mut m = HashMap::new();
|
||||
|
||||
pub static ref CONFIG: Value = {
|
||||
let config = fs::read_to_string("config.toml").expect("Config file not found. Add 'config.toml' to this directory");
|
||||
let value = config.parse::<Value>().expect(err);
|
||||
let emotes = value.get("emotes").expect(err);
|
||||
config.parse::<Value>().expect(CONFIG_ERR)
|
||||
};
|
||||
|
||||
for v in emotes.as_array().expect(err) {
|
||||
let name = v[0].as_str().expect(err).to_string();
|
||||
let id = EmojiId(v[1].as_integer().expect(err).clone() as u64);
|
||||
static ref REACTION_EMOTES: HashMap<String, EmojiId> = {
|
||||
let mut m = HashMap::new();
|
||||
let emotes = CONFIG.get("emotes").expect(CONFIG_ERR);
|
||||
|
||||
for v in emotes.as_array().expect(CONFIG_ERR) {
|
||||
let name = v[0].as_str().expect(CONFIG_ERR).to_string();
|
||||
let id = EmojiId(v[1].as_integer().expect(CONFIG_ERR).clone() as u64);
|
||||
m.insert(name, id);
|
||||
}
|
||||
m
|
||||
};
|
||||
|
||||
static ref RESPONSES: HashMap<String, String> = {
|
||||
let err = "Invalid config file";
|
||||
let mut m = HashMap::new();
|
||||
|
||||
let config = fs::read_to_string("config.toml").expect("Config file not found. Add 'config.toml' to this directory");
|
||||
let value = config.parse::<Value>().expect(err);
|
||||
let emotes = value.get("responses").expect(err);
|
||||
let emotes = CONFIG.get("responses").expect(CONFIG_ERR);
|
||||
|
||||
for v in emotes.as_array().expect(err) {
|
||||
let trigger = v[0].as_str().expect(err).to_string();
|
||||
let response = v[1].as_str().expect(err).to_string();
|
||||
for v in emotes.as_array().expect(CONFIG_ERR) {
|
||||
let trigger = v[0].as_str().expect(CONFIG_ERR).to_string();
|
||||
let response = v[1].as_str().expect(CONFIG_ERR).to_string();
|
||||
m.insert(trigger, response);
|
||||
}
|
||||
m
|
||||
|
|
|
|||
18
src/main.rs
18
src/main.rs
|
|
@ -13,8 +13,11 @@ use serenity::http::Http;
|
|||
use serenity::model::id::UserId;
|
||||
use serenity::utils::{content_safe, ContentSafeOptions};
|
||||
use uwuifier::uwuify_str_sse;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use widertom::{normal_message, reply};
|
||||
use widertom::{normal_message, reply, CONFIG, CONFIG_ERR};
|
||||
use rand::Rng;
|
||||
use toml::Value;
|
||||
|
||||
#[group]
|
||||
#[commands(say)]
|
||||
|
|
@ -22,7 +25,7 @@ use widertom::{normal_message, reply};
|
|||
struct General;
|
||||
|
||||
#[group]
|
||||
#[commands(uwuify)]
|
||||
#[commands(uwuify, xp)]
|
||||
#[description = "meme commands"]
|
||||
struct Meme;
|
||||
|
||||
|
|
@ -118,6 +121,17 @@ async fn shutdown(ctx: &Context, msg: &Message, _: Args) -> CommandResult {
|
|||
}
|
||||
|
||||
|
||||
#[command]
|
||||
async fn xp(ctx: &Context, msg: &Message, _: Args) -> CommandResult {
|
||||
lazy_static! {
|
||||
static ref XP_RESPONSES: &'static Vec<Value> = CONFIG.get("xp").expect(CONFIG_ERR).as_array().expect(CONFIG_ERR);
|
||||
}
|
||||
let index = rand::thread_rng().gen_range(0..XP_RESPONSES.len());
|
||||
let random_value = XP_RESPONSES[index].as_str().expect(CONFIG_ERR);
|
||||
msg.channel_id.say(&ctx.http, random_value).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[help]
|
||||
#[individual_command_tip =
|
||||
"w i d e t o m\n\n\
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue