From a7fa722518a6ff02d2045d3447a1a5e9afb565d4 Mon Sep 17 00:00:00 2001 From: jude Date: Sun, 25 Oct 2020 11:19:21 +0000 Subject: [PATCH] use serenity from my repo. other minor improvements --- Cargo.lock | 77 ++++++++++++++++++++++++++++-------------------- Cargo.toml | 4 +-- README.md | 2 ++ src/framework.rs | 34 +++++---------------- src/main.rs | 6 ++-- 5 files changed, 59 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8793b14..960de71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,18 +64,6 @@ dependencies = [ "syn", ] -[[package]] -name = "async-tls" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7e7fbc0843fc5ad3d5ca889c5b2bea9130984d34cd0e62db57ab70c2529a8e3" -dependencies = [ - "futures", - "rustls", - "webpki", - "webpki-roots 0.20.0", -] - [[package]] name = "async-trait" version = "0.1.41" @@ -89,17 +77,18 @@ dependencies = [ [[package]] name = "async-tungstenite" -version = "0.8.0" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5c45a0dd44b7e6533ac4e7acc38ead1a3b39885f5bbb738140d30ea528abc7c" +checksum = "9ce503a5cb1e7450af7d211b86b84807791b251f335b2f43f1e26b85a416f315" dependencies = [ - "async-tls", "futures-io", "futures-util", "log", - "pin-project", + "pin-project 1.0.1", "tokio", + "tokio-rustls", "tungstenite", + "webpki-roots 0.20.0", ] [[package]] @@ -125,6 +114,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + [[package]] name = "bigdecimal" version = "0.1.2" @@ -234,9 +229,8 @@ dependencies = [ [[package]] name = "command_attr" -version = "0.3.0-rc.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6745770e89e5e4583424362f15f91c8bb0ef54387d209af30e0446d08909ae7d" +version = "0.3.0-rc.3" +source = "git+https://github.com/jellywx/serenity?branch=jellywx-member_permissions#6d96e6837bbbc09127bd728b80daccce538daf09" dependencies = [ "proc-macro2", "quote", @@ -497,7 +491,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project", + "pin-project 0.4.27", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -638,7 +632,7 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project", + "pin-project 0.4.27", "socket2", "tokio", "tower-service", @@ -1021,7 +1015,16 @@ version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" dependencies = [ - "pin-project-internal", + "pin-project-internal 0.4.27", +] + +[[package]] +name = "pin-project" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee41d838744f60d959d7074e3afb6b35c7456d0f61cad38a24e35e6553f73841" +dependencies = [ + "pin-project-internal 1.0.1", ] [[package]] @@ -1035,6 +1038,17 @@ dependencies = [ "syn", ] +[[package]] +name = "pin-project-internal" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81a4ffa594b66bff340084d4081df649a7dc049ac8d7fc458d8e628bfbbb2f86" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pin-project-lite" version = "0.1.10" @@ -1165,7 +1179,7 @@ dependencies = [ [[package]] name = "reminder_rs" -version = "1.0.0-rc.9" +version = "1.0.0-rc.10" dependencies = [ "Inflector", "async-trait", @@ -1204,7 +1218,7 @@ version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9eaa17ac5d7b838b7503d118fa16ad88f440498bf9ffe5424e621f93190d61e" dependencies = [ - "base64", + "base64 0.12.3", "bytes", "encoding_rs", "futures-core", @@ -1259,7 +1273,7 @@ version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d1126dcf58e93cee7d098dbda643b5f92ed724f1f6a63007c1116eed6700c81" dependencies = [ - "base64", + "base64 0.12.3", "log", "ring", "sct", @@ -1360,13 +1374,12 @@ dependencies = [ [[package]] name = "serenity" -version = "0.9.0-rc.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d179c8684cccfc95898c4a97ba3cb8787dd8db5e3f8cb645efd129ddb1a7dd7f" +version = "0.9.0-rc.3" +source = "git+https://github.com/jellywx/serenity?branch=jellywx-member_permissions#6d96e6837bbbc09127bd728b80daccce538daf09" dependencies = [ "async-trait", "async-tungstenite", - "base64", + "base64 0.13.0", "bitflags", "bytes", "chrono", @@ -1485,7 +1498,7 @@ checksum = "88ac5a436f941c42eac509471a730df5c3c58e1450e68cd39afedbd948206273" dependencies = [ "async-native-tls", "async-stream", - "base64", + "base64 0.12.3", "bigdecimal", "bitflags", "byteorder", @@ -1731,7 +1744,7 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c" dependencies = [ - "pin-project", + "pin-project 0.4.27", "tracing", ] @@ -1747,7 +1760,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0308d80d86700c5878b9ef6321f020f29b1bb9d5ff3cab25e75e23f3a492a23" dependencies = [ - "base64", + "base64 0.12.3", "byteorder", "bytes", "http", diff --git a/Cargo.toml b/Cargo.toml index c0cb5a9..7a73961 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "reminder_rs" -version = "1.0.0-rc.9" +version = "1.0.0-rc.10" authors = ["jellywx "] edition = "2018" [dependencies] -serenity = { version = "0.9.0-rc.2", features = ["collector", "rustls_backend"] } +serenity = { git = "https://github.com/jellywx/serenity", branch = "jellywx-member_permissions", features = ["collector", "rustls_backend"] } dotenv = "0.15" tokio = { version = "0.2", features = ["process"] } reqwest = { version = "0.10", features = ["rustls-tls"] } diff --git a/README.md b/README.md index 5e640ec..72f35f9 100644 --- a/README.md +++ b/README.md @@ -35,3 +35,5 @@ __Other Variables__ * `THEME_COLOR` - default `8fb677`. Specifies the hex value of the color to use on info message embeds * `WEBHOOK_AVATAR` - default `None`, accepts the path to an image file to be used as the avatar when creating webhooks. **IMPORTANT: image file must be 128x128 or smaller in size** * `CASE_INSENSITIVE` - default `1`, if `1`, commands will be treated with case insensitivity (so both `$help` and `$HELP` will work) +* `SHARD_COUNT` - default `None`, accepts the number of shards that are being ran +* `SHARD_RANGE` - default `None`, if `SHARD_COUNT` is specified, specifies what range of shards to start on this process diff --git a/src/framework.rs b/src/framework.rs index 85c643b..1313a03 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -22,7 +22,6 @@ use std::{collections::HashMap, fmt}; use crate::models::{GuildData, UserData}; use crate::{models::ChannelData, SQLPool}; -use serenity::futures::TryFutureExt; type CommandFn = for<'fut> fn(&'fut Context, &'fut Message, String) -> BoxFuture<'fut, CommandResult>; @@ -47,34 +46,15 @@ impl Command { if self.required_perms == PermissionLevel::Unrestricted { true } else { - if member - .permissions(&ctx) - .map_ok_or_else( - |_| false, - |perms| { - perms.manage_guild() - || (self.required_perms == PermissionLevel::Managed - && perms.manage_messages()) - }, - ) - .await + let permissions = guild.member_permissions(&ctx, &member.user).await.unwrap(); + + if permissions.manage_guild() + || (permissions.manage_messages() + && self.required_perms == PermissionLevel::Managed) { return true; } - for role_id in &member.roles { - let role = role_id.to_role_cached(&ctx).await; - - if let Some(cached_role) = role { - if cached_role.permissions.manage_guild() - || (self.required_perms == PermissionLevel::Managed - && cached_role.permissions.manage_messages()) - { - return true; - } - } - } - if self.required_perms == PermissionLevel::Managed { let pool = ctx .data @@ -320,10 +300,10 @@ impl Framework for RegexFramework { ctx: &Context, guild: &Guild, channel: &GuildChannel, - ) -> Result> { + ) -> SerenityResult { let user_id = ctx.cache.current_user_id().await; - let guild_perms = guild.member_permissions(user_id); + let guild_perms = guild.member_permissions(&ctx, user_id).await?; let perms = channel.permissions_for_user(ctx, user_id).await?; let basic_perms = perms.send_messages(); diff --git a/src/main.rs b/src/main.rs index a47892c..1bddab6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use serenity::{ model::{ channel::GuildChannel, channel::Message, - guild::{Guild, PartialGuild}, + guild::{Guild, GuildUnavailable}, id::{GuildId, UserId}, }, prelude::{Context, EventHandler, TypeMapKey}, @@ -131,7 +131,7 @@ DELETE FROM channels WHERE channel = ? } } - async fn guild_delete(&self, ctx: Context, guild: PartialGuild, _guild: Option) { + async fn guild_delete(&self, ctx: Context, guild: GuildUnavailable, _guild: Option) { let pool = ctx .data .read() @@ -214,7 +214,7 @@ async fn main() -> Result<(), Box> { let framework_arc = Arc::new(Box::new(framework) as Box); - let mut client = Client::new(&token) + let mut client = Client::builder(&token) .intents( GatewayIntents::GUILD_MESSAGES | GatewayIntents::GUILDS