class Discordrb::AuditLogs::Entry

An entry in a server's audit logs.

Attributes

action[R]

@return [Symbol] the action that was performed.

action_type[R]

@return [Symbol] the type action that was performed. (:create, :delete, :update, :unknown)

amount[R]

@return [Integer, nil] the amount of messages deleted. Only present if the action is `:message_delete`.

changes[R]

@return [Hash<String => Change>, RoleChange, nil] the changes from this log, listing the key as the key changed. Will be a RoleChange object if the action is `:member_role_update`. Will be nil if the action is either `:message_delete` or `:member_prune`.

count[R]

@return [Integer, nil] the amount of messages deleted. Only present if the action is `:message_delete`.

days[R]

@return [Integer, nil] the amount of days the members were inactive for. Only present if the action is `:member_prune`.

members_removed[R]

@return [Integer, nil] the amount of members removed. Only present if the action is `:member_prune`.

reason[R]

@return [String, nil] the reason for this action occuring.

target_type[R]

@return [Symbol] the type of target being performed on. (:server, :channel, :user, :role, :invite, :webhook, :emoji, :unknown)

Public Class Methods

new(logs, server, bot, data) click to toggle source

@!visibility private

# File lib/discordrb/data.rb, line 3965
def initialize(logs, server, bot, data)
  @bot = bot
  @id = data['id'].resolve_id
  @logs = logs
  @server = server
  @data = data
  @action = ACTIONS[data['action_type']]
  @reason = data['reason']
  @action_type = AuditLogs.action_type_for(data['action_type'])
  @target_type = AuditLogs.target_type_for(data['action_type'])

  # Sets the 'changes' variable to a empty hash if there are no special actions.
  @changes = {} unless @action == :message_delete || @action == :member_prune || @action == :member_role_update

  # Sets the 'changes' variable to a RoleChange class if theres a role update.
  @changes = RoleChange.new(data['changes'][0], @server) if @action == :member_role_update

  process_changes(data['changes']) unless @action == :member_role_update
  return unless data.include?('options')

  # Checks and sets variables for special action options.
  @count = data['options']['count'].to_i unless data['options']['count'].nil?
  @channel_id = data['options']['channel'].to_i unless data['options']['channel'].nil?
  @days = data['options']['delete_member_days'].to_i unless data['options']['delete_member_days'].nil?
  @members_removed = data['options']['members_removed'].to_i unless data['options']['members_removed'].nil?
end

Public Instance Methods

author()
Alias for: user
channel() click to toggle source

@return [Channel, nil] the amount of messages deleted. Won't be nil if the action is `:message_delete`.

# File lib/discordrb/data.rb, line 4004
def channel
  return nil unless @channel_id

  @channel ||= @bot.channel(@channel_id, @server, bot, self)
end
inspect() click to toggle source

The inspect method is overwritten to give more useful output

# File lib/discordrb/data.rb, line 4025
def inspect
  "<AuditLogs::Entry id=#{@id} action=#{@action} reason=#{@reason} action_type=#{@action_type} target_type=#{@target_type} count=#{@count} days=#{@days} members_removed=#{@members_removed}>"
end
process_changes(changes) click to toggle source

Process action changes @note For internal use only @!visibility private

# File lib/discordrb/data.rb, line 4032
def process_changes(changes)
  return unless changes

  changes.each do |element|
    change = Change.new(element, @server, @bot, self)
    @changes[change.key] = change
  end
end
process_target(id, type) click to toggle source

@!visibility private

# File lib/discordrb/data.rb, line 4011
def process_target(id, type)
  id = id.resolve_id unless id.nil?
  case type
  when :server then @server # Since it won't be anything else
  when :channel then @bot.channel(id, @server)
  when :user, :message then @server.member(id) || @bot.user(id) || @logs.user(id)
  when :role then @server.role(id)
  when :invite then @bot.invite(@data['changes'].find { |change| change['key'] == 'code' }.values.delete_if { |v| v == 'code' }.first)
  when :webhook then @server.webhooks.find { |webhook| webhook.id == id } || @logs.webhook(id)
  when :emoji then @server.emoji[id]
  end
end
target() click to toggle source

@return [Server, Channel, Member, User, Role, Invite, Webhook, Emoji, nil] the target being performed on.

# File lib/discordrb/data.rb, line 3993
def target
  @target ||= process_target(@data['target_id'], @target_type)
end
user() click to toggle source

@return [Member, User] the user that authored this action. Can be a User object if the user no longer exists in the server.

# File lib/discordrb/data.rb, line 3998
def user
  @user ||= @server.member(@data['user_id'].to_i) || @bot.user(@data['user_id'].to_i) || @logs.user(@data['user_id'].to_i)
end
Also aliased as: author