Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(http,model)!: auto moderation http methods and mention spam #1846

Merged
merged 15 commits into from
Oct 28, 2022
36 changes: 20 additions & 16 deletions twilight-http-ratelimiting/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ pub enum Path {
ApplicationGuildCommandId(u64),
/// Operating on a channel.
ChannelsId(u64),
/// Operating on a channel's followers.
ChannelsIdFollowers(u64),
/// Operating on a channel's invites.
ChannelsIdInvites(u64),
/// Operating on a channel's messages.
Expand Down Expand Up @@ -160,8 +162,6 @@ pub enum Path {
ChannelsIdTyping(u64),
/// Operating on a channel's webhooks.
ChannelsIdWebhooks(u64),
/// Operating on a channel's followers.
ChannelsIdFollowers(u64),
/// Operating with the gateway information.
Gateway,
/// Operating with the gateway information tailored to the current user.
Expand All @@ -170,18 +170,20 @@ pub enum Path {
Guilds,
/// Operating on one of user's guilds.
GuildsId(u64),
/// Operating on a ban from one of the user's guilds.
GuildsIdAuditLogs(u64),
/// Operating on a guild's auto moderation rules.
GuildsIdAutoModerationRules(u64),
/// Operating on an auto moderation rule from one of the user's guilds.
GuildsIdAutoModerationRulesId(u64),
/// Operating on one of the user's guilds' bans.
GuildsIdBans(u64),
/// Operating on a ban from one of the user's guilds.
GuildsIdBansId(u64),
/// Operating on a ban from one of the user's guilds.
GuildsIdAuditLogs(u64),
/// Operating on specific member's ban from one of the user's guilds.
GuildsIdBansUserId(u64),
/// Operating on one of the user's guilds' channels.
GuildsIdChannels(u64),
/// Operating on one of the user's guilds' widget.
GuildsIdWidget(u64),
/// Operating on one of the user's guilds' emojis.
GuildsIdEmojis(u64),
/// Operating on an emoji from one of the user's guilds.
Expand Down Expand Up @@ -226,8 +228,6 @@ pub enum Path {
GuildsIdStickers(u64),
/// Operating on one of the user's guilds' templates.
GuildsIdTemplates(u64),
/// Operating on a guild template.
GuildsTemplatesCode(String),
/// Operating on a template from one of the user's guilds.
GuildsIdTemplatesCode(u64, String),
/// Operating on one of the user's guilds' threads.
Expand All @@ -236,16 +236,22 @@ pub enum Path {
GuildsIdVanityUrl(u64),
/// Operating on one of the user's guilds' voice states.
GuildsIdVoiceStates(u64),
/// Operating on one of the user's guilds' welcome screen.
GuildsIdWelcomeScreen(u64),
/// Operating on one of the user's guilds' webhooks.
GuildsIdWebhooks(u64),
/// Operating on an invite.
InvitesCode,
/// Operating on one of the user's guilds' welcome screen.
GuildsIdWelcomeScreen(u64),
/// Operating on one of the user's guilds' widget.
GuildsIdWidget(u64),
/// Operating on a guild template.
GuildsTemplatesCode(String),
/// Operating on an interaction's callback.
///
/// This path is not bound to the application's global rate limit.
InteractionCallback(u64),
/// Operating on an invite.
InvitesCode,
/// Operating on the user's application information.
OauthApplicationsMe,
/// Operating on stage instances.
StageInstances,
/// Operating on sticker packs.
Expand All @@ -254,12 +260,10 @@ pub enum Path {
Stickers,
/// Operating on a sticker.
UsersId,
/// Operating on the user's application information.
OauthApplicationsMe,
/// Operating on the user's connections.
UsersIdConnections,
/// Operating on the user's private channels.
UsersIdChannels,
/// Operating on the user's connections.
UsersIdConnections,
/// Operating on the state of a guild that the user is in.
UsersIdGuilds,
/// Operating on the state of a guild that the user is in.
Expand Down
98 changes: 94 additions & 4 deletions twilight-http/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ use crate::{
FollowNewsChannel, GetChannel, GetPins, UpdateChannel, UpdateChannelPermission,
},
guild::{
auto_moderation::{
CreateAutoModerationRule, DeleteAutoModerationRule, GetAutoModerationRule,
GetGuildAutoModerationRules, UpdateAutoModerationRule,
},
ban::{CreateBan, DeleteBan, GetBan, GetBans},
create_guild::CreateGuildError,
emoji::{CreateEmoji, DeleteEmoji, GetEmoji, GetEmojis, UpdateEmoji},
Expand Down Expand Up @@ -95,13 +99,13 @@ use tokio::time;
use twilight_http_ratelimiting::Ratelimiter;
use twilight_model::{
channel::{message::allowed_mentions::AllowedMentions, ChannelType},
guild::MfaLevel,
guild::{auto_moderation::AutoModerationEventType, MfaLevel},
http::permission_overwrite::PermissionOverwrite,
id::{
marker::{
ApplicationMarker, ChannelMarker, EmojiMarker, GuildMarker, IntegrationMarker,
MessageMarker, RoleMarker, ScheduledEventMarker, StickerMarker, UserMarker,
WebhookMarker,
ApplicationMarker, AutoModerationRuleMarker, ChannelMarker, EmojiMarker, GuildMarker,
IntegrationMarker, MessageMarker, RoleMarker, ScheduledEventMarker, StickerMarker,
UserMarker, WebhookMarker,
},
Id,
},
Expand Down Expand Up @@ -287,6 +291,92 @@ impl Client {
self.ratelimiter.as_ref().map(AsRef::as_ref)
}

/// Get an auto moderation rule in a guild.
///
/// Requires the [`MANAGE_GUILD`] permission.
///
/// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
pub const fn auto_moderation_rule(
&self,
guild_id: Id<GuildMarker>,
auto_moderation_rule_id: Id<AutoModerationRuleMarker>,
) -> GetAutoModerationRule<'_> {
GetAutoModerationRule::new(self, guild_id, auto_moderation_rule_id)
}

/// Get the auto moderation rules in a guild.
///
/// Requires the [`MANAGE_GUILD`] permission.
///
/// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
pub const fn auto_moderation_rules(
&self,
guild_id: Id<GuildMarker>,
) -> GetGuildAutoModerationRules<'_> {
GetGuildAutoModerationRules::new(self, guild_id)
}

/// Create an auto moderation rule within a guild.
///
/// Requires the [`MANAGE_GUILD`] permission.
///
/// # Examples
///
/// Create a rule that deletes messages that contain the word "darn":
///
/// ```no_run
/// # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use twilight_http::Client;
/// use twilight_model::{guild::auto_moderation::AutoModerationEventType, id::Id};
///
/// let client = Client::new("my token".to_owned());
///
/// let guild_id = Id::new(1);
/// client
/// .create_auto_moderation_rule(guild_id, "no darns", AutoModerationEventType::MessageSend)
/// .action_block_message()
/// .enabled(true)
/// .with_keyword(&["darn"])
/// .await?;
/// # Ok(()) }
/// ```
///
/// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
pub const fn create_auto_moderation_rule<'a>(
&'a self,
guild_id: Id<GuildMarker>,
name: &'a str,
event_type: AutoModerationEventType,
) -> CreateAutoModerationRule<'a> {
CreateAutoModerationRule::new(self, guild_id, name, event_type)
}

/// Delete an auto moderation rule in a guild.
///
/// Requires the [`MANAGE_GUILD`] permission.
///
/// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
pub const fn delete_auto_moderation_rule(
&self,
guild_id: Id<GuildMarker>,
auto_moderation_rule_id: Id<AutoModerationRuleMarker>,
) -> DeleteAutoModerationRule<'_> {
DeleteAutoModerationRule::new(self, guild_id, auto_moderation_rule_id)
}

/// Update an auto moderation rule in a guild.
///
/// Requires the [`MANAGE_GUILD`] permission.
///
/// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
pub const fn update_auto_moderation_rule(
&self,
guild_id: Id<GuildMarker>,
auto_moderation_rule_id: Id<AutoModerationRuleMarker>,
) -> UpdateAutoModerationRule<'_> {
UpdateAutoModerationRule::new(self, guild_id, auto_moderation_rule_id)
}

/// Get the audit log for a guild.
///
/// # Examples
Expand Down
6 changes: 6 additions & 0 deletions twilight-http/src/request/audit_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ mod private {
UpdateChannelPermission,
},
guild::{
auto_moderation::{
CreateAutoModerationRule, DeleteAutoModerationRule, UpdateAutoModerationRule,
},
ban::{CreateBan, DeleteBan},
emoji::{CreateEmoji, DeleteEmoji, UpdateEmoji},
integration::DeleteGuildIntegration,
Expand All @@ -44,6 +47,7 @@ mod private {
pub trait Sealed {}

impl Sealed for AddRoleToMember<'_> {}
impl Sealed for CreateAutoModerationRule<'_> {}
impl Sealed for CreateBan<'_> {}
impl Sealed for CreateEmoji<'_> {}
impl Sealed for CreateGuildChannel<'_> {}
Expand All @@ -57,6 +61,7 @@ mod private {
impl Sealed for CreatePin<'_> {}
impl Sealed for CreateRole<'_> {}
impl Sealed for CreateWebhook<'_> {}
impl Sealed for DeleteAutoModerationRule<'_> {}
impl Sealed for DeleteBan<'_> {}
impl Sealed for DeleteChannel<'_> {}
impl Sealed for DeleteChannelPermissionConfigured<'_> {}
Expand All @@ -71,6 +76,7 @@ mod private {
impl Sealed for DeleteWebhookMessage<'_> {}
impl Sealed for RemoveMember<'_> {}
impl Sealed for RemoveRoleFromMember<'_> {}
impl Sealed for UpdateAutoModerationRule<'_> {}
impl Sealed for UpdateChannel<'_> {}
impl Sealed for UpdateChannelPermission<'_> {}
impl Sealed for UpdateCurrentMember<'_> {}
Expand Down
Loading