Class: RubyCord::Guild::AutoModRule

Inherits:
DiscordModel show all
Defined in:
lib/rubycord/guild/automod_rule.rb

Defined Under Namespace

Classes: Action

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DiscordModel

#==, #eql?, #inspect

Instance Attribute Details

#actionsArray<RubyCord::Guild::AutoModRule::Action> (readonly)

Returns The actions of the rule.

Returns:



34
35
36
# File 'lib/rubycord/guild/automod_rule.rb', line 34

def actions
  @actions
end

#allow_listArray<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.



40
41
42
# File 'lib/rubycord/guild/automod_rule.rb', line 40

def allow_list
  @allow_list
end

#enabledBoolean (readonly) Also known as: enabled?

Returns Whether the rule is enabled.

Returns:

  • (Boolean)

    Whether the rule is enabled.



31
32
33
# File 'lib/rubycord/guild/automod_rule.rb', line 31

def enabled
  @enabled
end

#idRubyCord::Snowflake (readonly)

Returns The ID of the rule.

Returns:



27
28
29
# File 'lib/rubycord/guild/automod_rule.rb', line 27

def id
  @id
end

#keyword_filterArray<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.



37
38
39
# File 'lib/rubycord/guild/automod_rule.rb', line 37

def keyword_filter
  @keyword_filter
end

#mention_total_limitInteger (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.



43
44
45
# File 'lib/rubycord/guild/automod_rule.rb', line 43

def mention_total_limit
  @mention_total_limit
end

#nameString (readonly)

Returns The name of the rule.

Returns:

  • (String)

    The name of the rule.



29
30
31
# File 'lib/rubycord/guild/automod_rule.rb', line 29

def name
  @name
end

Instance Method Details

#creatorRubyCord::Guild::Member

Returns The member who created the rule.

Returns:



74
75
76
# File 'lib/rubycord/guild/automod_rule.rb', line 74

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.



155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/rubycord/guild/automod_rule.rb', line 155

def delete(reason: nil)
  Async do
    @client.http.request(
      RubyCord::Internal::Route.new(
        "/guilds/#{@guild_id}/automod/rules/#{@id}",
        "//guilds/:guild_id/automod/rules/:id",
        :delete
      ),
      audit_log_reason: reason
    )
  end
end

#edit(name: RubyCord::Unset, event_type: RubyCord::Unset, actions: RubyCord::Unset, enabled: RubyCord::Unset, exempt_roles: RubyCord::Unset, exempt_channels: RubyCord::Unset, keyword_filter: RubyCord::Unset, presets: RubyCord::Unset, reason: nil) ⇒ Async::Task<void>

Edit the rule.

Parameters:

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

    The name of the rule.

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

    The event type of the rule. See EVENT_TYPES.

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

    The actions of the rule.

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

    Whether the rule is enabled or not.

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

    The roles that are exempt from the rule.

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

    The channels that are exempt from the rule.

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

    The keywords to filter.

  • presets (Symbol) (defaults to: RubyCord::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.



109
110
111
112
113
114
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
# File 'lib/rubycord/guild/automod_rule.rb', line 109

def edit(
  name: RubyCord::Unset,
  event_type: RubyCord::Unset,
  actions: RubyCord::Unset,
  enabled: RubyCord::Unset,
  exempt_roles: RubyCord::Unset,
  exempt_channels: RubyCord::Unset,
  keyword_filter: RubyCord::Unset,
  presets: RubyCord::Unset,
  reason: nil
)
  payload = { metadata: {} }
  payload[:name] = name unless name == RubyCord::Unset
  payload[:event_type] = EVENT_TYPES.key(event_type) unless event_type ==
    RubyCord::Unset
  payload[:actions] = actions unless actions == RubyCord::Unset
  payload[:enabled] = enabled unless enabled == RubyCord::Unset
  payload[:exempt_roles] = exempt_roles.map(&:id) unless exempt_roles ==
    RubyCord::Unset
  payload[:exempt_channels] = exempt_channels.map(
    &:id
  ) unless exempt_channels == RubyCord::Unset
  payload[:metadata][
    :keyword_filter
  ] = keyword_filter unless keyword_filter == RubyCord::Unset
  payload[:metadata][:presets] = PRESET_TYPES.key(presets) unless presets ==
    RubyCord::Unset

  @client.http.request(
    RubyCord::Internal::Route.new(
      "/guilds/#{@guild_id}/automod/rules/#{@id}",
      "//guilds/:guild_id/automod/rules/:id",
      :patch
    ),
    payload,
    audit_log_reason: reason
  )
end

#event_typeSymbol

Returns the type of the event.

Returns:

  • (Symbol)

    Returns the type of the event.



69
70
71
# File 'lib/rubycord/guild/automod_rule.rb', line 69

def event_type
  EVENT_TYPES[@event_type_raw]
end

#exempt_channelsArray<RubyCord::Channel>

Returns The channels that the rule is exempt from.

Returns:



89
90
91
# File 'lib/rubycord/guild/automod_rule.rb', line 89

def exempt_channels
  @exempt_channels_id.map { |id| guild.channels[id] }
end

#exempt_rolesArray<RubyCord::Guild::Role>

Returns The roles that the rule is exempt from.

Returns:



84
85
86
# File 'lib/rubycord/guild/automod_rule.rb', line 84

def exempt_roles
  @exempt_roles_id.map { |id| guild.roles[id] }
end

#guildRubyCord::Guild

Returns The guild that the rule is in.

Returns:



79
80
81
# File 'lib/rubycord/guild/automod_rule.rb', line 79

def guild
  @client.guilds[@guild_id]
end

#preset_typeSymbol

Note:

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

Returns the type of the preset.

Returns:

  • (Symbol)

    Returns the type of the preset.



59
60
61
# File 'lib/rubycord/guild/automod_rule.rb', line 59

def preset_type
  PRESET_TYPES[@presets_raw]
end

#trigger_typeSymbol

Returns the type of the trigger.

Returns:

  • (Symbol)

    Returns the type of the trigger.



64
65
66
# File 'lib/rubycord/guild/automod_rule.rb', line 64

def trigger_type
  TRIGGER_TYPES[@trigger_type_raw]
end