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.



217
218
219
220
221
# File 'lib/discorb/automod.rb', line 217

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

Instance Attribute Details

#duration_seconds -> Integer (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.



206
207
208
# File 'lib/discorb/automod.rb', line 206

def duration_seconds
  @duration_seconds
end

#type -> Symbol (readonly)

Returns the type of the action.

Returns:

  • (Symbol)

    Returns the type of the action.



203
204
205
# File 'lib/discorb/automod.rb', line 203

def type
  @type
end

Class Method Details

.from_hash(client, data) -> Object



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

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

Instance Method Details

#channel -> Object



253
254
255
# File 'lib/discorb/automod.rb', line 253

def channel
  @client.channels[@channel_id]
end

#to_hash -> Hash

Convert the action to hash.

Returns:

  • (Hash)

    The action hash.



228
229
230
231
232
233
234
235
236
# File 'lib/discorb/automod.rb', line 228

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