Class: DiscordRDA::Event
- Inherits:
-
Object
- Object
- DiscordRDA::Event
- Defined in:
- lib/discord_rda/event/base.rb
Overview
Base event class for all Discord events. Events are immutable data objects.
Direct Known Subclasses
AutoModerationActionExecutionEvent, AutoModerationRuleCreateEvent, AutoModerationRuleDeleteEvent, AutoModerationRuleUpdateEvent, ChannelCreateEvent, ChannelDeleteEvent, ChannelPinsUpdateEvent, ChannelUpdateEvent, EntitlementCreateEvent, EntitlementDeleteEvent, EntitlementUpdateEvent, GuildAuditLogEntryCreateEvent, GuildBanAddEvent, GuildBanRemoveEvent, GuildCreateEvent, GuildDeleteEvent, GuildIntegrationsUpdateEvent, GuildMemberAddEvent, GuildMemberRemoveEvent, GuildMemberUpdateEvent, GuildRoleCreateEvent, GuildRoleDeleteEvent, GuildRoleUpdateEvent, GuildScheduledEventCreateEvent, GuildScheduledEventDeleteEvent, GuildScheduledEventUpdateEvent, GuildScheduledEventUserAddEvent, GuildScheduledEventUserRemoveEvent, GuildUpdateEvent, InteractionCreateEvent, MessageCreateEvent, MessageDeleteBulkEvent, MessageDeleteEvent, MessageReactionAddEvent, MessageReactionRemoveAllEvent, MessageReactionRemoveEvent, MessageUpdateEvent, PresenceUpdateEvent, ReadyEvent, ResumedEvent, StageInstanceCreateEvent, StageInstanceDeleteEvent, StageInstanceUpdateEvent, ThreadCreateEvent, ThreadDeleteEvent, ThreadListSyncEvent, ThreadMemberUpdateEvent, ThreadMembersUpdateEvent, ThreadUpdateEvent, TypingStartEvent, UserUpdateEvent, VoiceServerUpdateEvent, VoiceStateUpdateEvent, WebhooksUpdateEvent
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
Raw event data.
-
#shard_id ⇒ Integer
readonly
Shard ID where event originated.
-
#timestamp ⇒ Time
readonly
Event timestamp.
-
#type ⇒ String
readonly
Event type.
Instance Method Summary collapse
-
#created_at ⇒ Time?
Get creation time from data if available.
-
#initialize(type, data, shard_id: 0) ⇒ Event
constructor
Initialize event.
-
#inspect ⇒ String
Inspect.
-
#to_h ⇒ Hash
Convert to hash.
Constructor Details
#initialize(type, data, shard_id: 0) ⇒ Event
Initialize event
24 25 26 27 28 29 |
# File 'lib/discord_rda/event/base.rb', line 24 def initialize(type, data, shard_id: 0) @type = type.to_s @data = data.each_with_object({}) { |(key, value), hash| hash[key.to_s] = value }.freeze @shard_id = shard_id @timestamp = Time.now.utc.freeze end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns Raw event data.
15 16 17 |
# File 'lib/discord_rda/event/base.rb', line 15 def data @data end |
#shard_id ⇒ Integer (readonly)
Returns Shard ID where event originated.
12 13 14 |
# File 'lib/discord_rda/event/base.rb', line 12 def shard_id @shard_id end |
#timestamp ⇒ Time (readonly)
Returns Event timestamp.
18 19 20 |
# File 'lib/discord_rda/event/base.rb', line 18 def @timestamp end |
#type ⇒ String (readonly)
Returns Event type.
9 10 11 |
# File 'lib/discord_rda/event/base.rb', line 9 def type @type end |
Instance Method Details
#created_at ⇒ Time?
Get creation time from data if available
33 34 35 36 37 |
# File 'lib/discord_rda/event/base.rb', line 33 def created_at return nil unless @data['id'] Snowflake.new(@data['id']). end |
#inspect ⇒ String
Inspect
52 53 54 |
# File 'lib/discord_rda/event/base.rb', line 52 def inspect "#<#{self.class.name} type=#{@type} shard=#{@shard_id}>" end |
#to_h ⇒ Hash
Convert to hash
41 42 43 44 45 46 47 48 |
# File 'lib/discord_rda/event/base.rb', line 41 def to_h { type: @type, shard_id: @shard_id, timestamp: @timestamp.iso8601, data: @data } end |