2020-08-18 19:09:21 +00:00
|
|
|
mod models;
|
2020-08-06 14:22:13 +00:00
|
|
|
mod framework;
|
2020-08-09 22:59:31 +00:00
|
|
|
mod commands;
|
2020-08-06 14:22:13 +00:00
|
|
|
|
|
|
|
use serenity::{
|
|
|
|
client::{
|
|
|
|
bridge::gateway::GatewayIntents,
|
2020-08-10 21:12:26 +00:00
|
|
|
Client,
|
2020-08-06 14:22:13 +00:00
|
|
|
},
|
|
|
|
prelude::TypeMapKey,
|
|
|
|
};
|
|
|
|
|
|
|
|
use sqlx::{
|
|
|
|
Pool,
|
|
|
|
mysql::{
|
2020-08-07 15:45:19 +00:00
|
|
|
MySqlPool,
|
2020-08-06 14:22:13 +00:00
|
|
|
MySqlConnection,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
use dotenv::dotenv;
|
|
|
|
|
|
|
|
use std::{
|
|
|
|
sync::Arc,
|
|
|
|
env,
|
|
|
|
};
|
|
|
|
|
2020-08-06 18:18:30 +00:00
|
|
|
use crate::framework::RegexFramework;
|
2020-08-09 22:59:31 +00:00
|
|
|
use crate::commands::{
|
|
|
|
info_cmds,
|
|
|
|
reminder_cmds,
|
|
|
|
todo_cmds,
|
2020-08-18 19:09:21 +00:00
|
|
|
moderation_cmds,
|
2020-08-09 22:59:31 +00:00
|
|
|
};
|
2020-08-06 14:22:13 +00:00
|
|
|
|
|
|
|
struct SQLPool;
|
|
|
|
|
|
|
|
impl TypeMapKey for SQLPool {
|
|
|
|
type Value = Pool<MySqlConnection>;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ReqwestClient;
|
|
|
|
|
|
|
|
impl TypeMapKey for ReqwestClient {
|
|
|
|
type Value = Arc<reqwest::Client>;
|
|
|
|
}
|
|
|
|
|
2020-08-07 15:45:19 +00:00
|
|
|
static THEME_COLOR: u32 = 0x8fb677;
|
2020-08-06 14:22:13 +00:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|
|
|
dotenv()?;
|
|
|
|
|
2020-08-07 00:02:01 +00:00
|
|
|
let framework = RegexFramework::new(env::var("CLIENT_ID").expect("Missing CLIENT_ID from environment").parse()?)
|
2020-08-06 14:22:13 +00:00
|
|
|
.ignore_bots(true)
|
|
|
|
.default_prefix("$")
|
2020-08-09 22:59:31 +00:00
|
|
|
.add_command("help", &info_cmds::HELP_COMMAND)
|
|
|
|
.add_command("info", &info_cmds::INFO_COMMAND)
|
|
|
|
.add_command("donate", &info_cmds::DONATE_COMMAND)
|
2020-08-17 23:18:33 +00:00
|
|
|
.add_command("todo", &todo_cmds::TODO_PARSE_COMMAND)
|
2020-08-18 19:09:21 +00:00
|
|
|
.add_command("blacklist", &moderation_cmds::BLACKLIST_COMMAND)
|
2020-08-06 14:22:13 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
let mut client = Client::new(&env::var("DISCORD_TOKEN").expect("Missing DISCORD_TOKEN from environment"))
|
|
|
|
.intents(GatewayIntents::GUILD_MESSAGES | GatewayIntents::GUILDS | GatewayIntents::DIRECT_MESSAGES)
|
|
|
|
.framework(framework)
|
2020-08-06 18:18:30 +00:00
|
|
|
.await.expect("Error occurred creating client");
|
2020-08-06 14:22:13 +00:00
|
|
|
|
2020-08-07 15:45:19 +00:00
|
|
|
{
|
|
|
|
let pool = MySqlPool::new(&env::var("DATABASE_URL").expect("Missing DATABASE_URL from environment")).await.unwrap();
|
|
|
|
|
|
|
|
let mut data = client.data.write().await;
|
|
|
|
|
|
|
|
data.insert::<SQLPool>(pool);
|
|
|
|
data.insert::<ReqwestClient>(Arc::new(reqwest::Client::new()));
|
|
|
|
}
|
|
|
|
|
2020-08-06 14:22:13 +00:00
|
|
|
client.start_autosharded().await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|