This repository has been archived by the owner on Jan 4, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add channel and guild permission calculations
show if a user is currently banned in a server in userinfo start of the logpump
- Loading branch information
1 parent
937338f
commit 5315a56
Showing
14 changed files
with
140 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use crate::core::Context; | ||
use crate::parser::Parser; | ||
use crate::CommandResult; | ||
use std::sync::Arc; | ||
use twilight::model::channel::Message; | ||
|
||
pub async fn quote(ctx: Arc<Context>, msg: Message, parser: Parser) -> CommandResult { | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use crate::core::Context; | ||
use crate::utils::LogType; | ||
use chrono::Utc; | ||
|
||
impl Context { | ||
pub fn log(&self, guild_id: u64, log: LogType) { | ||
match self.log_pumps.get(&guild_id) { | ||
Some(pump) => { | ||
pump.value().send((Utc::now(), log)); | ||
} | ||
None => {} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use crate::core::Context; | ||
use log::debug; | ||
use std::sync::Arc; | ||
use twilight::model::channel::permission_overwrite::PermissionOverwriteType; | ||
use twilight::model::channel::GuildChannel; | ||
use twilight::model::guild::Permissions; | ||
use twilight::model::id::{ChannelId, GuildId, UserId}; | ||
|
||
impl Context { | ||
pub async fn bot_has_guild_permissions( | ||
&self, | ||
guild_id: GuildId, | ||
permissions: Permissions, | ||
) -> bool { | ||
self.get_bot_guild_permissions(guild_id) | ||
.await | ||
.contains(permissions) | ||
} | ||
|
||
pub async fn get_bot_guild_permissions(&self, guild_id: GuildId) -> Permissions { | ||
self.get_guild_permissions_for(guild_id, self.bot_user.id) | ||
.await | ||
} | ||
|
||
pub async fn get_guild_permissions_for( | ||
&self, | ||
guild_id: GuildId, | ||
user_id: UserId, | ||
) -> Permissions { | ||
let mut permissions = Permissions::empty(); | ||
if let Some(member) = self.cache.member(guild_id, user_id).await.unwrap() { | ||
for role_id in &member.roles { | ||
if let Some(role) = self.cache.role(role_id.clone()).await.unwrap() { | ||
permissions |= role.permissions; | ||
} | ||
} | ||
}; | ||
permissions | ||
} | ||
|
||
pub async fn get_channel_permissions_for( | ||
&self, | ||
guild_id: GuildId, | ||
user_id: UserId, | ||
channel_id: ChannelId, | ||
) -> Permissions { | ||
let mut permissions = self.get_guild_permissions_for(guild_id, user_id).await; | ||
if let Some(channel) = self.cache.guild_channel(channel_id).await.unwrap() { | ||
if let Some(member) = self.cache.member(guild_id, user_id).await.unwrap() { | ||
let overrides = match &*channel { | ||
GuildChannel::Category(category) => &category.permission_overwrites, | ||
GuildChannel::Text(channel) => &channel.permission_overwrites, | ||
GuildChannel::Voice(channel) => &channel.permission_overwrites, | ||
}; | ||
let mut user_allowed = Permissions::empty(); | ||
let mut user_denied = Permissions::empty(); | ||
let mut role_allowed = Permissions::empty(); | ||
let mut role_denied = Permissions::empty(); | ||
for o in overrides { | ||
match o.kind { | ||
PermissionOverwriteType::Member(member_id) => { | ||
if member_id == user_id { | ||
user_allowed |= o.allow; | ||
user_denied |= o.deny; | ||
} | ||
} | ||
PermissionOverwriteType::Role(role_id) => { | ||
if member.roles.contains(&role_id) { | ||
role_allowed |= o.allow; | ||
role_denied |= o.deny; | ||
} | ||
} | ||
} | ||
} | ||
|
||
permissions &= !role_denied; | ||
permissions |= role_allowed; | ||
|
||
permissions &= !user_denied; | ||
permissions |= user_allowed; | ||
}; | ||
}; | ||
permissions | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub enum LogType {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters