Class: Discorb::AutoModRule
- Inherits:
-
DiscordModel
- Object
- DiscordModel
- Discorb::AutoModRule
- Defined in:
- lib/discorb/automod.rb
Overview
Represents a rule of auto moderation.
Defined Under Namespace
Classes: Action
Instance Attribute Summary collapse
-
#actions -> Array<Discorb::AutoModRule::Action>
readonly
The actions of the rule.
-
#allow_list -> Array<String>
readonly
Substrings which will be exempt from triggering the preset trigger type.
-
#enabled -> Boolean
(also: #enabled?)
readonly
Whether the rule is enabled.
-
#id -> Discorb::Snowflake
readonly
The ID of the rule.
-
#keyword_filter -> Array<String>
readonly
The keywords that the rule is triggered by.
-
#mention_total_limit -> Integer
readonly
Total number of mentions allowed per message.
-
#name -> String
readonly
The name of the rule.
Instance Method Summary collapse
- #creator -> Object
-
#delete(reason: nil) -> Async::Task<void>
Delete the rule.
-
#edit(name: Discorb::Unset, event_type: Discorb::Unset, actions: Discorb::Unset, enabled: Discorb::Unset, exempt_roles: Discorb::Unset, exempt_channels: Discorb::Unset, keyword_filter: Discorb::Unset, presets: Discorb::Unset, reason: nil) -> Async::Task<void>
Edit the rule.
- #event_type -> Object
- #exempt_channels -> Object
- #exempt_roles -> Object
- #guild -> Object
- #preset_type -> Object
- #trigger_type -> Object
Methods inherited from DiscordModel
Instance Attribute Details
#actions -> Array<Discorb::AutoModRule::Action> (readonly)
Returns The actions of the rule.
32 33 34 |
# File 'lib/discorb/automod.rb', line 32 def actions @actions end |
#allow_list -> Array<String> (readonly)
This is only available if the trigger type is :keyword_preset
.
Returns Substrings which will be exempt from triggering the preset trigger type.
38 39 40 |
# File 'lib/discorb/automod.rb', line 38 def allow_list @allow_list end |
#enabled -> Boolean (readonly) Also known as: enabled?
Returns Whether the rule is enabled.
29 30 31 |
# File 'lib/discorb/automod.rb', line 29 def enabled @enabled end |
#id -> Discorb::Snowflake (readonly)
Returns The ID of the rule.
25 26 27 |
# File 'lib/discorb/automod.rb', line 25 def id @id end |
#keyword_filter -> Array<String> (readonly)
This is only available if the trigger type is :keyword
.
Returns The keywords that the rule is triggered by.
35 36 37 |
# File 'lib/discorb/automod.rb', line 35 def keyword_filter @keyword_filter end |
#mention_total_limit -> Integer (readonly)
This is only available if the trigger type is :mention_spam
.
Returns Total number of mentions allowed per message.
41 42 43 |
# File 'lib/discorb/automod.rb', line 41 def mention_total_limit @mention_total_limit end |
#name -> String (readonly)
Returns The name of the rule.
27 28 29 |
# File 'lib/discorb/automod.rb', line 27 def name @name end |
Instance Method Details
#creator -> Object
77 78 79 |
# File 'lib/discorb/automod.rb', line 77 def creator guild.members[@creator_id] end |
#delete(reason: nil) -> Async::Task<void>
Delete the rule.
163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/discorb/automod.rb', line 163 def delete(reason: nil) Async do @client.http.request( Route.new( "/guilds/#{@guild_id}/automod/rules/#{@id}", "//guilds/:guild_id/automod/rules/:id", :delete ), audit_log_reason: reason ) end end |
#edit(name: Discorb::Unset, event_type: Discorb::Unset, actions: Discorb::Unset, enabled: Discorb::Unset, exempt_roles: Discorb::Unset, exempt_channels: Discorb::Unset, keyword_filter: Discorb::Unset, presets: Discorb::Unset, reason: nil) -> Async::Task<void>
Edit the rule.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/discorb/automod.rb', line 116 def edit( name: Discorb::Unset, event_type: Discorb::Unset, actions: Discorb::Unset, enabled: Discorb::Unset, exempt_roles: Discorb::Unset, exempt_channels: Discorb::Unset, keyword_filter: Discorb::Unset, presets: Discorb::Unset, reason: nil ) # @type var payload: Hash[Symbol, untyped] payload = { metadata: {} } payload[:name] = name unless name == Discorb::Unset payload[:event_type] = EVENT_TYPES.key(event_type) unless event_type == Discorb::Unset payload[:actions] = actions unless actions == Discorb::Unset payload[:enabled] = enabled unless enabled == Discorb::Unset payload[:exempt_roles] = exempt_roles.map(&:id) unless exempt_roles == Discorb::Unset payload[:exempt_channels] = exempt_channels.map( &:id ) unless exempt_channels == Discorb::Unset payload[:metadata][ :keyword_filter ] = keyword_filter unless keyword_filter == Discorb::Unset payload[:metadata][:presets] = PRESET_TYPES.key(presets) unless presets == Discorb::Unset @client.http.request( Route.new( "/guilds/#{@guild_id}/automod/rules/#{@id}", "//guilds/:guild_id/automod/rules/:id", :patch ), payload, audit_log_reason: reason ) end |
#event_type -> Object
70 71 72 |
# File 'lib/discorb/automod.rb', line 70 def event_type EVENT_TYPES[@event_type_raw] end |
#exempt_channels -> Object
95 96 97 |
# File 'lib/discorb/automod.rb', line 95 def exempt_channels @exempt_channels_id.map { |id| guild.channels[id] } end |
#exempt_roles -> Object
89 90 91 |
# File 'lib/discorb/automod.rb', line 89 def exempt_roles @exempt_roles_id.map { |id| guild.roles[id] } end |
#guild -> Object
83 84 85 |
# File 'lib/discorb/automod.rb', line 83 def guild @client.guilds[@guild_id] end |
#preset_type -> Object
58 59 60 |
# File 'lib/discorb/automod.rb', line 58 def preset_type PRESET_TYPES[@presets_raw] end |
#trigger_type -> Object
64 65 66 |
# File 'lib/discorb/automod.rb', line 64 def trigger_type TRIGGER_TYPES[@trigger_type_raw] end |