You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
7.4 KiB
Rust

use serenity::prelude::*;
use serenity::model::prelude::*;
use serenity::model::channel::Message;
use crate::{utils, Owner};
// AUTHORIZED USER IDS:
const BEL_WORK_USER_ID: u64 = 474259726427750420;
// CHANNEL IDS
const SM_TEST_CHANNEL_ID: u64 = 280548893135994880;
const SM_INFO_CHANNEL_ID: u64 = 270628925300801546;
// COLOR ROLE IDS
const ROLE_ID_RED: u64 = 279338933748236289;
const ROLE_ID_GREEN: u64 = 279338847102566400;
const ROLE_ID_BLUE: u64 = 279338904526782464;
const ROLE_ID_YELLOW: u64 = 279339011921805312;
const ROLE_ID_PINK: u64 = 279339051444862976;
const ROLE_ID_ORANGE: u64 = 279339077382438912;
const ROLE_ID_PURPLE: u64 = 284310454908747787;
// RACE ROLE IDS
const ROLE_ID_ANY_PERCENT: u64 = 313710041641254912;
const ROLE_ID_HUNDO: u64 = 313710205986668546;
const ROLE_ID_RANDOMIZER: u64 = 313710276685856768;
const ROLE_ID_BINGO: u64 = 621128130681110546;
const ROLE_ID_MISC: u64 = 313710318486421505;
const ROLE_ID_PUZZLE: u64 = 405792833820164102;
pub async fn parse_command(ctx: Context, msg: Message, server_id: GuildId)
{
if handle_meme(ctx.clone(), msg.clone()).await
{
return;
}
let command_lower = msg.content.to_lowercase();
let mut command_iter = command_lower.split_whitespace();
let command_start = command_iter.next();
let data = ctx.data.read().await;
let owner_id = match data.get::<Owner>()
{
Some(o) => o.load(std::sync::atomic::Ordering::Relaxed),
None => { utils::Logger::log_error(ctx.clone(), &format!("Couldn't get bot owner id")).await; return; }
};
if (UserId::from(owner_id) == msg.author.id || UserId::from(BEL_WORK_USER_ID) == msg.author.id) && command_start == Some(".dotestmsg")
{
if let Some(msg) = utils::send_msg(ctx.clone(), ChannelId::from(SM_TEST_CHANNEL_ID), "Test message!").await
{
println!("Test message id is: {:#?}", msg.id)
}
else
{
println!("Failed to get test message id");
}
}
if command_start == Some(".randomizer")
{
let item = utils::get_random_item();
utils::send_msg(ctx.clone(), msg.channel_id, &format!("You found {}!", item)).await;
return;
}
if command_start == Some(".colors") || command_start == Some(".color")
{
utils::send_msg(ctx.clone(), msg.channel_id, "Valid colors are: green blue red purple pink yellow orange").await;
return;
}
if command_start == Some(".setcolor")
{
if let Some(arg) = command_iter.next()
{
match arg
{
// TODO: add color roles
"red" => { set_color(ctx.clone(), msg, RoleId(ROLE_ID_RED), server_id).await; return; }
"green" => { set_color(ctx.clone(), msg, RoleId(ROLE_ID_GREEN), server_id).await; return; }
"blue" => { set_color(ctx.clone(), msg, RoleId(ROLE_ID_BLUE), server_id).await; return; }
"yellow" => { set_color(ctx.clone(), msg, RoleId(ROLE_ID_YELLOW), server_id).await; return; }
"orange" => { set_color(ctx.clone(), msg, RoleId(ROLE_ID_ORANGE), server_id).await; return; }
"pink" => { set_color(ctx.clone(), msg, RoleId(ROLE_ID_PINK), server_id).await; return; }
"purple" => { set_color(ctx.clone(), msg, RoleId(ROLE_ID_PURPLE), server_id).await; return; }
_ => utils::Logger::log_error(ctx.clone(), &format!("unknown .color argument: {}", arg)).await
};
}
}
}
pub async fn handle_reaction_add(ctx: Context, reaction: Reaction)
{
if reaction.channel_id == ChannelId::from(SM_TEST_CHANNEL_ID)
&& reaction.message_id == MessageId::from(1245086205381574790 as u64)
{
if reaction.emoji.unicode_eq("👍")
{
let user_name = reaction.user(ctx.clone()).await.unwrap().name;
utils::add_role(ctx.clone(), reaction.user_id.expect("UserId was None in handle_reaction_add"),
RoleId::from(ROLE_ID_ANY_PERCENT),
reaction.guild_id.expect("GuildId was None in handle_reaction_add"))
.await.unwrap();
utils::Logger::log_message(ctx.clone(), &format!("Added any% role for {}", user_name)).await;
}
else
{
utils::Logger::log_message(ctx.clone(), "Reaction was not the thumbs up emoji").await;
}
}
}
pub async fn handle_reaction_remove(ctx: Context, reaction: Reaction)
{
if reaction.channel_id == ChannelId::from(SM_TEST_CHANNEL_ID)
&& reaction.message_id == MessageId::from(1245086205381574790 as u64)
{
if reaction.emoji.unicode_eq("👍")
{
utils::remove_role(ctx, reaction.user_id.expect("UserId was None in handle_reaction_remove"),
RoleId::from(ROLE_ID_ANY_PERCENT),
reaction.guild_id.expect("GuildId was None in handle_reaction_remove"))
.await.unwrap();
}
else
{
utils::Logger::log_message(ctx, "Reaction was not the thumbs up emoji").await;
}
}
}
///////////////////// HELPERS
async fn set_color(ctx: Context, msg: Message, role_id: RoleId, server_id: GuildId)
{
// Unset all color roles
let colors = [ROLE_ID_RED, ROLE_ID_GREEN, ROLE_ID_BLUE, ROLE_ID_YELLOW, ROLE_ID_PINK, ROLE_ID_ORANGE, ROLE_ID_PURPLE];
for color in colors
{
if let Err(why) = utils::remove_role(ctx.clone(), msg.author.clone().into(), RoleId(color), server_id).await
{
utils::send_msg(ctx.clone(), msg.channel_id, &format!("Could not set color")).await;
utils::Logger::log_error(ctx.clone(), &format!("set_color failed - could not remove other color roles: {}", why)).await;
return;
}
}
// Set requested color role
match utils::add_role(ctx.clone(), msg.author.into(), role_id, server_id).await
{
Ok(role) =>
{
utils::send_msg(ctx.clone(), msg.channel_id, &format!("Added role: {}", role.name)).await;
return;
}
Err(why) =>
{
utils::send_msg(ctx.clone(), msg.channel_id, &format!("Could not set color role")).await;
utils::Logger::log_error(ctx.clone(), &format!("set_color: Failed to set color role: {}", why)).await;
return;
}
}
}
async fn handle_meme(ctx: Context, msg: Message) -> bool
{
let command_lower = msg.content.to_lowercase();
match command_lower.as_str()
{
".godwin" => { utils::send_msg(ctx, msg.channel_id, "https://imgur.com/1MVRQsc").await; return true }
".beer" => { utils::send_msg(ctx, msg.channel_id, "https://www.youtube.com/watch?v=IZVHBMCdXIw").await; return true }
".beeer" => { utils::send_msg(ctx, msg.channel_id, "https://youtu.be/nPtMHSYtPc4").await; return true }
".ivan" => { utils::send_msg(ctx, msg.channel_id, "http://i.imgur.com/0sjR5lE.jpg").await; return true }
".hotdog" => { utils::send_msg(ctx, msg.channel_id, "https://www.youtube.com/watch?v=ZXVhOPiM4mk").await; return true }
".edu" => { utils::send_msg(ctx, msg.channel_id, "<:ThisIsFine:243880310859759616> http://imgur.com/1STAzsl").await; return true }
".gari" => { utils::send_msg(ctx, msg.channel_id, "http://i.imgur.com/EYAti0a.jpg").await; return true }
".deerforce" => { utils::send_msg(ctx, msg.channel_id, "https://i.imgur.com/PSxFfku.png").await; return true }
_ => { return false; }
}
}