class Discordrb::AuditLogs::Entry
An entry in a server’s audit logs.
Attributes
@return [Symbol] the action that was performed.
@return [Symbol] the type action that was performed. (:create, :delete, :update, :unknown)
@return [Integer, nil] the amount of messages deleted. Only present if the action is ‘:message_delete`.
@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`.
@return [Integer, nil] the amount of messages deleted. Only present if the action is ‘:message_delete`.
@return [Integer, nil] the amount of days the members were inactive for. Only present if the action is ‘:member_prune`.
@return [Integer, nil] the amount of members removed. Only present if the action is ‘:member_prune`.
@return [String, nil] the reason for this action occurring.
@return [Symbol] the type of target being performed on. (:server, :channel, :user, :role, :invite, :webhook, :emoji, :unknown)
Public Class Methods
@!visibility private
# File lib/discordrb/data/audit_logs.rb, line 118 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 there's 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
@return [Channel, nil] the amount of messages deleted. Won’t be nil if the action is ‘:message_delete`.
# File lib/discordrb/data/audit_logs.rb, line 157 def channel return nil unless @channel_id @channel ||= @bot.channel(@channel_id, @server, bot, self) end
The inspect method is overwritten to give more useful output
# File lib/discordrb/data/audit_logs.rb, line 179 def inspect "<AuditLogs::Entry id=#{@id} key=#{@key} action=#{@action} reason=#{@reason} action_type=#{@action_type} target_type=#{@target_type} count=#{@count} days=#{@days} members_removed=#{@members_removed}>" end
Process action changes @note For internal use only @!visibility private
# File lib/discordrb/data/audit_logs.rb, line 186 def process_changes(changes) return unless changes changes.each do |element| change = Change.new(element, @server, @bot, self) @changes[change.key] = change end end
@!visibility private
# File lib/discordrb/data/audit_logs.rb, line 164 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] when :integration then @server.integrations.find { |integration| integration.id == id } end end
@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/audit_logs.rb, line 151 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