diff --git a/Cargo.lock b/Cargo.lock index 8efe5f8..92e242e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,6 +87,15 @@ version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +dependencies = [ + "serde", +] + [[package]] name = "async-trait" version = "0.1.77" @@ -110,7 +119,7 @@ dependencies = [ "pin-project-lite", "tokio", "tokio-rustls 0.23.4", - "tungstenite", + "tungstenite 0.17.3", "webpki-roots 0.22.6", ] @@ -222,6 +231,12 @@ version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +[[package]] +name = "bytecount" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1e5f035d16fc623ae5f74981db80a439803888314e3a555fd6f04acd51a3205" + [[package]] name = "byteorder" version = "1.5.0" @@ -255,6 +270,37 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "camino" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "694c8807f2ae16faecc43dc17d74b3eb042482789fd0eb64b39a2e04e087053f" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", +] + [[package]] name = "cc" version = "1.0.83" @@ -321,6 +367,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "command_attr" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32f08c85a02e066b7b4f7dcb60eee6ae0793ef7d6452a3547d1f19665df070a9" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "const-oid" version = "0.9.6" @@ -382,6 +439,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "176dc175b78f56c0f321911d9c8eb2b77a78a4860b9c19db83835fea1a46649b" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-queue" version = "0.3.11" @@ -421,6 +487,12 @@ dependencies = [ "serde", ] +[[package]] +name = "data-encoding" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" + [[package]] name = "der" version = "0.7.8" @@ -513,6 +585,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "error-chain" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" +dependencies = [ + "version_check", +] + [[package]] name = "etcetera" version = "0.8.0" @@ -705,6 +786,15 @@ dependencies = [ "slab", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -734,6 +824,12 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "h2" version = "0.3.24" @@ -1135,6 +1231,21 @@ dependencies = [ "unicase", ] +[[package]] +name = "mini-moka" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c325dfab65f261f386debee8b0969da215b3fa0037e74c8a1234db7ba986d803" +dependencies = [ + "crossbeam-channel", + "crossbeam-utils", + "dashmap", + "skeptic", + "smallvec", + "tagptr", + "triomphe", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1495,6 +1606,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "pulldown-cmark" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b" +dependencies = [ + "bitflags 2.4.2", + "memchr", + "unicase", +] + [[package]] name = "quote" version = "1.0.35" @@ -1796,6 +1918,15 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "schannel" version = "0.1.23" @@ -1821,6 +1952,16 @@ dependencies = [ "untrusted 0.9.0", ] +[[package]] +name = "secrecy" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bd1c54ea06cfd2f6b63219704de0b9b4f72dcc2b8fdef820be6cd799780e91e" +dependencies = [ + "serde", + "zeroize", +] + [[package]] name = "security-framework" version = "2.9.2" @@ -1844,6 +1985,15 @@ dependencies = [ "libc", ] +[[package]] +name = "semver" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" +dependencies = [ + "serde", +] + [[package]] name = "serde" version = "1.0.196" @@ -1922,7 +2072,7 @@ dependencies = [ "bytes", "cfg-if", "chrono", - "command_attr", + "command_attr 0.4.2", "dashmap", "flate2", "futures", @@ -1940,7 +2090,43 @@ dependencies = [ "time", "tokio", "tracing", - "typemap_rev", + "typemap_rev 0.1.5", + "url", + "uwl", +] + +[[package]] +name = "serenity" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "385647faa24a889929028973650a4f158fb1b4272b2fcf94feb9fcc3c009e813" +dependencies = [ + "arrayvec", + "async-trait", + "base64 0.21.7", + "bitflags 2.4.2", + "bytes", + "chrono", + "command_attr 0.5.1", + "dashmap", + "flate2", + "futures", + "fxhash", + "levenshtein", + "mime_guess", + "parking_lot", + "percent-encoding", + "reqwest", + "secrecy", + "serde", + "serde_json", + "static_assertions", + "time", + "tokio", + "tokio-tungstenite", + "tracing", + "typemap_rev 0.3.0", + "typesize", "url", "uwl", ] @@ -1988,6 +2174,21 @@ dependencies = [ "rand_core", ] +[[package]] +name = "skeptic" +version = "0.13.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16d23b015676c90a0f01c197bfdc786c20342c73a0afdda9025adb0bc42940a8" +dependencies = [ + "bytecount", + "cargo_metadata", + "error-chain", + "glob", + "pulldown-cmark", + "tempfile", + "walkdir", +] + [[package]] name = "slab" version = "0.4.9" @@ -2332,6 +2533,12 @@ dependencies = [ "libc", ] +[[package]] +name = "tagptr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" + [[package]] name = "tempfile" version = "3.10.0" @@ -2489,6 +2696,21 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-tungstenite" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" +dependencies = [ + "futures-util", + "log", + "rustls 0.21.10", + "tokio", + "tokio-rustls 0.24.1", + "tungstenite 0.20.1", + "webpki-roots 0.25.4", +] + [[package]] name = "tokio-util" version = "0.7.10" @@ -2541,6 +2763,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "triomphe" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3" + [[package]] name = "try-lock" version = "0.2.5" @@ -2568,18 +2796,73 @@ dependencies = [ "webpki", ] +[[package]] +name = "tungstenite" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" +dependencies = [ + "byteorder", + "bytes", + "data-encoding", + "http", + "httparse", + "log", + "rand", + "rustls 0.21.10", + "sha1", + "thiserror", + "url", + "utf-8", +] + [[package]] name = "typemap_rev" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed5b74f0a24b5454580a79abb6994393b09adf0ab8070f15827cb666255de155" +[[package]] +name = "typemap_rev" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74b08b0c1257381af16a5c3605254d529d3e7e109f3c62befc5d168968192998" + [[package]] name = "typenum" version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "typesize" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36924509726e38224322c8c90ddfbf4317324338327b7c11b7cf8672cb786da1" +dependencies = [ + "chrono", + "dashmap", + "hashbrown 0.14.3", + "mini-moka", + "parking_lot", + "secrecy", + "serde_json", + "time", + "typesize-derive", + "url", +] + +[[package]] +name = "typesize-derive" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b122284365ba8497be951b9a21491f70c9688eb6fddc582931a0703f6a00ece" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "unicase" version = "2.7.0" @@ -2676,6 +2959,16 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "walkdir" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" @@ -3008,7 +3301,7 @@ version = "0.1.0" dependencies = [ "dotenv", "env_logger", - "serenity", + "serenity 0.12.0", "tokio", "youmubot-cf", "youmubot-core", @@ -3030,7 +3323,7 @@ dependencies = [ "regex", "reqwest", "serde", - "serenity", + "serenity 0.12.0", "tokio", "youmubot-db", "youmubot-prelude", @@ -3046,7 +3339,7 @@ dependencies = [ "futures-util", "rand", "serde", - "serenity", + "serenity 0.11.7", "static_assertions", "tokio", "youmubot-db", @@ -3061,7 +3354,7 @@ dependencies = [ "dotenv", "rustbreak", "serde", - "serenity", + "serenity 0.12.0", ] [[package]] @@ -3092,7 +3385,7 @@ dependencies = [ "rosu-v2", "serde", "serde_json", - "serenity", + "serenity 0.12.0", "time", "youmubot-db", "youmubot-db-sql", @@ -3111,7 +3404,7 @@ dependencies = [ "flume 0.10.14", "futures-util", "reqwest", - "serenity", + "serenity 0.12.0", "tokio", "youmubot-db", "youmubot-db-sql", diff --git a/youmubot-cf/Cargo.toml b/youmubot-cf/Cargo.toml index 520b589..a3a590d 100644 --- a/youmubot-cf/Cargo.toml +++ b/youmubot-cf/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" serde = { version = "1.0.137", features = ["derive"] } tokio = { version = "1.19.2", features = ["time"] } reqwest = "0.11.10" -serenity = "0.11.2" +serenity = "0.12" Inflector = "0.11.4" codeforces = "0.3.1" regex = "1.5.6" diff --git a/youmubot-db/Cargo.toml b/youmubot-db/Cargo.toml index e149c4f..95b9f74 100644 --- a/youmubot-db/Cargo.toml +++ b/youmubot-db/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -serenity = "0.11.2" +serenity = "0.12" dotenv = "0.15.0" serde = { version = "1.0.137", features = ["derive"] } chrono = "0.4.19" diff --git a/youmubot-osu/Cargo.toml b/youmubot-osu/Cargo.toml index 7ada79e..53b17fe 100644 --- a/youmubot-osu/Cargo.toml +++ b/youmubot-osu/Cargo.toml @@ -19,7 +19,7 @@ rosu-pp = "0.9.1" rosu-v2 = { git = "https://github.com/natsukagami/rosu-v2", rev = "6f6731cb2f0d235b006ab375dd94b446dde894ac" } time = "0.3" serde = { version = "1.0.137", features = ["derive"] } -serenity = "0.11.2" +serenity = "0.12" zip = "0.6.2" rand = "0.8" diff --git a/youmubot-prelude/Cargo.toml b/youmubot-prelude/Cargo.toml index f30003a..bfb85b8 100644 --- a/youmubot-prelude/Cargo.toml +++ b/youmubot-prelude/Cargo.toml @@ -19,6 +19,6 @@ flume = "0.10.13" dashmap = "5.3.4" [dependencies.serenity] -version = "0.11.2" +version = "0.12" default-features = true features = ["collector"] diff --git a/youmubot-prelude/src/announcer.rs b/youmubot-prelude/src/announcer.rs index ca3f9c3..1d6c101 100644 --- a/youmubot-prelude/src/announcer.rs +++ b/youmubot-prelude/src/announcer.rs @@ -5,22 +5,40 @@ use futures_util::{ stream::{FuturesUnordered, StreamExt}, }; use serenity::{ + client::Cache, framework::standard::{ macros::{command, group}, Args, CommandResult, }, - http::CacheHttp, + http::{CacheHttp, Http}, model::{ channel::Message, id::{ChannelId, GuildId, UserId}, }, prelude::*, utils::MessageBuilder, - CacheAndHttp, }; use std::{collections::HashMap, sync::Arc}; use youmubot_db::DB; +#[derive(Debug, Clone)] +pub struct CacheAndHttp(Arc, Arc); + +impl CacheAndHttp { + pub fn from_client(client: &Client) -> Self { + Self(client.cache.clone(), client.http.clone()) + } +} + +impl CacheHttp for CacheAndHttp { + fn cache(&self) -> Option<&Arc> { + Some(&self.0) + } + fn http(&self) -> &Http { + &*self.1 + } +} + /// A list of assigned channels for an announcer. pub(crate) type AnnouncerChannels = DB>>; @@ -39,7 +57,7 @@ pub trait Announcer: Send { /// Errors returned from this function gets ignored and logged down. async fn updates( &mut self, - c: Arc, + c: CacheAndHttp, d: AppData, channels: MemberToChannels, ) -> Result<()>; @@ -76,7 +94,7 @@ impl MemberToChannels { /// /// This struct manages the list of all Announcers, firing them in a certain interval. pub struct AnnouncerHandler { - cache_http: Arc, + cache_http: CacheAndHttp, data: AppData, announcers: HashMap<&'static str, RwLock>>, } @@ -91,7 +109,7 @@ impl AnnouncerHandler { /// Create a new instance of the handler. pub fn new(client: &serenity::Client) -> Self { Self { - cache_http: client.cache_and_http.clone(), + cache_http: CacheAndHttp(client.cache.clone(), client.http.clone()), data: client.data.clone(), announcers: HashMap::new(), } @@ -135,7 +153,7 @@ impl AnnouncerHandler { /// Run the announcing sequence on a certain announcer. async fn announce( data: AppData, - cache_http: Arc, + cache_http: CacheAndHttp, key: &'static str, announcer: &'_ RwLock>, ) -> Result<()> { @@ -243,7 +261,11 @@ pub async fn register_announcer(ctx: &Context, m: &Message, mut args: Args) -> C .await?; return Ok(()); } - let guild = m.guild(ctx).expect("Guild-only command"); + let guild = m + .guild_id + .expect("Guild-only command") + .to_partial_guild(&ctx) + .await?; let channel = m.channel_id.to_channel(&ctx).await?; AnnouncerChannels::open(&data) .borrow_mut()? @@ -258,7 +280,7 @@ pub async fn register_announcer(ctx: &Context, m: &Message, mut args: Args) -> C .push(" has been activated for server ") .push_bold_safe(&guild.name) .push(" on channel ") - .push_bold_safe(channel) + .push_bold_safe(channel.mention().to_string()) .build(), ) .await?; @@ -286,7 +308,11 @@ pub async fn remove_announcer(ctx: &Context, m: &Message, mut args: Args) -> Com .await?; return Ok(()); } - let guild = m.guild(ctx).expect("Guild-only command"); + let guild = m + .guild_id + .expect("Guild-only command") + .to_partial_guild(&ctx) + .await?; AnnouncerChannels::open(&data) .borrow_mut()? .entry(key.clone()) diff --git a/youmubot-prelude/src/pagination.rs b/youmubot-prelude/src/pagination.rs index 9b6a9bf..949a28d 100644 --- a/youmubot-prelude/src/pagination.rs +++ b/youmubot-prelude/src/pagination.rs @@ -1,7 +1,8 @@ use crate::{Context, Result}; -use futures_util::{future::Future, StreamExt}; +use futures_util::{future::Future, StreamExt as _}; use serenity::{ - collector::ReactionAction, + builder::CreateMessage, + collector, model::{ channel::{Message, Reaction, ReactionType}, id::ChannelId, @@ -35,7 +36,7 @@ pub trait Paginate: Send + Sized { page: u8, ctx: &Context, message: &mut Message, - reaction: &ReactionAction, + reaction: &Reaction, ) -> Result> { handle_pagination_reaction(page, self, ctx, message, reaction) .await @@ -91,7 +92,10 @@ pub async fn paginate( timeout: std::time::Duration, ) -> Result<()> { let message = channel - .send_message(&ctx, |e| e.content("Youmu is loading the first page...")) + .send_message( + &ctx, + CreateMessage::new().content("Youmu is loading the first page..."), + ) .await?; paginate_with_first_message(pager, ctx, message, timeout).await } @@ -137,7 +141,18 @@ async fn paginate_with_first_message( rs }; // Build a reaction collector - let mut reaction_collector = message.await_reactions(ctx).removed(true).build(); + let mut reaction_collector = { + // message.await_reactions(ctx).removed(true).build(); + let message_id = message.id; + collector::collect(&ctx.shard, move |event| { + match event { + serenity::all::Event::ReactionAdd(r) => Some(r.reaction.clone()), + serenity::all::Event::ReactionRemove(r) => Some(r.reaction.clone()), + _ => None, + } + .filter(|r| r.message_id == message_id) + }) + }; let mut page = 0; // Loop the handler function. @@ -201,11 +216,8 @@ pub async fn handle_pagination_reaction( pager: &mut impl Paginate, ctx: &Context, message: &mut Message, - reaction: &ReactionAction, + reaction: &Reaction, ) -> Result { - let reaction = match reaction { - ReactionAction::Added(v) | ReactionAction::Removed(v) => v, - }; let pages = pager.len(); let fast = pages.map(|v| v / 10).unwrap_or(5).max(5) as u8; match &reaction.emoji { diff --git a/youmubot/Cargo.toml b/youmubot/Cargo.toml index 9161a09..b48d8b1 100644 --- a/youmubot/Cargo.toml +++ b/youmubot/Cargo.toml @@ -12,7 +12,7 @@ osu = ["youmubot-osu"] codeforces = ["youmubot-cf"] [dependencies] -serenity = "0.11.2" +serenity = "0.12" tokio = { version = "1.19.2", features = ["rt-multi-thread"] } dotenv = "0.15.0" env_logger = "0.9.0"