use serenity from my repo. other minor improvements

This commit is contained in:
jude 2020-10-25 11:19:21 +00:00
parent 2e9b06faf6
commit a7fa722518
5 changed files with 59 additions and 64 deletions

77
Cargo.lock generated
View File

@ -64,18 +64,6 @@ dependencies = [
"syn", "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]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.41" version = "0.1.41"
@ -89,17 +77,18 @@ dependencies = [
[[package]] [[package]]
name = "async-tungstenite" name = "async-tungstenite"
version = "0.8.0" version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5c45a0dd44b7e6533ac4e7acc38ead1a3b39885f5bbb738140d30ea528abc7c" checksum = "9ce503a5cb1e7450af7d211b86b84807791b251f335b2f43f1e26b85a416f315"
dependencies = [ dependencies = [
"async-tls",
"futures-io", "futures-io",
"futures-util", "futures-util",
"log", "log",
"pin-project", "pin-project 1.0.1",
"tokio", "tokio",
"tokio-rustls",
"tungstenite", "tungstenite",
"webpki-roots 0.20.0",
] ]
[[package]] [[package]]
@ -125,6 +114,12 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
[[package]]
name = "base64"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]] [[package]]
name = "bigdecimal" name = "bigdecimal"
version = "0.1.2" version = "0.1.2"
@ -234,9 +229,8 @@ dependencies = [
[[package]] [[package]]
name = "command_attr" name = "command_attr"
version = "0.3.0-rc.2" version = "0.3.0-rc.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/jellywx/serenity?branch=jellywx-member_permissions#6d96e6837bbbc09127bd728b80daccce538daf09"
checksum = "6745770e89e5e4583424362f15f91c8bb0ef54387d209af30e0446d08909ae7d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -497,7 +491,7 @@ dependencies = [
"futures-sink", "futures-sink",
"futures-task", "futures-task",
"memchr", "memchr",
"pin-project", "pin-project 0.4.27",
"pin-utils", "pin-utils",
"proc-macro-hack", "proc-macro-hack",
"proc-macro-nested", "proc-macro-nested",
@ -638,7 +632,7 @@ dependencies = [
"httparse", "httparse",
"httpdate", "httpdate",
"itoa", "itoa",
"pin-project", "pin-project 0.4.27",
"socket2", "socket2",
"tokio", "tokio",
"tower-service", "tower-service",
@ -1021,7 +1015,16 @@ version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15"
dependencies = [ 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]] [[package]]
@ -1035,6 +1038,17 @@ dependencies = [
"syn", "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]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.1.10" version = "0.1.10"
@ -1165,7 +1179,7 @@ dependencies = [
[[package]] [[package]]
name = "reminder_rs" name = "reminder_rs"
version = "1.0.0-rc.9" version = "1.0.0-rc.10"
dependencies = [ dependencies = [
"Inflector", "Inflector",
"async-trait", "async-trait",
@ -1204,7 +1218,7 @@ version = "0.10.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9eaa17ac5d7b838b7503d118fa16ad88f440498bf9ffe5424e621f93190d61e" checksum = "e9eaa17ac5d7b838b7503d118fa16ad88f440498bf9ffe5424e621f93190d61e"
dependencies = [ dependencies = [
"base64", "base64 0.12.3",
"bytes", "bytes",
"encoding_rs", "encoding_rs",
"futures-core", "futures-core",
@ -1259,7 +1273,7 @@ version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d1126dcf58e93cee7d098dbda643b5f92ed724f1f6a63007c1116eed6700c81" checksum = "5d1126dcf58e93cee7d098dbda643b5f92ed724f1f6a63007c1116eed6700c81"
dependencies = [ dependencies = [
"base64", "base64 0.12.3",
"log", "log",
"ring", "ring",
"sct", "sct",
@ -1360,13 +1374,12 @@ dependencies = [
[[package]] [[package]]
name = "serenity" name = "serenity"
version = "0.9.0-rc.2" version = "0.9.0-rc.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/jellywx/serenity?branch=jellywx-member_permissions#6d96e6837bbbc09127bd728b80daccce538daf09"
checksum = "d179c8684cccfc95898c4a97ba3cb8787dd8db5e3f8cb645efd129ddb1a7dd7f"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"async-tungstenite", "async-tungstenite",
"base64", "base64 0.13.0",
"bitflags", "bitflags",
"bytes", "bytes",
"chrono", "chrono",
@ -1485,7 +1498,7 @@ checksum = "88ac5a436f941c42eac509471a730df5c3c58e1450e68cd39afedbd948206273"
dependencies = [ dependencies = [
"async-native-tls", "async-native-tls",
"async-stream", "async-stream",
"base64", "base64 0.12.3",
"bigdecimal", "bigdecimal",
"bitflags", "bitflags",
"byteorder", "byteorder",
@ -1731,7 +1744,7 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c" checksum = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c"
dependencies = [ dependencies = [
"pin-project", "pin-project 0.4.27",
"tracing", "tracing",
] ]
@ -1747,7 +1760,7 @@ version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0308d80d86700c5878b9ef6321f020f29b1bb9d5ff3cab25e75e23f3a492a23" checksum = "f0308d80d86700c5878b9ef6321f020f29b1bb9d5ff3cab25e75e23f3a492a23"
dependencies = [ dependencies = [
"base64", "base64 0.12.3",
"byteorder", "byteorder",
"bytes", "bytes",
"http", "http",

View File

@ -1,11 +1,11 @@
[package] [package]
name = "reminder_rs" name = "reminder_rs"
version = "1.0.0-rc.9" version = "1.0.0-rc.10"
authors = ["jellywx <judesouthworth@pm.me>"] authors = ["jellywx <judesouthworth@pm.me>"]
edition = "2018" edition = "2018"
[dependencies] [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" dotenv = "0.15"
tokio = { version = "0.2", features = ["process"] } tokio = { version = "0.2", features = ["process"] }
reqwest = { version = "0.10", features = ["rustls-tls"] } reqwest = { version = "0.10", features = ["rustls-tls"] }

View File

@ -35,3 +35,5 @@ __Other Variables__
* `THEME_COLOR` - default `8fb677`. Specifies the hex value of the color to use on info message embeds * `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** * `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) * `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

View File

@ -22,7 +22,6 @@ use std::{collections::HashMap, fmt};
use crate::models::{GuildData, UserData}; use crate::models::{GuildData, UserData};
use crate::{models::ChannelData, SQLPool}; use crate::{models::ChannelData, SQLPool};
use serenity::futures::TryFutureExt;
type CommandFn = type CommandFn =
for<'fut> fn(&'fut Context, &'fut Message, String) -> BoxFuture<'fut, CommandResult>; for<'fut> fn(&'fut Context, &'fut Message, String) -> BoxFuture<'fut, CommandResult>;
@ -47,34 +46,15 @@ impl Command {
if self.required_perms == PermissionLevel::Unrestricted { if self.required_perms == PermissionLevel::Unrestricted {
true true
} else { } else {
if member let permissions = guild.member_permissions(&ctx, &member.user).await.unwrap();
.permissions(&ctx)
.map_ok_or_else( if permissions.manage_guild()
|_| false, || (permissions.manage_messages()
|perms| { && self.required_perms == PermissionLevel::Managed)
perms.manage_guild()
|| (self.required_perms == PermissionLevel::Managed
&& perms.manage_messages())
},
)
.await
{ {
return true; 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 { if self.required_perms == PermissionLevel::Managed {
let pool = ctx let pool = ctx
.data .data
@ -320,10 +300,10 @@ impl Framework for RegexFramework {
ctx: &Context, ctx: &Context,
guild: &Guild, guild: &Guild,
channel: &GuildChannel, channel: &GuildChannel,
) -> Result<PermissionCheck, Box<dyn std::error::Error + Sync + Send>> { ) -> SerenityResult<PermissionCheck> {
let user_id = ctx.cache.current_user_id().await; 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 perms = channel.permissions_for_user(ctx, user_id).await?;
let basic_perms = perms.send_messages(); let basic_perms = perms.send_messages();

View File

@ -16,7 +16,7 @@ use serenity::{
model::{ model::{
channel::GuildChannel, channel::GuildChannel,
channel::Message, channel::Message,
guild::{Guild, PartialGuild}, guild::{Guild, GuildUnavailable},
id::{GuildId, UserId}, id::{GuildId, UserId},
}, },
prelude::{Context, EventHandler, TypeMapKey}, prelude::{Context, EventHandler, TypeMapKey},
@ -131,7 +131,7 @@ DELETE FROM channels WHERE channel = ?
} }
} }
async fn guild_delete(&self, ctx: Context, guild: PartialGuild, _guild: Option<Guild>) { async fn guild_delete(&self, ctx: Context, guild: GuildUnavailable, _guild: Option<Guild>) {
let pool = ctx let pool = ctx
.data .data
.read() .read()
@ -214,7 +214,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let framework_arc = Arc::new(Box::new(framework) as Box<dyn Framework + Send + Sync>); let framework_arc = Arc::new(Box::new(framework) as Box<dyn Framework + Send + Sync>);
let mut client = Client::new(&token) let mut client = Client::builder(&token)
.intents( .intents(
GatewayIntents::GUILD_MESSAGES GatewayIntents::GUILD_MESSAGES
| GatewayIntents::GUILDS | GatewayIntents::GUILDS