class Discordrb::AuditLogs

A server's audit logs

Constants

ACTIONS

The numbers associated with the type of action.

Attributes

entries[R]

@return [Array<Entry>] the entries listed in the audit logs.

users[R]

@return [Hash<String => User>] the users included in the audit logs.

webhooks[R]

@return [Hash<String => Webhook>] the webhooks included in the audit logs.

Public Class Methods

action_type_for(action) click to toggle source

Find the type of action by its action number @note For internal use only @!visibility private

# File lib/discordrb/data.rb, line 4181
def self.action_type_for(action)
  action = ACTIONS[action]
  return :create if %i[channel_create channel_overwrite_create member_ban_add role_create invite_create webhook_create emoji_create].include?(action)
  return :delete if %i[channel_delete channel_overwrite_delete member_kick member_prune member_ban_remove role_delete invite_delete webhook_delete emoji_delete message_delete].include?(action)
  return :update if %i[server_update channel_update channel_overwrite_update member_update member_role_update role_update invite_update webhook_update emoji_update].include?(action)

  :unknown
end
new(server, bot, data) click to toggle source

@!visibility private

# File lib/discordrb/data.rb, line 3924
def initialize(server, bot, data)
  @bot = bot
  @server = server
  @users = {}
  @webhooks = {}
  @entries = data['audit_log_entries'].map { |entry| Entry.new(self, @server, @bot, entry) }

  process_users(data['users'])
  process_webhooks(data['webhooks'])
end
target_type_for(action) click to toggle source

Find the type of target by it's action number @note For internal use only @!visibility private

# File lib/discordrb/data.rb, line 4164
def self.target_type_for(action)
  case action
  when 1..9 then :server
  when 10..19 then :channel
  when 20..29 then :user
  when 30..39 then :role
  when 40..49 then :invite
  when 50..59 then :webhook
  when 60..69 then :emoji
  when 70..79 then :message
  else :unknown
  end
end

Public Instance Methods

first()
Alias for: latest
latest() click to toggle source

@return [Entry] the latest entry in the audit logs.

# File lib/discordrb/data.rb, line 4122
def latest
  @entries.first
end
Also aliased as: first
process_users(users) click to toggle source

Process user objects given by the request @note For internal use only @!visibility private

# File lib/discordrb/data.rb, line 4144
def process_users(users)
  users.each do |element|
    user = User.new(element, @bot)
    @users[user.id] = user
  end
end
process_webhooks(webhooks) click to toggle source

Process webhook objects given by the request @note For internal use only @!visibility private

# File lib/discordrb/data.rb, line 4154
def process_webhooks(webhooks)
  webhooks.each do |element|
    webhook = Webhook.new(element, @bot)
    @webhooks[webhook.id] = webhook
  end
end
user(id) click to toggle source

Gets a user in the audit logs data based on user ID @note This only uses data given by the audit logs request @param id [#resolve_id] The user ID to look for

# File lib/discordrb/data.rb, line 4130
def user(id)
  @users[id.resolve_id]
end
webhook(id) click to toggle source

Gets a webhook in the audit logs data based on webhook ID @note This only uses data given by the audit logs request @param id [#resolve_id] The webhook ID to look for

# File lib/discordrb/data.rb, line 4137
def webhook(id)
  @webhooks[id.resolve_id]
end