2023-07-05 09:06:04 +00:00
|
|
|
use serenity::async_trait;
|
2024-02-16 20:54:07 +00:00
|
|
|
use serenity::prelude::GatewayIntents;
|
2024-02-14 12:22:29 +00:00
|
|
|
use serenity::client::Context;
|
2024-02-16 20:54:07 +00:00
|
|
|
use serenity::model::gateway::Ready;
|
|
|
|
use serenity::all::{Message, EventHandler};
|
|
|
|
use serenity::Client;
|
2024-02-14 12:22:29 +00:00
|
|
|
|
2024-02-16 20:54:07 +00:00
|
|
|
use tokio_cron_scheduler::{JobScheduler, Job};
|
2023-07-07 08:55:59 +00:00
|
|
|
use util::security::dotenv_var;
|
2024-02-14 12:22:29 +00:00
|
|
|
|
2023-07-15 09:18:08 +00:00
|
|
|
mod message_handler;
|
|
|
|
use message_handler::handle;
|
|
|
|
|
2024-02-16 20:54:07 +00:00
|
|
|
use std::future::Future;
|
|
|
|
use std::pin::Pin;
|
|
|
|
|
2023-07-15 09:18:08 +00:00
|
|
|
mod commands;
|
2023-07-07 08:55:59 +00:00
|
|
|
mod util;
|
2024-02-14 12:22:29 +00:00
|
|
|
|
2023-09-23 19:15:19 +00:00
|
|
|
mod other;
|
2024-02-14 12:22:29 +00:00
|
|
|
use other::notice;
|
2023-07-05 09:06:04 +00:00
|
|
|
|
|
|
|
struct Handler;
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl EventHandler for Handler {
|
|
|
|
async fn message(&self, ctx: Context, msg: Message) {
|
2023-07-15 09:18:08 +00:00
|
|
|
handle(ctx, msg).await;
|
2023-07-05 09:06:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-07 08:55:59 +00:00
|
|
|
async fn ready(&self, ctx: Context, ready: Ready) {
|
2024-02-16 21:31:12 +00:00
|
|
|
println!("{} v0.2 is connected!", ready.user.name);
|
2024-02-14 12:22:29 +00:00
|
|
|
|
2024-02-15 19:27:52 +00:00
|
|
|
#[cfg(feature="RELEASE")] {
|
|
|
|
use util::debug::hello;
|
|
|
|
hello(ctx.http.clone()).await;
|
|
|
|
}
|
2024-02-18 11:14:02 +00:00
|
|
|
|
2024-02-16 20:54:07 +00:00
|
|
|
let sched = JobScheduler::new().await.unwrap();
|
|
|
|
|
|
|
|
let job_closure = move |_, _| -> Pin<Box<dyn Future<Output = ()> + Send>> {
|
|
|
|
let ctx_clone = ctx.clone();
|
|
|
|
Box::pin( async move {
|
|
|
|
notice::notice_wrapper(ctx_clone).await;
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
sched.add(Job::new_async("0 0 13 * * *", job_closure).expect("Cron job not set up correctly")).await.unwrap();
|
|
|
|
sched.start().await.unwrap();
|
2023-07-05 09:06:04 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-07 11:44:07 +00:00
|
|
|
|
2023-07-05 09:06:04 +00:00
|
|
|
#[tokio::main]
|
2023-07-07 10:16:25 +00:00
|
|
|
async fn main() -> anyhow::Result<()> {
|
|
|
|
use anyhow::Context;
|
2024-02-15 19:27:52 +00:00
|
|
|
|
2024-02-14 12:22:29 +00:00
|
|
|
let token_str = "TOKEN";
|
|
|
|
|
|
|
|
#[cfg(feature="DEBUG")]
|
|
|
|
let token_str = "DEBUGTOKEN";
|
|
|
|
|
2024-02-15 19:27:52 +00:00
|
|
|
let token = dotenv_var(token_str).context("TOKEN not found in env")?;
|
2024-02-14 12:22:29 +00:00
|
|
|
|
2023-07-14 14:41:16 +00:00
|
|
|
let intents = GatewayIntents::GUILD_MESSAGES | GatewayIntents::MESSAGE_CONTENT;
|
|
|
|
|
2023-07-07 08:55:59 +00:00
|
|
|
let mut client = Client::builder(&token, intents)
|
2023-07-07 10:16:25 +00:00
|
|
|
.event_handler(Handler)
|
|
|
|
.await
|
|
|
|
.context("Failed to build client")?;
|
2023-07-14 14:41:16 +00:00
|
|
|
|
2023-07-07 10:16:25 +00:00
|
|
|
client.start().await?;
|
|
|
|
Ok(())
|
2023-07-05 09:06:04 +00:00
|
|
|
}
|