2024-02-14 12:22:29 +00:00
|
|
|
use std::sync::atomic::AtomicUsize;
|
|
|
|
|
|
|
|
use chrono::Utc;
|
2023-07-05 09:06:04 +00:00
|
|
|
use serenity::async_trait;
|
|
|
|
use serenity::model::channel::Message;
|
|
|
|
use serenity::model::gateway::Ready;
|
|
|
|
use serenity::prelude::*;
|
2024-02-14 12:22:29 +00:00
|
|
|
use serenity::client::Context;
|
|
|
|
|
|
|
|
// use tokio_cron_scheduler::{JobScheduler, JobToRun, Job};
|
|
|
|
use tokio_schedule::{every, EveryDay, Job};
|
2023-07-07 08:55:59 +00:00
|
|
|
use util::security::dotenv_var;
|
2024-02-14 12:22:29 +00:00
|
|
|
|
|
|
|
use std::sync::Arc;
|
2023-07-05 09:06:04 +00:00
|
|
|
|
2023-07-15 09:18:08 +00:00
|
|
|
mod message_handler;
|
|
|
|
use message_handler::handle;
|
|
|
|
|
|
|
|
mod commands;
|
2023-07-07 08:55:59 +00:00
|
|
|
mod util;
|
2024-02-14 12:22:29 +00:00
|
|
|
use util::debug::send_error;
|
|
|
|
|
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) {
|
2023-07-05 09:06:04 +00:00
|
|
|
println!("{} 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-14 12:22:29 +00:00
|
|
|
|
2024-02-15 19:27:52 +00:00
|
|
|
// notice::notice_wrapper(ctx).await;
|
2024-02-14 12:22:29 +00:00
|
|
|
|
|
|
|
// let scheduler = every(1).day().at(13, 30, 0)
|
|
|
|
// .perform(|| async {
|
|
|
|
// notice::notice_wrapper(ctx.clone()).await
|
|
|
|
// }).await;
|
|
|
|
|
|
|
|
// let mut scheduler = JobScheduler::new().await;
|
|
|
|
// scheduler.
|
|
|
|
// scheduler.add(match Job::new_async("5 * * * * * *", |uuid, mut l| Box::pin( async {
|
|
|
|
// notice::notice(ctx.clone()).await;
|
|
|
|
// })) {
|
|
|
|
// Ok(_) => {}
|
|
|
|
// Err(e) => {
|
|
|
|
// send_error(ctx.http.clone(), e.to_string());
|
|
|
|
// panic!()
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// scheduler.add(Job::new(daily("22"), move || {
|
|
|
|
// notice::notice(ctx.clone())
|
|
|
|
// }));
|
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
|
|
|
}
|