discorb 0.6.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,9 +4,9 @@ module Discorb
4
4
  #
5
5
  # Handles application commands.
6
6
  #
7
- module Command
7
+ module ApplicationCommand
8
8
  #
9
- # Module to handle commands.
9
+ # Module to handle application commands.
10
10
  #
11
11
  module Handler
12
12
  #
@@ -27,13 +27,13 @@ module Discorb
27
27
  # @param [Array<#to_s>, false, nil] guild_ids Guild IDs to set the command to. `false` to global command, `nil` to use default.
28
28
  # @param [Proc] block Command block.
29
29
  #
30
- # @return [Discorb::Command::Command::SlashCommand]
30
+ # @return [Discorb::ApplicationCommand::Command::SlashCommand] Command object.
31
31
  #
32
32
  # @see file:docs/application_command.md#register-slash-command
33
33
  # @see file:docs/cli/setup.md
34
34
  #
35
35
  def slash(command_name, description, options = {}, guild_ids: nil, &block)
36
- command = Discorb::Command::Command::SlashCommand.new(command_name, description, options, guild_ids, block, 1, "")
36
+ command = Discorb::ApplicationCommand::Command::SlashCommand.new(command_name, description, options, guild_ids, block, 1, "")
37
37
  @commands << command
38
38
  @bottom_commands << command
39
39
  command
@@ -46,17 +46,17 @@ module Discorb
46
46
  # @param [String] description Command description.
47
47
  # @param [Array<#to_s>, false, nil] guild_ids Guild IDs to set the command to. `false` to global command, `nil` to use default.
48
48
  #
49
- # @yield Block to execute as the command. It can be used to define sub-commands.
50
- # @yieldself [Discorb::Command::Command::GroupCommand] Group command.
49
+ # @yield Block to yield with the command.
50
+ # @yieldparam [Discorb::ApplicationCommand::Command::GroupCommand] group Group command.
51
51
  #
52
- # @return [Discorb::Command::Command::GroupCommand] Command object.
52
+ # @return [Discorb::ApplicationCommand::Command::GroupCommand] Command object.
53
53
  #
54
54
  # @see file:docs/slash_command.md
55
55
  # @see file:docs/cli/setup.md
56
56
  #
57
57
  def slash_group(command_name, description, guild_ids: nil, &block)
58
- command = Discorb::Command::Command::GroupCommand.new(command_name, description, guild_ids, nil, self)
59
- command.instance_eval(&block) if block_given?
58
+ command = Discorb::ApplicationCommand::Command::GroupCommand.new(command_name, description, guild_ids, nil, self)
59
+ command.yield_self(&block) if block_given?
60
60
  @commands << command
61
61
  command
62
62
  end
@@ -68,13 +68,13 @@ module Discorb
68
68
  # @param [Array<#to_s>, false, nil] guild_ids Guild IDs to set the command to. `false` to global command, `nil` to use default.
69
69
  # @param [Proc] block Command block.
70
70
  # @yield [interaction, message] Block to execute.
71
- # @yieldparam [Discorb::CommandInteraction::UserMenuCommand] interaction Interaction object.
71
+ # @yieldparam [Discorb::ApplicationCommandInteraction::UserMenuCommand] interaction Interaction object.
72
72
  # @yieldparam [Discorb::Message] message Message object.
73
73
  #
74
- # @return [Discorb::Command::Command] Command object.
74
+ # @return [Discorb::ApplicationCommand::Command] Command object.
75
75
  #
76
76
  def message_command(command_name, guild_ids: nil, &block)
77
- command = Discorb::Command::Command.new(command_name, guild_ids, block, 3)
77
+ command = Discorb::ApplicationCommand::Command.new(command_name, guild_ids, block, 3)
78
78
  @commands << command
79
79
  command
80
80
  end
@@ -86,13 +86,13 @@ module Discorb
86
86
  # @param [Array<#to_s>, false, nil] guild_ids Guild IDs to set the command to. `false` to global command, `nil` to use default.
87
87
  # @param [Proc] block Command block.
88
88
  # @yield [interaction, user] Block to execute.
89
- # @yieldparam [Discorb::CommandInteraction::UserMenuCommand] interaction Interaction object.
89
+ # @yieldparam [Discorb::ApplicationCommandInteraction::UserMenuCommand] interaction Interaction object.
90
90
  # @yieldparam [Discorb::User] user User object.
91
91
  #
92
- # @return [Discorb::Command::Command] Command object.
92
+ # @return [Discorb::ApplicationCommand::Command] Command object.
93
93
  #
94
94
  def user_command(command_name, guild_ids: nil, &block)
95
- command = Discorb::Command::Command.new(command_name, guild_ids, block, 2)
95
+ command = Discorb::ApplicationCommand::Command.new(command_name, guild_ids, block, 2)
96
96
  @commands << command
97
97
  command
98
98
  end
@@ -163,7 +163,7 @@ module Discorb
163
163
  @guild_ids = guild_ids&.map(&:to_s)
164
164
  @block = block
165
165
  @raw_type = type
166
- @type = Discorb::Command::Command.types[type]
166
+ @type = Discorb::ApplicationCommand::Command.types[type]
167
167
  @type_raw = type
168
168
  @id_map = Discorb::Dictionary.new
169
169
  end
@@ -251,7 +251,7 @@ module Discorb
251
251
  # Represents the command with subcommands.
252
252
  #
253
253
  class GroupCommand < Command
254
- # @return [Array<Discorb::Command::Command::SlashCommand, Discorb::Command::Command::SubcommandGroup>] The subcommands of the command.
254
+ # @return [Array<Discorb::ApplicationCommand::Command::SlashCommand, Discorb::ApplicationCommand::Command::SubcommandGroup>] The subcommands of the command.
255
255
  attr_reader :commands
256
256
  # @return [String] The description of the command.
257
257
  attr_reader :description
@@ -268,11 +268,11 @@ module Discorb
268
268
  #
269
269
  # Add new subcommand.
270
270
  #
271
- # @param (see Discorb::Command::Handler#slash)
272
- # @return [Discorb::Command::Command::SlashCommand] The added subcommand.
271
+ # @param (see Discorb::ApplicationCommand::Handler#slash)
272
+ # @return [Discorb::ApplicationCommand::Command::SlashCommand] The added subcommand.
273
273
  #
274
274
  def slash(command_name, description, options = {}, &block)
275
- command = Discorb::Command::Command::SlashCommand.new(command_name, description, options, [], block, 1, @name)
275
+ command = Discorb::ApplicationCommand::Command::SlashCommand.new(command_name, description, options, [], block, 1, @name)
276
276
  @client.bottom_commands << command
277
277
  @commands << command
278
278
  command
@@ -284,16 +284,16 @@ module Discorb
284
284
  # @param [String] command_name Group name.
285
285
  # @param [String] description Group description.
286
286
  #
287
- # @yield Block to execute as the command. It can be used to define sub-commands.
288
- # @yieldself [Discorb::Command::Command::SubcommandGroup] Group command.
287
+ # @yield Block to yield with the command.
288
+ # @yieldparam [Discorb::ApplicationCommand::Command::SubcommandGroup] group Group command.
289
289
  #
290
- # @return [Discorb::Command::Command::SubcommandGroup] Command object.
290
+ # @return [Discorb::ApplicationCommand::Command::SubcommandGroup] Command object.
291
291
  #
292
292
  # @see file:docs/slash_command.md
293
293
  #
294
294
  def group(command_name, description, &block)
295
- command = Discorb::Command::Command::SubcommandGroup.new(command_name, description, @name, @client)
296
- command.instance_eval(&block) if block_given?
295
+ command = Discorb::ApplicationCommand::Command::SubcommandGroup.new(command_name, description, @name, @client)
296
+ command.yield_self(&block) if block_given?
297
297
  @commands << command
298
298
  command
299
299
  end
@@ -342,7 +342,7 @@ module Discorb
342
342
  # Represents the subcommand group.
343
343
  #
344
344
  class SubcommandGroup < GroupCommand
345
- # @return [Array<Discorb::Command::Command::SlashCommand>] The subcommands of the command.
345
+ # @return [Array<Discorb::ApplicationCommand::Command::SlashCommand>] The subcommands of the command.
346
346
  attr_reader :commands
347
347
 
348
348
  # @!visibility private
@@ -359,11 +359,11 @@ module Discorb
359
359
 
360
360
  #
361
361
  # Add new subcommand.
362
- # @param (see Discorb::Command::Handler#slash)
363
- # @return [Discorb::Command::Command::SlashCommand] The added subcommand.
362
+ # @param (see Discorb::ApplicationCommand::Handler#slash)
363
+ # @return [Discorb::ApplicationCommand::Command::SlashCommand] The added subcommand.
364
364
  #
365
365
  def slash(command_name, description, options = {}, &block)
366
- command = Discorb::Command::Command::SlashCommand.new(command_name, description, options, [], block, 1, @parent + " " + @name)
366
+ command = Discorb::ApplicationCommand::Command::SlashCommand.new(command_name, description, options, [], block, 1, @parent + " " + @name)
367
367
  @commands << command
368
368
  @client.bottom_commands << command
369
369
  command
@@ -41,7 +41,7 @@ module Discorb
41
41
  attr_reader :messages
42
42
  # @return [Discorb::Logger] The logger.
43
43
  attr_reader :log
44
- # @return [Array<Discorb::Command::Command>] The commands that the client is using.
44
+ # @return [Array<Discorb::ApplicationCommand::Command>] The commands that the client is using.
45
45
  attr_reader :commands
46
46
  # @return [Float] The ping of the client.
47
47
  # @note This will be calculated from heartbeat and heartbeat_ack.
@@ -91,6 +91,7 @@ module Discorb
91
91
  @commands = []
92
92
  @bottom_commands = []
93
93
  @status = :initialized
94
+ set_default_events
94
95
  end
95
96
 
96
97
  #
@@ -99,14 +100,15 @@ module Discorb
99
100
  #
100
101
  # @param [Symbol] event_name The name of the event.
101
102
  # @param [Symbol] id Custom ID of the event.
102
- # @param [Hash] discriminator The discriminator of the event.
103
+ # @param [Hash] metadata The metadata of the event.
103
104
  # @param [Proc] block The block to execute when the event is triggered.
104
105
  #
105
106
  # @return [Discorb::Event] The event.
106
107
  #
107
- def on(event_name, id: nil, **discriminator, &block)
108
- ne = Event.new(block, id, discriminator)
108
+ def on(event_name, id: nil, **metadata, &block)
109
+ ne = Event.new(block, id, metadata)
109
110
  @events[event_name] ||= []
111
+ @events[event_name].delete_if { |e| e.metadata[:override] }
110
112
  @events[event_name] << ne
111
113
  ne
112
114
  end
@@ -118,12 +120,9 @@ module Discorb
118
120
  #
119
121
  # @return [Discorb::Event] The event.
120
122
  #
121
- def once(event_name, id: nil, **discriminator, &block)
122
- discriminator[:once] = true
123
- ne = Event.new(block, id, discriminator)
124
- @events[event_name] ||= []
125
- @events[event_name] << ne
126
- ne
123
+ def once(event_name, id: nil, **metadata, &block)
124
+ metadata[:once] = true
125
+ on(event_name, id: id, **metadata, &block)
127
126
  end
128
127
 
129
128
  #
@@ -174,23 +173,17 @@ module Discorb
174
173
  end
175
174
  @log.debug "Dispatching event #{event_name}"
176
175
  events.each do |block|
177
- lambda { |event_args|
176
+ Async do
178
177
  Async(annotation: "Discorb event: #{event_name}") do |task|
179
178
  if block.is_a?(Discorb::Event)
180
- @events[event_name].delete(block) if block.discriminator[:once]
179
+ @events[event_name].delete(block) if block.metadata[:once]
181
180
  end
182
- block.call(*event_args)
181
+ block.call(*args)
183
182
  @log.debug "Dispatched proc with ID #{block.id.inspect}"
184
183
  rescue StandardError, ScriptError => e
185
- message = "An error occurred while dispatching proc with ID #{block.id.inspect}\n#{e.full_message}"
186
- dispatch(:error, event_name, event_args, e)
187
- if @log.out
188
- @log.error message
189
- else
190
- warn message
191
- end
184
+ dispatch(:error, event_name, args, e)
192
185
  end
193
- }.call(args)
186
+ end
194
187
  end
195
188
  end
196
189
  end
@@ -369,10 +362,11 @@ module Discorb
369
362
  def extend(mod)
370
363
  if mod.respond_to?(:events)
371
364
  @events.each_value do |event|
372
- event.delete_if { |c| c.discriminator[:extension] == mod.name }
365
+ event.delete_if { |c| c.metadata[:extension] == mod.name }
373
366
  end
374
367
  mod.events.each do |name, events|
375
- @events[name] = [] if @events[name].nil?
368
+ @events[name] ||= []
369
+ @events[name].delete_if { |c| c.metadata[:override] }
376
370
  events.each do |event|
377
371
  @events[name] << event
378
372
  end
@@ -391,7 +385,7 @@ module Discorb
391
385
  end
392
386
 
393
387
  include Discorb::Gateway::Handler
394
- include Discorb::Command::Handler
388
+ include Discorb::ApplicationCommand::Handler
395
389
 
396
390
  #
397
391
  # Starts the client.
@@ -483,5 +477,12 @@ module Discorb
483
477
  @main_task.stop
484
478
  end
485
479
  end
480
+
481
+ def set_default_events
482
+ on :error, override: true do |event_name, _args, e|
483
+ message = "An error occurred while dispatching #{event_name}:\n#{e.full_message}"
484
+ @log.error message, fallback: $stderr
485
+ end
486
+ end
486
487
  end
487
488
  end
data/lib/discorb/color.rb CHANGED
@@ -130,35 +130,65 @@ module Discorb
130
130
  #
131
131
  # Create a color from a Discord's color.
132
132
  # Currently these colors are supported:
133
- # - teal (0x1abc9c)
134
- # - dark_teal (0x11806a)
135
- # - green (0x2ecc71)
136
- # - dark_green (0x1f8b4c)
137
- # - blue (0x3498db)
138
- # - dark_blue (0x206694)
139
- # - purple (0x9b59b6)
140
- # - dark_purple (0x71368a)
141
- # - magenta (0xe91e63)
142
- # - dark_magenta (0xad1457)
143
- # - gold (0xf1c40f)
144
- # - dark_gold (0xc27c0e)
145
- # - orange (0xe67e22)
146
- # - dark_orange (0xa84300)
147
- # - red (0xe74c3c)
148
- # - dark_red (0x992d22)
149
- # - lighter_grey (0x95a5a6)
150
- # - lighter_gray (0x95a5a6)
151
- # - dark_grey (0x607d8b)
152
- # - dark_gray (0x607d8b)
153
- # - light_grey (0x979c9f)
154
- # - light_gray (0x979c9f)
155
- # - darker_grey (0x546e7a)
156
- # - darker_gray (0x546e7a)
157
- # - og_blurple (0x7289da)
158
- # - blurple (0x5865f2)
159
- # - greyple (0x99aab5)
160
- # - dark_theme (0x36393f)
161
- # - fuchsia (0xeb459e)
133
+ # | Color Name | Hexadecimal |
134
+ # |------------|------------|
135
+ # | `:teal` | `#1abc9c` |
136
+ # | `:dark_teal` | `#11806a` |
137
+ # | `:green` | `#2ecc71` |
138
+ # | `:dark_green` | `#1f8b4c` |
139
+ # | `:blue` | `#3498db` |
140
+ # | `:dark_blue` | `#206694` |
141
+ # | `:purple` | `#9b59b6` |
142
+ # | `:dark_purple` | `#71368a` |
143
+ # | `:magenta` | `#e91e63` |
144
+ # | `:dark_magenta` | `#ad1457` |
145
+ # | `:gold` | `#f1c40f` |
146
+ # | `:dark_gold` | `#c27c0e` |
147
+ # | `:orange` | `#e67e22` |
148
+ # | `:dark_orange` | `#a84300` |
149
+ # | `:red` | `#e74c3c` |
150
+ # | `:dark_red` | `#992d22` |
151
+ # | `:lighter_grey` | `#95a5a6` |
152
+ # | `:lighter_gray` | `#95a5a6` |
153
+ # | `:dark_grey` | `#607d8b` |
154
+ # | `:dark_gray` | `#607d8b` |
155
+ # | `:light_grey` | `#979c9f` |
156
+ # | `:light_gray` | `#979c9f` |
157
+ # | `:darker_grey` | `#546e7a` |
158
+ # | `:darker_gray` | `#546e7a` |
159
+ # | `:og_blurple` | `#7289da` |
160
+ # | `:blurple` | `#5865f2` |
161
+ # | `:greyple` | `#99aab5` |
162
+ # | `:dark_theme` | `#36393f` |
163
+ # | `:fuchsia` | `#eb459e` |
164
+ # | `:dark_teal` | `#11806a` |
165
+ # | `:green` | `#2ecc71` |
166
+ # | `:dark_green` | `#1f8b4c` |
167
+ # | `:blue` | `#3498db` |
168
+ # | `:dark_blue` | `#206694` |
169
+ # | `:purple` | `#9b59b6` |
170
+ # | `:dark_purple` | `#71368a` |
171
+ # | `:magenta` | `#e91e63` |
172
+ # | `:dark_magenta` | `#ad1457` |
173
+ # | `:gold` | `#f1c40f` |
174
+ # | `:dark_gold` | `#c27c0e` |
175
+ # | `:orange` | `#e67e22` |
176
+ # | `:dark_orange` | `#a84300` |
177
+ # | `:red` | `#e74c3c` |
178
+ # | `:dark_red` | `#992d22` |
179
+ # | `:lighter_grey` | `#95a5a6` |
180
+ # | `:lighter_gray` | `#95a5a6` |
181
+ # | `:dark_grey` | `#607d8b` |
182
+ # | `:dark_gray` | `#607d8b` |
183
+ # | `:light_grey` | `#979c9f` |
184
+ # | `:light_gray` | `#979c9f` |
185
+ # | `:darker_grey` | `#546e7a` |
186
+ # | `:darker_gray` | `#546e7a` |
187
+ # | `:og_blurple` | `#7289da` |
188
+ # | `:blurple` | `#5865f2` |
189
+ # | `:greyple` | `#99aab5` |
190
+ # | `:dark_theme` | `#36393f` |
191
+ # | `:fuchsia` | `#eb459e` |
162
192
  #
163
193
  # @param [Symbol] color A Discord color name.
164
194
  #
@@ -4,7 +4,7 @@ module Discorb
4
4
  # @return [String] The API base URL.
5
5
  API_BASE_URL = "https://discord.com/api/v9"
6
6
  # @return [String] The version of discorb.
7
- VERSION = "0.6.0"
7
+ VERSION = "0.7.2"
8
8
  # @return [String] The user agent for the bot.
9
9
  USER_AGENT = "DiscordBot (https://github.com/discorb-lib/discorb #{VERSION}) Ruby/#{RUBY_VERSION}"
10
10
 
data/lib/discorb/embed.rb CHANGED
@@ -93,18 +93,18 @@ module Discorb
93
93
  # @return [Hash] Converted embed.
94
94
  #
95
95
  def to_hash
96
- {
97
- title: @title,
98
- description: @description,
99
- url: @url,
100
- timestamp: @timestamp&.iso8601,
101
- color: @color&.to_i,
102
- footer: @footer&.to_hash,
103
- image: @image&.to_hash,
104
- thumbnail: @thumbnail&.to_hash,
105
- author: @author&.to_hash,
106
- fields: @fields&.map { |f| f.to_hash },
107
- }
96
+ ret = { type: "rich" }
97
+ ret[:title] = @title if @title
98
+ ret[:description] = @description if @description
99
+ ret[:url] = @url if @url
100
+ ret[:timestamp] = @timestamp&.iso8601 if @timestamp
101
+ ret[:color] = @color&.to_i if @color
102
+ ret[:footer] = @footer&.to_hash if @footer
103
+ ret[:image] = @image&.to_hash if @image
104
+ ret[:thumbnail] = @thumbnail&.to_hash if @thumbnail
105
+ ret[:author] = @author&.to_hash if @author
106
+ ret[:fields] = @fields&.map { |f| f.to_hash } if @fields.any?
107
+ ret
108
108
  end
109
109
 
110
110
  #
data/lib/discorb/error.rb CHANGED
@@ -94,7 +94,7 @@ module Discorb
94
94
  @client.close!
95
95
  DiscorbError.instance_method(:initialize).bind(self).call(<<~MESSAGE)
96
96
  The client is banned from CloudFlare.
97
- Hint: Try to increase the number of requests per second, e.g. Use sleep in between requests.
97
+ Hint: Try to decrease the number of requests per second, e.g. Use sleep in between requests.
98
98
  MESSAGE
99
99
  end
100
100
  end
data/lib/discorb/event.rb CHANGED
@@ -11,17 +11,17 @@ module Discorb
11
11
  attr_reader :block
12
12
  # @return [Symbol] the event id.
13
13
  attr_reader :id
14
- # @return [Hash] the event discriminator.
15
- attr_reader :discriminator
14
+ # @return [Hash] the event metadata.
15
+ attr_reader :metadata
16
16
  # @return [Boolean] whether the event is once or not.
17
17
  attr_reader :once
18
18
  alias once? once
19
19
 
20
- def initialize(block, id, discriminator)
20
+ def initialize(block, id, metadata)
21
21
  @block = block
22
22
  @id = id
23
- @once = discriminator.fetch(:once, false)
24
- @discriminator = discriminator
23
+ @once = metadata.fetch(:once, false)
24
+ @metadata = metadata
25
25
  @rescue = nil
26
26
  end
27
27
 
@@ -8,7 +8,7 @@ module Discorb
8
8
  # @abstract
9
9
  #
10
10
  module Extension
11
- include Discorb::Command::Handler
11
+ include Discorb::ApplicationCommand::Handler
12
12
  undef setup_commands
13
13
 
14
14
  @events = {}
@@ -19,18 +19,18 @@ module Discorb
19
19
  #
20
20
  # @param [Symbol] event_name The name of the event.
21
21
  # @param [Symbol] id The id of the event. Used to delete the event.
22
- # @param [Hash] discriminator Other discriminators.
22
+ # @param [Hash] metadata Other metadata.
23
23
  # @param [Proc] block The block to execute when the event is triggered.
24
24
  #
25
25
  # @return [Discorb::Event] The event.
26
26
  #
27
- def event(event_name, id: nil, **discriminator, &block)
27
+ def event(event_name, id: nil, **metadata, &block)
28
28
  raise ArgumentError, "Event name must be a symbol" unless event_name.is_a?(Symbol)
29
29
  raise ArgumentError, "block must be a Proc" unless block.is_a?(Proc)
30
30
 
31
31
  @events[event_name] ||= []
32
- discriminator[:extension] = self.name
33
- @events[event_name] << Discorb::Event.new(block, id, discriminator)
32
+ metadata[:extension] = self.name
33
+ @events[event_name] << Discorb::Event.new(block, id, metadata)
34
34
  end
35
35
 
36
36
  #
@@ -38,18 +38,18 @@ module Discorb
38
38
  #
39
39
  # @param [Symbol] event_name The name of the event.
40
40
  # @param [Symbol] id The id of the event. Used to delete the event.
41
- # @param [Hash] discriminator Other discriminators.
41
+ # @param [Hash] metadata Other metadata.
42
42
  # @param [Proc] block The block to execute when the event is triggered.
43
43
  #
44
44
  # @return [Discorb::Event] The event.
45
45
  #
46
- def once_event(event_name, id: nil, **discriminator, &block)
47
- event(event_name, id: id, once: true, **discriminator, &block)
46
+ def once_event(event_name, id: nil, **metadata, &block)
47
+ event(event_name, id: id, once: true, **metadata, &block)
48
48
  end
49
49
 
50
50
  # @return [Hash{Symbol => Array<Discorb::Event>}] The events of the extension.
51
51
  attr_reader :events
52
- # @return [Array<Discorb::Command::Command>] The commands of the extension.
52
+ # @return [Array<Discorb::ApplicationCommand::Command>] The commands of the extension.
53
53
  attr_reader :commands
54
54
  # @private
55
55
  attr_reader :bottom_commands
@@ -53,6 +53,12 @@ module Discorb
53
53
  attr_reader :member
54
54
  # @return [Discorb::UnicodeEmoji, Discorb::PartialEmoji] The emoji that was reacted with.
55
55
  attr_reader :emoji
56
+ # @macro client_cache
57
+ # @return [Discorb::Member, Discorb::User] The user or member who reacted.
58
+ attr_reader :fired_by
59
+
60
+ alias reactor fired_by
61
+ alias from fired_by
56
62
 
57
63
  # @!visibility private
58
64
  def initialize(client, data)
@@ -79,6 +85,8 @@ module Discorb
79
85
  end
80
86
  end
81
87
 
88
+ @fired_by = @member || @user || @client.users[data[:user_id]]
89
+
82
90
  @message = client.messages[data[:message_id]]
83
91
  @emoji = data[:emoji][:id].nil? ? UnicodeEmoji.new(data[:emoji][:name]) : PartialEmoji.new(data[:emoji])
84
92
  end
@@ -355,6 +363,9 @@ module Discorb
355
363
  class TypingStartEvent < GatewayEvent
356
364
  # @return [Discorb::Snowflake] The ID of the channel the user is typing in.
357
365
  attr_reader :user_id
366
+ # @macro client_cache
367
+ # @return [Discorb::Member] The member that is typing.
368
+ attr_reader :member
358
369
 
359
370
  # @!attribute [r] channel
360
371
  # @macro client_cache
@@ -365,6 +376,9 @@ module Discorb
365
376
  # @!attribute [r] user
366
377
  # @macro client_cache
367
378
  # @return [Discorb::User] The user that is typing.
379
+ # @!attribute [r] fired_by
380
+ # @macro client_cache
381
+ # @return [Discorb::Member, Discorb::User] The member or user that started typing.
368
382
 
369
383
  # @!visibility private
370
384
  def initialize(client, data)
@@ -388,6 +402,12 @@ module Discorb
388
402
  def guild
389
403
  @client.guilds[@guild_id]
390
404
  end
405
+
406
+ def fired_by
407
+ @member || user
408
+ end
409
+
410
+ alias from fired_by
391
411
  end
392
412
 
393
413
  #
@@ -584,10 +604,10 @@ module Discorb
584
604
  @session_id = data[:session_id]
585
605
  @user = ClientUser.new(self, data[:user])
586
606
  @uncached_guilds = data[:guilds].map { |g| g[:id] }
587
- if @uncached_guilds == []
607
+ if @uncached_guilds == [] or !@intents.guilds
588
608
  @ready = true
589
609
  dispatch(:ready)
590
- @log.info("Guilds were cached")
610
+ @log.info("Successfully connected to Discord.")
591
611
  end
592
612
  @tasks << handle_heartbeat(@heartbeat_interval)
593
613
  when "GUILD_CREATE"
@@ -597,7 +617,7 @@ module Discorb
597
617
  if @uncached_guilds == []
598
618
  @ready = true
599
619
  dispatch(:ready)
600
- @log.info("Guilds were cached")
620
+ @log.info("Successfully connected to Discord, and cached all guilds.")
601
621
  end
602
622
  elsif @guilds.has?(data[:id])
603
623
  @guilds[data[:id]].send(:_set_data, data)
@@ -80,7 +80,7 @@ module Discorb
80
80
  @enable_emoticons = data[:enable_emoticons]
81
81
  @expire_behavior = self.class.expire_behavior[data[:expire_behavior]]
82
82
  @expire_grace_period = data[:expire_grace_period]
83
- @user = client.users[data[:user].to_i]
83
+ @user = @client.users[data[:user].to_i]
84
84
  @account = Account.new(data[:account])
85
85
  @subscriber_count = data[:subscriber_count]
86
86
  @revoked = data[:revoked]
@@ -26,7 +26,6 @@ module Discorb
26
26
  #
27
27
  # @param guilds [Boolean] Whether guild related events are enabled.
28
28
  # @param members [Boolean] Whether guild members related events are enabled.
29
- # @note You must enable members intent on developers portal.
30
29
  # @param bans [Boolean] Whether guild ban related events are enabled.
31
30
  # @param emojis [Boolean] Whether guild emojis related events are enabled.
32
31
  # @param integrations [Boolean] Whether guild integration related events are enabled.
@@ -34,13 +33,14 @@ module Discorb
34
33
  # @param invites [Boolean] Whether guild invite related events are enabled.
35
34
  # @param voice_states [Boolean] Whether guild voice state related events are enabled.
36
35
  # @param presences [Boolean] Whether guild presences related events are enabled.
37
- # @note You must enable members intent on developers portal.
38
36
  # @param messages [Boolean] Whether guild messages related events are enabled.
39
37
  # @param reactions [Boolean] Whether guild reaction related events are enabled.
40
38
  # @param dm_messages [Boolean] Whether dm messages related events are enabled.
41
39
  # @param dm_reactions [Boolean] Whether dm reactions related events are enabled.
42
40
  # @param dm_typing [Boolean] Whether dm typing related events are enabled.
43
41
  #
42
+ # @note You must enable privileged intents to use `members` and/or `presences` intents.
43
+ #
44
44
  def initialize(guilds: true,
45
45
  members: false,
46
46
  bans: true,