From e8b10e030c49b0e4f8167c29b19239d92cfd079b Mon Sep 17 00:00:00 2001 From: HadziqM Date: Wed, 13 Dec 2023 06:43:07 +0700 Subject: [PATCH] testing poise success --- Cargo.lock | 76 ++++++++++++++++++++++++++++++++++++++++---- test-bot/Cargo.toml | 4 +-- test-bot/src/main.rs | 22 +++++++++++-- 3 files changed, 90 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d914f0..c4b7ac0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -498,8 +498,18 @@ version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.14.4", + "darling_macro 0.14.4", +] + +[[package]] +name = "darling" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +dependencies = [ + "darling_core 0.20.3", + "darling_macro 0.20.3", ] [[package]] @@ -516,17 +526,42 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "darling_core" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.39", +] + [[package]] name = "darling_macro" version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" dependencies = [ - "darling_core", + "darling_core 0.14.4", "quote", "syn 1.0.109", ] +[[package]] +name = "darling_macro" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +dependencies = [ + "darling_core 0.20.3", + "quote", + "syn 2.0.39", +] + [[package]] name = "dashmap" version = "5.5.3" @@ -1756,24 +1791,51 @@ dependencies = [ "log", "once_cell", "parking_lot", - "poise_macros", + "poise_macros 0.5.7", "regex", "serenity 0.11.7", "tokio", ] +[[package]] +name = "poise" +version = "0.6.1-rc1" +source = "git+https://github.com/serenity-rs/poise?branch=current#3a052b1853371fcc5d0818622b8c75a00ba8ab0f" +dependencies = [ + "async-trait", + "derivative", + "futures-util", + "parking_lot", + "poise_macros 0.6.1-rc1", + "regex", + "serenity 0.12.0", + "tokio", + "tracing", +] + [[package]] name = "poise_macros" version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb516a8cf4e4ae4bd7ef5819d08c6ca408976461a9bea3ee3eec5138ac070c1" dependencies = [ - "darling", + "darling 0.14.4", "proc-macro2", "quote", "syn 1.0.109", ] +[[package]] +name = "poise_macros" +version = "0.6.1-rc1" +source = "git+https://github.com/serenity-rs/poise?branch=current#3a052b1853371fcc5d0818622b8c75a00ba8ab0f" +dependencies = [ + "darling 0.20.3", + "proc-macro2", + "quote", + "syn 2.0.39", +] + [[package]] name = "powerfmt" version = "0.2.0" @@ -1833,7 +1895,7 @@ dependencies = [ "image", "imageproc", "lazy_static", - "poise", + "poise 0.5.7", "rand 0.8.5", "reqwest", "rusttype", @@ -2828,7 +2890,7 @@ name = "test-bot" version = "0.1.0" dependencies = [ "dotenv", - "poise", + "poise 0.6.1-rc1", "serenity 0.12.0", "tokio", ] diff --git a/test-bot/Cargo.toml b/test-bot/Cargo.toml index e9060af..d2c2af5 100644 --- a/test-bot/Cargo.toml +++ b/test-bot/Cargo.toml @@ -7,6 +7,6 @@ edition = "2021" [dependencies] dotenv = "0.15.0" -poise = { version = "0.5.7", features = ["time", "collector"] } -serenity = { version = "0.12.0", features = ["client", "gateway", "rustls_backend", "model", "collector"] } +poise = { git = "https://github.com/serenity-rs/poise", branch = "current", features = [ "collector"] } +serenity = { version = "0.12.0", features = ["client", "gateway", "rustls_backend", "model", "collector", "framework"] } tokio = { version = "1.35.0", features = ["full"] } diff --git a/test-bot/src/main.rs b/test-bot/src/main.rs index 5bce0bf..ca367de 100644 --- a/test-bot/src/main.rs +++ b/test-bot/src/main.rs @@ -1,7 +1,9 @@ #![allow(unused)] +use std::collections::HashMap; + use dotenv::{dotenv,var}; -use poise::{serenity_prelude as serenity, CreateReply}; -use ::serenity::futures::future::ok; +use poise::{serenity_prelude as seren, CreateReply}; +use ::serenity::futures::{future::ok, lock::Mutex}; struct Data; @@ -24,7 +26,7 @@ async fn on_error(err:poise::FrameworkError<'_,Data,Error>) { poise::FrameworkError::Setup { error, .. } => { panic!("failed to setup with err messages {error:?}") } - poise::FrameworkError::Command { error, ctx } => { + poise::FrameworkError::Command { error, ctx, .. } => { ctx.say("this can be error").await; } error => { @@ -40,10 +42,24 @@ async fn main() { dotenv(); let token = var("TOKEN") .expect("cant find token in .env"); + let intents = seren::GatewayIntents::non_privileged() | seren::GatewayIntents::MESSAGE_CONTENT; let opt = poise::FrameworkOptions { commands:vec![ping(),error()], on_error: |err| Box::pin(on_error(err)), ..Default::default() }; + let framework = poise::Framework::builder() + .setup(move |ctx, _ready, framework| { + Box::pin(async move { + println!("Logged in as {}", _ready.user.name); + poise::builtins::register_globally(ctx, &framework.options().commands).await?; + Ok(Data {}) + }) + }) + .options(opt) + .build(); + + let client = seren::client::ClientBuilder::new(token, intents).framework(framework).await; + client.unwrap().start().await.unwrap(); }