mirror of
https://github.com/Noratrieb/widetom.git
synced 2026-01-15 01:15:03 +01:00
wide tom
This commit is contained in:
parent
cef31e1b84
commit
1d1ea1e5a2
6 changed files with 422 additions and 24 deletions
53
src/lib.rs
Normal file
53
src/lib.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
|
||||
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;
|
||||
|
||||
lazy_static! {
|
||||
static ref REACTION_EMOTES: HashMap<String, EmojiId> = {
|
||||
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("emotes").expect(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);
|
||||
m.insert(name, id);
|
||||
}
|
||||
m
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#[hook]
|
||||
pub async fn normal_message(ctx: &Context, msg: &Message) {
|
||||
if msg.content == "tom" {
|
||||
reply(" <:tom:811324632082415626>", &msg, &ctx).await;
|
||||
}
|
||||
|
||||
for (name, id) in REACTION_EMOTES.iter() {
|
||||
if msg.content.contains(name) {
|
||||
if let Err(why) = msg.react(&ctx.http, ReactionType::Custom {
|
||||
animated: false,
|
||||
id: *id,
|
||||
name: Some(name.to_string()),
|
||||
}).await {
|
||||
println!("Error reacting: {}", why);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn reply(txt: &str, msg: &Message, ctx: &Context) {
|
||||
if let Err(why) = msg.channel_id.say(&ctx.http, txt).await {
|
||||
println!("Error sending message: {:?}", why);
|
||||
}
|
||||
}
|
||||
133
src/main.rs
133
src/main.rs
|
|
@ -1,3 +1,132 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
|
||||
use serenity::{
|
||||
async_trait,
|
||||
model::{channel::Message, 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;
|
||||
use serenity::utils::{content_safe, ContentSafeOptions};
|
||||
use uwuifier::uwuify_str_sse;
|
||||
|
||||
use widertom::normal_message;
|
||||
|
||||
#[group]
|
||||
#[commands(say)]
|
||||
#[description = "General widetom commands"]
|
||||
struct General;
|
||||
|
||||
#[group]
|
||||
#[commands(uwuify)]
|
||||
#[description = "meme commands"]
|
||||
struct Meme;
|
||||
|
||||
|
||||
struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
async fn ready(&self, _: Context, ready: Ready) {
|
||||
println!("{} is connected!", ready.user.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
||||
let token = fs::read_to_string("bot_token")
|
||||
.expect("Expected bot token in file 'bot_token'");
|
||||
|
||||
let http = Http::new_with_token(&token);
|
||||
|
||||
let (owners, bot_id) = match http.get_current_application_info().await {
|
||||
Ok(info) => {
|
||||
let mut owners = HashSet::new();
|
||||
if let Some(team) = info.team {
|
||||
owners.insert(team.owner_user_id);
|
||||
} else {
|
||||
owners.insert(info.owner.id);
|
||||
}
|
||||
match http.get_current_user().await {
|
||||
Ok(bot_id) => (owners, bot_id.id),
|
||||
Err(why) => panic!("Could not access the bot id: {:?}", why),
|
||||
}
|
||||
}
|
||||
Err(why) => panic!("Could not access application info: {:?}", why),
|
||||
};
|
||||
|
||||
let framework = StandardFramework::new()
|
||||
.configure(|c| c
|
||||
.with_whitespace(false)
|
||||
.on_mention(Some(bot_id))
|
||||
.prefix("<:tom:811324632082415626> ")
|
||||
.delimiter(" ")
|
||||
.owners(owners)
|
||||
)
|
||||
.normal_message(normal_message)
|
||||
.help(&MY_HELP)
|
||||
.group(&GENERAL_GROUP)
|
||||
.group(&MEME_GROUP);
|
||||
|
||||
let mut client = Client::builder(&token)
|
||||
.event_handler(Handler)
|
||||
.framework(framework)
|
||||
.await
|
||||
.expect("Err creating client");
|
||||
|
||||
if let Err(why) = client.start().await {
|
||||
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]
|
||||
async fn uwuify(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
let uwu = uwuify_str_sse(args.rest());
|
||||
msg.channel_id.say(&ctx.http, uwu).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