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:



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.

Returns:

  • (Boolean)

    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.

Returns:



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.

Returns:

  • (Array<String>)

    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.

Returns:

  • (String)

    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.

Parameters:

  • reason (String) (defaults to: nil)

    The reason for deleting the rule.

Returns:

  • (Async::Task<void>)

    The task.



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.

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.



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