Class: RubyCord::Guild::AutoModRule::Action

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

Overview

Represents the action of auto moderation.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DiscordModel

#==, #eql?, #inspect

Constructor Details

#initialize(type, duration_seconds: nil, channel: nil) ⇒ Action

Initialize a new action.

Parameters:

  • type (Symbol)

    The type of the action.

  • duration_seconds (Integer) (defaults to: nil)

    The duration of the timeout. This is only available if the action type is :timeout.

  • channel (RubyCord::Channel) (defaults to: nil)

    The channel that the alert message is sent to. This is only available if the action type is :send_alert_message.



219
220
221
222
223
# File 'lib/rubycord/guild/automod_rule.rb', line 219

def initialize(type, duration_seconds: nil, channel: nil)
  @type = type
  @duration_seconds = duration_seconds
  @channel = channel
end

Instance Attribute Details

#duration_secondsInteger (readonly)

Note:

This is only available if the action type is :timeout.

Returns The duration of the timeout.

Returns:

  • (Integer)

    The duration of the timeout.



208
209
210
# File 'lib/rubycord/guild/automod_rule.rb', line 208

def duration_seconds
  @duration_seconds
end

#typeSymbol (readonly)

Returns the type of the action.

Returns:

  • (Symbol)

    Returns the type of the action.



205
206
207
# File 'lib/rubycord/guild/automod_rule.rb', line 205

def type
  @type
end

Class Method Details

.from_hash(client, data) ⇒ Object



265
266
267
# File 'lib/rubycord/guild/automod_rule.rb', line 265

def self.from_hash(client, data)
  allocate.tap { |action| action.initialize_hash(client, data) }
end

Instance Method Details

#channelRubyCord::Channel

Note:

This is only available if the action type is :send_alert_message.

Returns The channel that the alert message is sent to.

Returns:



254
255
256
# File 'lib/rubycord/guild/automod_rule.rb', line 254

def channel
  @client.channels[@channel_id]
end

#to_hashHash

Convert the action to hash.

Returns:

  • (Hash)

    The action hash.



230
231
232
233
234
235
236
237
238
# File 'lib/rubycord/guild/automod_rule.rb', line 230

def to_hash
  {
    type: @type,
    metadata: {
      channel_id: @channel&.id,
      duration_seconds: @duration_seconds
    }
  }
end