Skip to content

Commit

Permalink
Update serenity
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Nov 20, 2023
1 parent c3b67a1 commit e6aea6d
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 50 deletions.
97 changes: 60 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ linkify = "0.10"
strsim = "0.10"
sysinfo = "0.29"
num-format = "0.4"
itertools = "0.11"
itertools = "0.12"
parking_lot = "0.12"
const_format = "0.2"
strum_macros = "0.25"
Expand Down Expand Up @@ -73,6 +73,8 @@ branch = "next"

[patch.crates-io]
serenity = { git = "https://github.com/GnomedDev/serenity", branch = "typesize" }
serenity-voice-model = { git = "https://github.com/GnomedDev/serenity", branch = "typesize" }

[patch."https://github.com/serenity-rs/serenity"]
serenity = { git = "https://github.com/GnomedDev/serenity", branch = "typesize" }
serenity-voice-model = { git = "https://github.com/GnomedDev/serenity", branch = "typesize" }
2 changes: 1 addition & 1 deletion src/commands/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ pub async fn invite(ctx: Context<'_>) -> CommandResult {
.replace("{bot_mention}", &bot_mention)
} else {
cache
.guild_channel(invite_channel)
.channel(invite_channel)
.map(|c| {
ctx.gettext(
"Join {server_invite} and look in #{channel_name} to invite {bot_mention}",
Expand Down
2 changes: 1 addition & 1 deletion src/events/voice_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub async fn voice_state_update(

let channel_members = ctx
.cache
.guild_channel(old.channel_id.try_unwrap()?)
.channel(old.channel_id.try_unwrap()?)
.try_unwrap()?
.members(&ctx.cache)?;

Expand Down
26 changes: 16 additions & 10 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,26 @@ impl PoiseContextExt for Context<'_> {
}

async fn author_permissions(&self) -> Result<serenity::Permissions> {
let ctx_discord = self.serenity_context();
match ctx_discord.cache.channel(self.channel_id()).try_unwrap()? {
serenity::Channel::Guild(channel) => {
let member = channel.guild_id.member(ctx_discord, self.author()).await?;
let guild = channel.guild(&ctx_discord.cache).try_unwrap()?;

Ok(guild.user_permissions_in(&channel, &member))
}
_ => Ok(((serenity::Permissions::from_bits_truncate(
// Handle non-guild call first, to allow try_unwrap calls to be safe.
if self.guild_id().is_none() {
return Ok(((serenity::Permissions::from_bits_truncate(
0b111_1100_1000_0000_0000_0111_1111_1000_0100_0000,
) | serenity::Permissions::SEND_MESSAGES)
- serenity::Permissions::SEND_TTS_MESSAGES)
- serenity::Permissions::MANAGE_MESSAGES),
- serenity::Permissions::MANAGE_MESSAGES);
}

// Accesses guild cache and is asynchronous, must be called first.
let member = self.author_member().await.try_unwrap()?;

// Accesses guild cache, but the member above was cloned out, so safe.
let guild = self.guild().try_unwrap()?;

// Does not access cache, but relies on above guild cache reference.
let channel = guild.channels.get(&self.channel_id()).try_unwrap()?;

// Does not access cache.
Ok(guild.user_permissions_in(channel, &member))
}

async fn send_error(&self, error_message: String) -> Result<Option<poise::ReplyHandle<'_>>> {
Expand Down

0 comments on commit e6aea6d

Please sign in to comment.