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.
-
#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.
-
#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.
37 38 39 |
# File 'lib/discorb/automod.rb', line 37 def actions @actions end |
#enabled -> Boolean (readonly) Also known as: enabled?
Returns Whether the rule is enabled.
34 35 36 |
# File 'lib/discorb/automod.rb', line 34 def enabled @enabled end |
#id -> Discorb::Snowflake (readonly)
Returns The ID of the rule.
30 31 32 |
# File 'lib/discorb/automod.rb', line 30 def id @id end |
#keyword_filter -> Array<String> (readonly)
Note:
This is only available if the trigger type is :keyword
.
Returns The keywords that the rule is triggered by.
40 41 42 |
# File 'lib/discorb/automod.rb', line 40 def keyword_filter @keyword_filter end |
#name -> String (readonly)
Returns The name of the rule.
32 33 34 |
# File 'lib/discorb/automod.rb', line 32 def name @name end |
Instance Method Details
#creator -> Object
76 77 78 |
# File 'lib/discorb/automod.rb', line 76 def creator guild.members[@creator_id] end |
#delete!(reason: nil) -> Async::Task<void>
Delete the rule.
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/discorb/automod.rb', line 157 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.
115 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 |
# File 'lib/discorb/automod.rb', line 115 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
69 70 71 |
# File 'lib/discorb/automod.rb', line 69 def event_type EVENT_TYPES[@event_type_raw] end |
#exempt_channels -> Object
94 95 96 |
# File 'lib/discorb/automod.rb', line 94 def exempt_channels @exempt_channels_id.map { |id| guild.channels[id] } end |
#exempt_roles -> Object
88 89 90 |
# File 'lib/discorb/automod.rb', line 88 def exempt_roles @exempt_roles_id.map { |id| guild.roles[id] } end |
#guild -> Object
82 83 84 |
# File 'lib/discorb/automod.rb', line 82 def guild @client.guilds[@guild_id] end |
#preset_type -> Object
57 58 59 |
# File 'lib/discorb/automod.rb', line 57 def preset_type PRESET_TYPES[@presets_raw] end |
#trigger_type -> Object
63 64 65 |
# File 'lib/discorb/automod.rb', line 63 def trigger_type TRIGGER_TYPES[@trigger_type_raw] end |