|
|
|
|
|
|
|
|
|
|
|
|
|
|
mod commands;
|
|
|
|
|
mod data_loader;
|
|
|
|
|
mod utils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use serenity::async_trait;
|
|
|
|
|
use serenity::model::channel::Message;
|
|
|
|
|
use serenity::model::gateway::Ready;
|
|
|
|
|
use serenity::prelude::*;
|
|
|
|
|
use serenity::model::prelude::*;
|
|
|
|
|
|
|
|
|
|
struct Handler;
|
|
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
|
impl EventHandler for Handler
|
|
|
|
|
{
|
|
|
|
|
// Set a handler for the `message` event - so that whenever a new message
|
|
|
|
|
// is received - the closure (or function) passed will be called.
|
|
|
|
|
//
|
|
|
|
|
// Event handlers are dispatched through a threadpool, and so multiple
|
|
|
|
|
// events can be dispatched simultaneously.
|
|
|
|
|
async fn message(&self, ctx: Context, msg: Message)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if let Some(server_id) = msg.guild_id
|
|
|
|
|
{
|
|
|
|
|
let sm_speedrun_server_id = 98929157894836224;
|
|
|
|
|
let guru_test_server_id = 483735475283165195;
|
|
|
|
|
|
|
|
|
|
if server_id == sm_speedrun_server_id || server_id == guru_test_server_id
|
|
|
|
|
{
|
|
|
|
|
if msg.content == ".role_test"
|
|
|
|
|
{
|
|
|
|
|
let test_role = RoleId(1129106677619228702 as u64);
|
|
|
|
|
if let Err(why) = server_id.edit_member(&ctx, msg.author, |m|
|
|
|
|
|
{
|
|
|
|
|
if let Some(mut member) = msg.member
|
|
|
|
|
{
|
|
|
|
|
member.roles.push(test_role);
|
|
|
|
|
return m.roles(member.roles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m
|
|
|
|
|
}).await
|
|
|
|
|
{
|
|
|
|
|
println!("Error updating roles: {:?}", why);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
let role = &server_id.roles(&ctx).await.unwrap()[&test_role];
|
|
|
|
|
if let Err(why) = msg.channel_id.say(&ctx.http, format!("{} role added!", role)).await
|
|
|
|
|
{
|
|
|
|
|
println!("Error sending message: {:?}", why);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if msg.content == ".randomizer"
|
|
|
|
|
{
|
|
|
|
|
let item = utils::get_random_item();
|
|
|
|
|
if let Err(why) = msg.channel_id.say(&ctx.http, format!("You found {}!", item)).await
|
|
|
|
|
{
|
|
|
|
|
println!("Error sending message: {:?}", why);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set a handler to be called on the `ready` event. This is called when a
|
|
|
|
|
// shard is booted, and a READY payload is sent by Discord. This payload
|
|
|
|
|
// contains data like the current user's guild Ids, current user data,
|
|
|
|
|
// private channels, and more.
|
|
|
|
|
//
|
|
|
|
|
// In this case, just print what the current user's username is.
|
|
|
|
|
async fn ready(&self, _: Context, ready: Ready) {
|
|
|
|
|
println!("{} is connected!", ready.user.name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main()
|
|
|
|
|
{
|
|
|
|
|
let token = match data_loader::load_token("secrets/test.txt")
|
|
|
|
|
{
|
|
|
|
|
Ok(t) => t,
|
|
|
|
|
Err(why) => panic!("Could not load app token: {}", why),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
println!("Connecting...");
|
|
|
|
|
|
|
|
|
|
let intents = GatewayIntents::GUILD_MESSAGES
|
|
|
|
|
| GatewayIntents::DIRECT_MESSAGES
|
|
|
|
|
| GatewayIntents::MESSAGE_CONTENT;
|
|
|
|
|
|
|
|
|
|
// Create a new instance of the Client, logging in as a bot. This will
|
|
|
|
|
// automatically prepend your bot token with "Bot ", which is a requirement
|
|
|
|
|
// by Discord for bot users.
|
|
|
|
|
let mut client = Client::builder(&token, intents).event_handler(Handler).await.expect("Err creating client");
|
|
|
|
|
|
|
|
|
|
// Finally, start a single shard, and start listening to events.
|
|
|
|
|
//
|
|
|
|
|
// Shards will automatically attempt to reconnect, and will perform
|
|
|
|
|
// exponential backoff until it reconnects.
|
|
|
|
|
if let Err(why) = client.start().await
|
|
|
|
|
{
|
|
|
|
|
println!("Client error: {:?}", why);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|