mirror of
https://github.com/Noratrieb/widetom.git
synced 2026-01-14 08:55:02 +01:00
restructuring
This commit is contained in:
parent
65c6f3eedc
commit
19e0ecc500
3 changed files with 122 additions and 113 deletions
112
src/commands.rs
112
src/commands.rs
|
|
@ -0,0 +1,112 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use rand::Rng;
|
||||
use serenity::client::Context;
|
||||
use serenity::framework::standard::{Args, CommandGroup, CommandResult, help_commands, HelpOptions, macros::{command, group, help}};
|
||||
use serenity::model::{channel::Message};
|
||||
use serenity::model::id::UserId;
|
||||
use serenity::utils::{content_safe, ContentSafeOptions};
|
||||
use toml::Value;
|
||||
use uwuifier::uwuify_str_sse;
|
||||
|
||||
use crate::general::{CONFIG, CONFIG_ERR, reply};
|
||||
use crate::LastMessageInChannel;
|
||||
|
||||
#[group]
|
||||
#[commands(say)]
|
||||
#[description = "General widetom commands"]
|
||||
struct General;
|
||||
|
||||
#[group]
|
||||
#[commands(uwuify, xp)]
|
||||
#[description = "meme commands"]
|
||||
struct Meme;
|
||||
|
||||
#[group]
|
||||
#[commands(shutdown)]
|
||||
#[owners_only]
|
||||
#[description = "bot admin commands"]
|
||||
struct Admin;
|
||||
|
||||
|
||||
#[command]
|
||||
#[description("say something")]
|
||||
async fn say(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
let settings = if let Some(guild_id) = msg.guild_id {
|
||||
ContentSafeOptions::default()
|
||||
.clean_channel(false)
|
||||
.display_as_member_from(guild_id)
|
||||
} else {
|
||||
ContentSafeOptions::default()
|
||||
.clean_channel(false)
|
||||
.clean_role(false)
|
||||
};
|
||||
|
||||
let content = content_safe(&ctx.cache, &args.rest(), &settings).await;
|
||||
msg.channel_id.say(&ctx.http, &content).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[description("uwuifies the arguments, or the last message in the channel if no args are supplied")]
|
||||
async fn uwuify(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
if args.is_empty() {
|
||||
let mut data = ctx.data.write().await;
|
||||
let map = data.get_mut::<LastMessageInChannel>().expect("No LastMessageInChannel in TypeMap");
|
||||
let old_message = map.get(&msg.channel_id);
|
||||
match old_message {
|
||||
Some(s) => {
|
||||
let uwu = uwuify_str_sse(s);
|
||||
msg.channel_id.say(&ctx.http, uwu).await?;
|
||||
}
|
||||
None => {
|
||||
msg.channel_id.say(&ctx.http, "Could not find last message.").await?;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let uwu = uwuify_str_sse(args.rest());
|
||||
msg.channel_id.say(&ctx.http, uwu).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[description("end tom")]
|
||||
async fn shutdown(ctx: &Context, msg: &Message, _: Args) -> CommandResult {
|
||||
reply("<:tom:811324632082415626> bye <:tom:811324632082415626>", &msg, &ctx).await;
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
|
||||
#[command]
|
||||
#[description("display a random answer from the xp support applications")]
|
||||
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\
|
||||
tom moment."]
|
||||
#[command_not_found_text = "Could not find: `{}`."]
|
||||
#[max_levenshtein_distance(3)]
|
||||
#[strikethrough_commands_tip_in_dm = ""]
|
||||
#[strikethrough_commands_tip_in_guild = ""]
|
||||
pub 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(())
|
||||
}
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
|
||||
use fancy_regex::Regex;
|
||||
use lazy_static::lazy_static;
|
||||
use serenity::client::Context;
|
||||
use serenity::framework::standard::{macros::hook};
|
||||
use serenity::model::channel::{Message, ReactionType};
|
||||
use serenity::model::id::EmojiId;
|
||||
use toml::Value;
|
||||
use fancy_regex::Regex;
|
||||
use crate::LastMessageInChannel;
|
||||
|
||||
use crate::LastMessageInChannel;
|
||||
|
||||
pub static CONFIG_ERR: &'static str = "Invalid config file";
|
||||
|
||||
|
|
|
|||
119
src/main.rs
119
src/main.rs
|
|
@ -1,26 +1,17 @@
|
|||
mod general;
|
||||
mod commands;
|
||||
|
||||
use std::collections::{HashSet, HashMap};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs;
|
||||
|
||||
use serenity::{
|
||||
async_trait,
|
||||
model::{channel::Message, gateway::Ready},
|
||||
prelude::*,
|
||||
};
|
||||
use serenity::{async_trait, model::gateway::Ready, prelude::*};
|
||||
use serenity::client::Context;
|
||||
use serenity::framework::standard::{Args, CommandGroup, CommandResult, help_commands, HelpOptions, macros::{command, group, help}};
|
||||
use serenity::framework::StandardFramework;
|
||||
use serenity::http::Http;
|
||||
use serenity::model::id::{UserId, ChannelId};
|
||||
use serenity::utils::{content_safe, ContentSafeOptions};
|
||||
use uwuifier::uwuify_str_sse;
|
||||
use lazy_static::lazy_static;
|
||||
use serenity::model::id::{ChannelId, UserId};
|
||||
|
||||
use rand::Rng;
|
||||
use toml::Value;
|
||||
use crate::general::{normal_message, CONFIG_ERR, reply, CONFIG};
|
||||
use crate::commands::{ADMIN_GROUP, GENERAL_GROUP, MEME_GROUP, MY_HELP};
|
||||
use crate::general::normal_message;
|
||||
|
||||
mod general;
|
||||
mod commands;
|
||||
|
||||
pub struct LastMessageInChannel;
|
||||
|
||||
|
|
@ -28,22 +19,6 @@ impl TypeMapKey for LastMessageInChannel {
|
|||
type Value = HashMap<ChannelId, String>;
|
||||
}
|
||||
|
||||
#[group]
|
||||
#[commands(say)]
|
||||
#[description = "General widetom commands"]
|
||||
struct General;
|
||||
|
||||
#[group]
|
||||
#[commands(uwuify, xp)]
|
||||
#[description = "meme commands"]
|
||||
struct Meme;
|
||||
|
||||
#[group]
|
||||
#[commands(shutdown)]
|
||||
#[owners_only]
|
||||
#[description = "bot admin commands"]
|
||||
struct Admin;
|
||||
|
||||
struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
|
|
@ -103,81 +78,3 @@ async fn main() {
|
|||
println!("Client error: {:?}", why);
|
||||
}
|
||||
}
|
||||
|
||||
#[command]
|
||||
async fn say(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
let settings = if let Some(guild_id) = msg.guild_id {
|
||||
ContentSafeOptions::default()
|
||||
.clean_channel(false)
|
||||
.display_as_member_from(guild_id)
|
||||
} else {
|
||||
ContentSafeOptions::default()
|
||||
.clean_channel(false)
|
||||
.clean_role(false)
|
||||
};
|
||||
|
||||
let content = content_safe(&ctx.cache, &args.rest(), &settings).await;
|
||||
msg.channel_id.say(&ctx.http, &content).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[description("uwuifies the arguments, or the last message in the channel if no args are supplied")]
|
||||
async fn uwuify(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
if args.is_empty() {
|
||||
let mut data = ctx.data.write().await;
|
||||
let map = data.get_mut::<LastMessageInChannel>().expect("No LastMessageInChannel in TypeMap");
|
||||
let old_message = map.get(&msg.channel_id);
|
||||
match old_message {
|
||||
Some(s) => {
|
||||
let uwu = uwuify_str_sse(s);
|
||||
msg.channel_id.say(&ctx.http, uwu).await?;
|
||||
}
|
||||
None => {
|
||||
msg.channel_id.say(&ctx.http, "Could not find last message.").await?;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let uwu = uwuify_str_sse(args.rest());
|
||||
msg.channel_id.say(&ctx.http, uwu).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
async fn shutdown(ctx: &Context, msg: &Message, _: Args) -> CommandResult {
|
||||
reply("<:tom:811324632082415626> bye <:tom:811324632082415626>", &msg, &ctx).await;
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
|
||||
#[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\
|
||||
tom moment."]
|
||||
#[command_not_found_text = "Could not find: `{}`."]
|
||||
#[max_levenshtein_distance(3)]
|
||||
#[strikethrough_commands_tip_in_dm = ""]
|
||||
#[strikethrough_commands_tip_in_guild = ""]
|
||||
pub 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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue