Class: Discorb::AutoModRule

Inherits:
DiscordModel show all
Defined in:
lib/discorb/automod.rb

Overview

Represents a rule of auto moderation.

Defined Under Namespace

Classes: Action

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DiscordModel

#==, #eql?, #inspect

Instance Attribute Details

#actions -> Array<Discorb::AutoModRule::Action> (readonly)

Returns The actions of the rule.

Returns:



32
33
34
# File 'lib/discorb/automod.rb', line 32

def actions
  @actions
end

#allow_list -> Array<String> (readonly)

Note:

This is only available if the trigger type is :keyword_preset.

Returns Substrings which will be exempt from triggering the preset trigger type.

Returns:

  • (Array<String>)

    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.

Returns:

  • (Boolean)

    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.

Returns:



25
26
27
# File 'lib/discorb/automod.rb', line 25

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.

Returns:

  • (Array<String>)

    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)

Note:

This is only available if the trigger type is :mention_spam.

Returns Total number of mentions allowed per message.

Returns:

  • (Integer)

    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.

Returns:

  • (String)

    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.

Parameters:

  • reason (String) (defaults to: nil)

    The reason for deleting the rule.

Returns:

  • (Async::Task<void>)

    The task.



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.

Parameters:

  • name (String) (defaults to: Discorb::Unset)

    The name of the rule.

  • event_type (Symbol) (defaults to: Discorb::Unset)

    The event type of the rule. See EVENT_TYPES.

  • actions (Array<Discorb::AutoModRule::Action>) (defaults to: Discorb::Unset)

    The actions of the rule.

  • enabled (Boolean) (defaults to: Discorb::Unset)

    Whether the rule is enabled or not.

  • exempt_roles (Array<Discorb::Role>) (defaults to: Discorb::Unset)

    The roles that are exempt from the rule.

  • exempt_channels (Array<Discorb::Channel>) (defaults to: Discorb::Unset)

    The channels that are exempt from the rule.

  • keyword_filter (Array<String>) (defaults to: Discorb::Unset)

    The keywords to filter.

  • presets (Symbol) (defaults to: Discorb::Unset)

    The preset of the rule. See PRESET_TYPES.

  • reason (String) (defaults to: nil)

    The reason for creating the rule.

Returns:

  • (Async::Task<void>)

    The task.



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