[no description]
-rw-r--r--Cargo.toml11
-rw-r--r--src/lib.rs64
2 files changed, 43 insertions, 32 deletions
diff --git a/Cargo.toml b/Cargo.toml
index d346474..f70413e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,7 +7,6 @@ edition = "2021"
[dependencies]
mindus = { version = "5.0.14", default-features = false }
-phf = { version = "0.11.2", features = ["macros"] }
anyhow = { version = "1.0.93", optional = true }
tokio = { version = "1.28.2", features = [
"net",
@@ -15,18 +14,18 @@ tokio = { version = "1.28.2", features = [
"rt",
"parking_lot",
], default-features = false, optional = true }
-serenity = { version = "0.12", features = [
+serenity = { git = "https://github.com/serenity-rs/serenity", branch = "next", features = [
"builder",
- "client",
+ # "client",
"rustls_backend",
"gateway",
"model",
], default-features = false, optional = true }
-poise = { git = "https://github.com/fgardt/poise", branch = "feat/user_apps", optional = true }
+# poise = { git = "https://github.com/serenity-rs/poise", branch = "serenity-next", optional = true }
[features]
-build = ["serenity", "poise", "tokio", "anyhow"]
+build = ["serenity", "tokio", "anyhow"]
+default = []
[patch.crates-io]
-serenity = { git = "https://github.com/serenity-rs/serenity" }
mindus = { git = "https://github.com/bend-n/mindus" }
diff --git a/src/lib.rs b/src/lib.rs
index cd673cf..da57155 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -90,14 +90,12 @@ pub mod mindustry {
#[cfg(feature = "build")]
mod build {
- use std::{
- collections::HashMap,
- fs::File,
- path::PathBuf,
- sync::{Arc, OnceLock},
- };
+ use std::{collections::HashMap, fs::File, path::PathBuf, sync::Arc};
- use serenity::all::{Context, ShardManager};
+ use serenity::{
+ all::{prelude::EventHandler, Context},
+ model::event::FullEvent,
+ };
pub fn load() {
tokio::runtime::Builder::new_current_thread()
@@ -106,28 +104,42 @@ mod build {
.unwrap()
.block_on(_load())
}
-
+ struct H {}
+ impl EventHandler for H {
+ fn dispatch<'life0, 'life1, 'life2, 'async_trait>(
+ &'life0 self,
+ c: &'life1 Context,
+ _event: &'life2 FullEvent,
+ ) -> ::core::pin::Pin<
+ Box<dyn ::core::future::Future<Output = ()> + ::core::marker::Send + 'async_trait>,
+ >
+ where
+ 'life0: 'async_trait,
+ 'life1: 'async_trait,
+ 'life2: 'async_trait,
+ Self: 'async_trait,
+ {
+ Box::pin(async move {
+ match _event {
+ FullEvent::Ready { .. } => {
+ build_files(c).await;
+ c.shutdown_all();
+ }
+ _ => {}
+ }
+ })
+ }
+ }
async fn _load() {
- static SHARD_MNGR: OnceLock<Arc<ShardManager>> = OnceLock::new();
let tok = std::env::var("TOKEN")
.unwrap_or_else(|_| std::fs::read_to_string("token").expect("wher token"));
- let f = poise::Framework::builder()
- .options(poise::FrameworkOptions::default())
- .setup(|c, _ready, _: &poise::Framework<(), anyhow::Error>| {
- Box::pin(async move {
- build_files(c).await;
- ShardManager::shutdown_all(SHARD_MNGR.get().unwrap()).await;
- Ok(())
- })
- })
- .build();
-
- let mut c =
- serenity::all::ClientBuilder::new(tok, serenity::all::GatewayIntents::non_privileged())
- .framework(f)
- .await
- .unwrap();
- SHARD_MNGR.set(c.shard_manager.clone()).unwrap();
+ let mut c = serenity::Client::builder(
+ tok.parse().unwrap(),
+ serenity::all::GatewayIntents::non_privileged(),
+ )
+ .event_handler(Arc::new(H {}))
+ .await
+ .unwrap();
c.start().await.unwrap()
}