class Discordrb::AuditLogs
A server’s audit logs
Constants
- ACTIONS
The numbers associated with the type of action.
- CREATE_ACTIONS
@!visibility private
- DELETE_ACTIONS
@!visibility private
- UPDATE_ACTIONS
@!visibility private
Attributes
@return [Array<Entry>] the entries listed in the audit logs.
@return [Hash<String => User>] the users included in the audit logs.
@return [Hash<String => Webhook>] the webhooks included in the audit logs.
Public Class Methods
Find the type of action by its action number @note For internal use only @!visibility private
# File lib/discordrb/data/audit_logs.rb, line 336 def self.action_type_for(action) action = ACTIONS[action] return :create if CREATE_ACTIONS.include?(action) return :delete if DELETE_ACTIONS.include?(action) return :update if UPDATE_ACTIONS.include?(action) :unknown end
@!visibility private
# File lib/discordrb/data/audit_logs.rb, line 77 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
Find the type of target by it’s action number @note For internal use only @!visibility private
# File lib/discordrb/data/audit_logs.rb, line 318 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 when 80..89 then :integration else :unknown end end
Public Instance Methods
@return [Entry] the latest entry in the audit logs.
# File lib/discordrb/data/audit_logs.rb, line 276 def latest @entries.first end
Process user objects given by the request @note For internal use only @!visibility private
# File lib/discordrb/data/audit_logs.rb, line 298 def process_users(users) users.each do |element| user = User.new(element, @bot) @users[user.id] = user end end
Process webhook objects given by the request @note For internal use only @!visibility private
# File lib/discordrb/data/audit_logs.rb, line 308 def process_webhooks(webhooks) webhooks.each do |element| webhook = Webhook.new(element, @bot) @webhooks[webhook.id] = webhook end end
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 [String, Integer] The user ID to look for
# File lib/discordrb/data/audit_logs.rb, line 284 def user(id) @users[id.resolve_id] end
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 [String, Integer] The webhook ID to look for
# File lib/discordrb/data/audit_logs.rb, line 291 def webhook(id) @webhooks[id.resolve_id] end