discorb 0.5.1 → 0.5.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54c64c3d8d4c8293ba42d1c6ab6042b9c03b12f52b2cbdd92afb3ab483e82b8b
4
- data.tar.gz: ad9c479984defc53a872cf196bd7476f7838fe9f004be6d817e78b4b5ebf3fbd
3
+ metadata.gz: d6919eceb7431839769fc4bca402df56fef34e50d12f47f6cc8824e210bef95b
4
+ data.tar.gz: 8e50f4f53b5a1b52d3c4e29f9856cac2469a067c7d6005542a520081622d8da2
5
5
  SHA512:
6
- metadata.gz: fc9a269f561e1a53ce46dbf0a026ae34999633e966bc7f286383cb0583160a85e6aaf5a1d2ee8596e72a7454052a119e7db24394abdf689f744c0cef85b5e2a4
7
- data.tar.gz: f0d14f5f858848e3a3d4877a505e998da9a76b12d57b31000d28b827d3acb47c1a1025214315abe900fcce6cf043632af563f4e43c4f6e942020c6f1bf059145
6
+ metadata.gz: 45a3649f783094e691921a041428df1a7a1d368705a116240385b94e9d2b30983a232b47a5d702c50ae61a7a4b36ef3252f6b7f48992832c6f4073cadab08d26
7
+ data.tar.gz: 1a89fba62ef9b03db524eb6b57e409280c1888709e248df33cd1c42266c12ae534535a39c2765046a56eebd66adb5b8472f202115cf0e16cfcbbefee04e17e1a
data/Changelog.md CHANGED
@@ -111,4 +111,24 @@
111
111
 
112
112
  - Add: Can use block for defining group commands
113
113
  - Fix: Fix bug in subcommands
114
- - Fix: Fix bug in receiving commands
114
+ - Fix: Fix bug in receiving commands
115
+
116
+ ## 0.5.2
117
+
118
+ - Fix: Fix bug of registering commands
119
+ - Add: Add way to register commands in Extension
120
+
121
+ ## 0.5.3
122
+
123
+ - Add: Add way to handle raw events with `event_xxx`
124
+ - Add: Add `Client#session_id`
125
+ - Add: Add `Connectable`
126
+ - Fix: Fix error by sending DM
127
+
128
+ ## 0.5.4
129
+
130
+ - Fix: Fix issue of receiving component events
131
+
132
+ ## 0.5.5
133
+
134
+ - Fix: Fix some bugs
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- discorb (0.5.1)
4
+ discorb (0.5.5)
5
5
  async (~> 1.30.1)
6
6
  async-http (~> 0.56.5)
7
7
  async-websocket (~> 0.19.0)
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
  [![Document](https://img.shields.io/badge/Document-discord--lib.github.io-blue.svg)](https://discorb-lib.github.io/)
3
3
  [![Gem](https://img.shields.io/gem/dt/discorb?logo=rubygems&logoColor=fff)](https://rubygems.org/gems/discorb)
4
4
  [![Gem](https://img.shields.io/gem/v/discorb?logo=rubygems&logoColor=fff)](https://rubygems.org/gems/discorb)
5
- [![Discord](https://img.shields.io/discord/863581274916913193?logo=discord&logoColor=fff&color=5865f2&label=Discord)](https://discord.gg/hCP6zq8Vpj)
5
+ [![Discord](https://img.shields.io/discord/863581274916913193?logo=discord&logoColor=fff&color=5865f2&label=Discord)](https://discord.gg/hCP6zq8Vpj)
6
+ [![GitHub](https://img.shields.io/github/stars/discorb-lib/discorb?color=24292e&label=Stars&logo=GitHub&logoColor=fff)](https://github.com/discorb-lib/discorb)
6
7
 
7
8
  discorb is a Discord API wrapper for Ruby.
8
9
 
data/docs/events.md CHANGED
@@ -219,14 +219,13 @@ Fires when a guild integration is created.
219
219
  | ---------- | ----- | ----------- |
220
220
  |`integration`| {Discorb::Integration}| The created integration. |
221
221
 
222
- #### `integration_update(before, after)`
222
+ #### `integration_update(after)`
223
223
 
224
224
  Fires when a guild integration is updated.
225
225
 
226
226
 
227
227
  | Parameter | Type | Description |
228
228
  | ---------- | ----- | ----------- |
229
- |`before` | {Discorb::Integration}| The integration before the update. |
230
229
  |`after` | {Discorb::Integration}| The integration after the update. |
231
230
 
232
231
  #### `integration_delete(integration)`
data/docs/extension.md CHANGED
@@ -34,6 +34,33 @@ module MyExtension
34
34
  end
35
35
  ```
36
36
 
37
+ ## Register Command
38
+
39
+ Since v0.5.2, {Discorb::Extension} includes {Discorb::Command::Handler} module, so you can register command with {Discorb::Command::Handler#slash} and {Discorb::Command::Handler#slash_group}.
40
+
41
+ ```ruby
42
+ module MyExtension
43
+ extend Discorb::Extension
44
+
45
+ slash("command", "Command") do |interaction|
46
+ # ...
47
+ end
48
+
49
+ slash_group("group", "Group") do
50
+ slash("subcommand", "Subcommand") do |interaction|
51
+ # ...
52
+ end
53
+
54
+ group("subgroup", "Subcommand group") do
55
+ slash("group_subcommand", "Command in Subcommand group") do |interaction|
56
+ # ...
57
+ end
58
+ end
59
+ end
60
+ end
61
+ ```
62
+
63
+
37
64
  ## Load extension
38
65
 
39
66
  Use {Discorb::Client#extend} to load extension.
@@ -636,7 +636,6 @@ module Discorb
636
636
 
637
637
  #
638
638
  # Represents a voice channel.
639
- # @todo Implement connecting to voice channel.
640
639
  #
641
640
  class VoiceChannel < GuildChannel
642
641
  # @return [Integer] The bitrate of the voice channel.
@@ -645,6 +644,8 @@ module Discorb
645
644
  # @return [nil] If the user limit is not set.
646
645
  attr_reader :user_limit
647
646
 
647
+ include Connectable
648
+
648
649
  @channel_type = 2
649
650
  #
650
651
  # Edit the voice channel.
@@ -699,6 +700,8 @@ module Discorb
699
700
  # @!visibility private
700
701
  attr_reader :stage_instances
701
702
 
703
+ include Connectable
704
+
702
705
  # @!attribute [r] stage_instance
703
706
  # @return [Discorb::StageInstance] The stage instance of the channel.
704
707
 
@@ -49,6 +49,10 @@ module Discorb
49
49
  attr_reader :ping
50
50
  # @return [:initialized, :running, :closed] The status of the client.
51
51
  attr_reader :status
52
+ # @return [Integer] The session ID of connection.
53
+ attr_reader :session_id
54
+ # @private
55
+ attr_reader :bottom_commands
52
56
 
53
57
  #
54
58
  # Initializes a new client.
@@ -85,6 +89,7 @@ module Discorb
85
89
  @tasks = []
86
90
  @conditions = {}
87
91
  @commands = []
92
+ @bottom_commands = []
88
93
  @status = :initialized
89
94
  end
90
95
 
@@ -372,6 +377,14 @@ module Discorb
372
377
  @events[name] << event
373
378
  end
374
379
  end
380
+ @commands.delete_if do |cmd|
381
+ cmd.respond_to? :extension and cmd.extension == mod.name
382
+ end
383
+ mod.commands.each do |cmd|
384
+ cmd.define_singleton_method(:extension) { mod.name }
385
+ @commands << cmd
386
+ end
387
+ @bottom_commands += mod.bottom_commands
375
388
  mod.client = self
376
389
  end
377
390
  super(mod)
@@ -34,6 +34,7 @@ module Discorb
34
34
  def slash(command_name, description, options = {}, guild_ids: [], &block)
35
35
  command = Discorb::Command::Command::SlashCommand.new(command_name, description, options, guild_ids, block, 1, "")
36
36
  @commands << command
37
+ @bottom_commands << command
37
38
  command
38
39
  end
39
40
 
@@ -54,6 +55,7 @@ module Discorb
54
55
  def slash_group(command_name, description, guild_ids: [], &block)
55
56
  command = Discorb::Command::Command::GroupCommand.new(command_name, description, guild_ids, nil, self)
56
57
  command.instance_eval(&block) if block_given?
58
+ @commands << command
57
59
  command
58
60
  end
59
61
 
@@ -248,7 +250,7 @@ module Discorb
248
250
  def initialize(name, description, guild_ids, type, client)
249
251
  super(name, guild_ids, block, type)
250
252
  @description = description
251
- @commands = client.commands
253
+ @commands = []
252
254
  @client = client
253
255
  @id_map = Discorb::Dictionary.new
254
256
  end
@@ -261,42 +263,7 @@ module Discorb
261
263
  #
262
264
  def slash(command_name, description, options = {}, &block)
263
265
  command = Discorb::Command::Command::SlashCommand.new(command_name, description, options, [], block, 1, @name)
264
- options_payload = options.map do |name, value|
265
- ret = {
266
- type: case (value[:type].is_a?(Array) ? value[:type].first : value[:type])
267
- when String, :string
268
- 3
269
- when Integer
270
- 4
271
- when TrueClass, FalseClass, :boolean
272
- 5
273
- when Discorb::User, Discorb::Member, :user, :member
274
- 6
275
- when Discorb::Channel, :channel
276
- 7
277
- when Discorb::Role, :role
278
- 8
279
- when :mentionable
280
- 9
281
- when Float
282
- 10
283
- end,
284
- name: name,
285
- description: value[:description],
286
- required: !value[:optional],
287
- }
288
- if value[:type].is_a?(Array)
289
- ret[:choices] = value[:type]
290
- end
291
-
292
- ret
293
- end
294
- {
295
- name: @name,
296
- default_permission: true,
297
- description: @description,
298
- options: options_payload,
299
- }
266
+ @client.bottom_commands << command
300
267
  @commands << command
301
268
  command
302
269
  end
@@ -317,6 +284,7 @@ module Discorb
317
284
  def group(command_name, description, &block)
318
285
  command = Discorb::Command::Command::SubcommandGroup.new(command_name, description, @name, @client)
319
286
  command.instance_eval(&block) if block_given?
287
+ @commands << command
320
288
  command
321
289
  end
322
290
 
@@ -371,7 +339,7 @@ module Discorb
371
339
  def initialize(name, description, parent, client)
372
340
  super(name, description, [], 1, client)
373
341
 
374
- @commands = client.commands
342
+ @commands = []
375
343
  @parent = parent
376
344
  end
377
345
 
@@ -387,6 +355,7 @@ module Discorb
387
355
  def slash(command_name, description, options = {}, &block)
388
356
  command = Discorb::Command::Command::SlashCommand.new(command_name, description, options, [], block, 1, @parent + " " + @name)
389
357
  @commands << command
358
+ @client.bottom_commands << command
390
359
  command
391
360
  end
392
361
  end
@@ -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.5.1"
7
+ VERSION = "0.5.5"
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
@@ -65,9 +65,9 @@ module Discorb
65
65
  @timestamp = data[:timestamp] && Time.iso8601(data[:timestamp])
66
66
  @type = data[:type]
67
67
  @color = data[:color] && Color.new(data[:color])
68
- @footer = data[:footer] && Footer.new(data[:footer][:text], icon: data[:footer][:icon])
68
+ @footer = data[:footer] && Footer.new(data[:footer][:text], icon: data[:footer][:icon_url])
69
69
  @author = if data[:author]
70
- Author.new(data[:author][:name], icon: data[:author][:icon],
70
+ Author.new(data[:author][:name], icon: data[:author][:icon_url],
71
71
  url: data[:author][:url])
72
72
  end
73
73
  @thumbnail = data[:thumbnail] && Thumbnail.new(data[:thumbnail])
@@ -171,10 +171,10 @@ if (dir = ARGV[0])
171
171
  $path += "/#{dir}"
172
172
  if Dir.exist?($path)
173
173
  if Dir.empty?($path)
174
- gputs "Found \e[30m#{dir}\e[90m and empty, using this directory."
174
+ iputs "Found \e[30m#{dir}\e[90m and empty, using this directory."
175
175
  else
176
176
  if $values[:force]
177
- gputs "Found \e[30m#{dir}\e[90m and not empty, but force is on, using this directory."
177
+ iputs "Found \e[30m#{dir}\e[90m and not empty, but force is on, using this directory."
178
178
  else
179
179
  eputs "Directory \e[31m#{dir}\e[91m already exists and not empty. Use \e[31m-f\e[91m to force."
180
180
  exit
@@ -182,7 +182,7 @@ if (dir = ARGV[0])
182
182
  end
183
183
  else
184
184
  Dir.mkdir($path)
185
- gputs "Couldn't find \e[30m#{dir}\e[90m, created directory."
185
+ iputs "Couldn't find \e[30m#{dir}\e[90m, created directory."
186
186
  end
187
187
  Dir.chdir($path)
188
188
  end
@@ -8,6 +8,9 @@ module Discorb
8
8
  # @abstract
9
9
  #
10
10
  module Extension
11
+ include Discorb::Command::Handler
12
+ undef setup_commands
13
+
11
14
  @events = {}
12
15
  @client = nil
13
16
 
@@ -46,12 +49,18 @@ module Discorb
46
49
 
47
50
  # @return [Hash{Symbol => Array<Discorb::Event>}] The events of the extension.
48
51
  attr_reader :events
52
+ # @return [Array<Discorb::Command::Command] The commands of the extension.
53
+ attr_reader :commands
54
+ # @private
55
+ attr_reader :bottom_commands
49
56
 
50
57
  # @!visibility private
51
58
  attr_accessor :client
52
59
 
53
60
  def self.extended(obj)
54
61
  obj.instance_variable_set(:@events, {})
62
+ obj.instance_variable_set(:@commands, [])
63
+ obj.instance_variable_set(:@bottom_commands, [])
55
64
  end
56
65
  end
57
66
  end
@@ -778,11 +778,9 @@ module Discorb
778
778
  dispatch(:integration_create, Integration.new(self, data, data[:guild_id]))
779
779
  when "INTEGRATION_UPDATE"
780
780
  return @log.warn "Unknown guild id #{data[:guild_id]}, ignoring" unless (guild = @guilds[data[:guild_id]])
781
- return @log.warn "Unknown integration id #{data[:id]}, ignoring" unless (integration = guild.integrations[data[:id]])
782
781
 
783
- before = Integration.new(self, integration.instance_variable_get(:@data), data[:guild_id], no_cache: true)
784
- integration.send(:_set_data, data)
785
- dispatch(:integration_update, before, integration)
782
+ before = Integration.new(self, data, data[:guild_id])
783
+ dispatch(:integration_update, integration)
786
784
  when "INTEGRATION_DELETE"
787
785
  return @log.warn "Unknown guild id #{data[:guild_id]}, ignoring" unless (guild = @guilds[data[:guild_id]])
788
786
  return @log.warn "Unknown integration id #{data[:id]}, ignoring" unless (integration = guild.integrations.delete(data[:id]))
@@ -979,7 +977,11 @@ module Discorb
979
977
  @log.info("Successfully resumed connection")
980
978
  dispatch(:resumed)
981
979
  else
982
- @log.warn "Unknown event: #{event_name}\n#{data.inspect}"
980
+ if respond_to?("event_" + event_name.downcase)
981
+ __send__("event_" + event_name.downcase, data)
982
+ else
983
+ @log.debug "Received unknown event: #{event_name}\n#{data.inspect}"
984
+ end
983
985
  end
984
986
  end
985
987
  end
@@ -297,7 +297,7 @@ module Discorb
297
297
  end
298
298
  end
299
299
 
300
- unless (command = @client.commands.find { |c| c.to_s == name && c.type_raw == 1 })
300
+ unless (command = @client.bottom_commands.find { |c| c.to_s == name && c.type_raw == 1 })
301
301
  @client.log.warn "Unknown command name #{name}, ignoreing"
302
302
  next
303
303
  end
@@ -336,7 +336,7 @@ module Discorb
336
336
  private
337
337
 
338
338
  def _set_data(data)
339
- @target = Message.new(@client, data[:resolved][:messages][data[:target_id].to_sym].merge({ guild_id: @guild_id.to_s }))
339
+ @target = Message.new(@client, data[:resolved][:messages][data[:target_id].to_sym])
340
340
  @client.commands.find { |c| c.name == data[:name] && c.type_raw == 3 }.block.call(self, @target)
341
341
  end
342
342
  end
@@ -393,7 +393,7 @@ module Discorb
393
393
  # @!visibility private
394
394
  def make_interaction(client, data)
395
395
  nested_classes.each do |klass|
396
- return klass.new(client, data) if !klass.component_type.nil? && klass.component_type == data[:type]
396
+ return klass.new(client, data) if !klass.component_type.nil? && klass.component_type == data[:data][:component_type]
397
397
  end
398
398
  client.log.warn("Unknown component type #{data[:component_type]}, initialized Interaction")
399
399
  MessageComponentInteraction.new(client, data)
@@ -208,4 +208,14 @@ module Discorb
208
208
  end
209
209
  end
210
210
  end
211
+
212
+ #
213
+ # Module for connecting to a voice channel.
214
+ # This will be discord-voice gem.
215
+ #
216
+ module Connectable
217
+ def connect
218
+ raise NotImplementedError, "This method is implemented by discord-voice gem."
219
+ end
220
+ end
211
221
  end
data/lib/discorb/user.rb CHANGED
@@ -78,7 +78,7 @@ module Discorb
78
78
  Async do
79
79
  next @dm_channel_id if @dm_channel_id
80
80
 
81
- dm_channel = @client.http.post("/users/#{@id}/channels", { recipient_id: @client.user.id }).wait
81
+ _resp, dm_channel = @client.http.post("/users/@me/channels", { recipient_id: @id }).wait
82
82
  @dm_channel_id = dm_channel[:id]
83
83
  @dm_channel_id
84
84
  end
data/lib/discorb.rb CHANGED
@@ -41,11 +41,11 @@ end
41
41
 
42
42
  require_order = %w[common flag dictionary error rate_limit http intents emoji_table modules] +
43
43
  %w[user member guild emoji channel embed message] +
44
- %w[application audit_logs color components event extension] +
44
+ %w[application audit_logs color components event] +
45
45
  %w[file guild_template image integration interaction invite log permission] +
46
46
  %w[presence reaction role sticker utils voice_state webhook] +
47
47
  %w[gateway_requests gateway command] +
48
- %w[asset client extend]
48
+ %w[asset extension client extend]
49
49
  require_order.each do |name|
50
50
  require_relative "discorb/#{name}.rb"
51
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discorb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - sevenc-nanashi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-10 00:00:00.000000000 Z
11
+ date: 2021-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async