Class: Discorb::AutoModRule::Action

Inherits:
DiscordModel show all
Defined in:
lib/discorb/automod.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 (Discorb::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.



227
228
229
230
231
# File 'lib/discorb/automod.rb', line 227

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.



216
217
218
# File 'lib/discorb/automod.rb', line 216

def duration_seconds
  @duration_seconds
end

#typeSymbol (readonly)

Returns the type of the action.

Returns:

  • (Symbol)

    Returns the type of the action.



213
214
215
# File 'lib/discorb/automod.rb', line 213

def type
  @type
end

Class Method Details

.from_hash(client, data) ⇒ Object



274
275
276
# File 'lib/discorb/automod.rb', line 274

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

Instance Method Details

#channelObject



263
264
265
# File 'lib/discorb/automod.rb', line 263

def channel
  @client.channels[@channel_id]
end

#to_hashHash

Convert the action to hash.

Returns:

  • (Hash)

    The action hash.



238
239
240
241
242
243
244
245
246
# File 'lib/discorb/automod.rb', line 238

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