discorb 0.5.2 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +21 -0
- data/Gemfile.lock +1 -1
- data/lib/discorb/channel.rb +4 -1
- data/lib/discorb/client.rb +4 -2
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/embed.rb +2 -2
- data/lib/discorb/emoji.rb +7 -0
- data/lib/discorb/exe/init.rb +3 -3
- data/lib/discorb/gateway.rb +15 -4
- data/lib/discorb/interaction.rb +2 -2
- data/lib/discorb/modules.rb +10 -0
- data/lib/discorb/user.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8484feb78582222a91d4fee1225fe649edc6a24a4c6c77eb83fa6c3094b3935d
|
4
|
+
data.tar.gz: 7597101823bd4f3f6900636af7f06320d9c296659069ff69bc829b7528171372
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6a690ccd8d95f66db74cafd22a430472841183d3048b10529009a0a64a1ba4c21f553fe83746c7356b3069c87badd3768c88834a34cecb0194ccf818a128947
|
7
|
+
data.tar.gz: cd46b4dd261aea5d4f9b2257e1cb81f07b377922364080863cce61551293dbb08ded110d15bac44812307d7846edb7a77787ef2e3f003bcb1ae977f8c35545b6
|
data/Changelog.md
CHANGED
@@ -117,3 +117,24 @@
|
|
117
117
|
|
118
118
|
- Fix: Fix bug of registering commands
|
119
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
|
135
|
+
|
136
|
+
## 0.5.6
|
137
|
+
|
138
|
+
- Add: Raise error when intents are invalid
|
139
|
+
- Fix: Fix Emoji#==
|
140
|
+
|
data/Gemfile.lock
CHANGED
data/lib/discorb/channel.rb
CHANGED
@@ -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
|
|
data/lib/discorb/client.rb
CHANGED
@@ -49,6 +49,8 @@ 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
|
52
54
|
# @private
|
53
55
|
attr_reader :bottom_commands
|
54
56
|
|
@@ -458,7 +460,7 @@ module Discorb
|
|
458
460
|
}
|
459
461
|
@token = token.to_s
|
460
462
|
@close_condition = Async::Condition.new
|
461
|
-
main_task = Async do
|
463
|
+
@main_task = Async do
|
462
464
|
@status = :running
|
463
465
|
connect_gateway(true).wait
|
464
466
|
rescue
|
@@ -467,7 +469,7 @@ module Discorb
|
|
467
469
|
raise
|
468
470
|
end
|
469
471
|
@close_condition.wait
|
470
|
-
main_task.stop
|
472
|
+
@main_task.stop
|
471
473
|
end
|
472
474
|
end
|
473
475
|
end
|
data/lib/discorb/common.rb
CHANGED
@@ -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.
|
7
|
+
VERSION = "0.5.6"
|
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][:
|
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][:
|
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])
|
data/lib/discorb/emoji.rb
CHANGED
data/lib/discorb/exe/init.rb
CHANGED
@@ -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
|
-
|
174
|
+
iputs "Found \e[30m#{dir}\e[90m and empty, using this directory."
|
175
175
|
else
|
176
176
|
if $values[:force]
|
177
|
-
|
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
|
-
|
185
|
+
iputs "Couldn't find \e[30m#{dir}\e[90m, created directory."
|
186
186
|
end
|
187
187
|
Dir.chdir($path)
|
188
188
|
end
|
data/lib/discorb/gateway.rb
CHANGED
@@ -513,7 +513,6 @@ module Discorb
|
|
513
513
|
case payload[:op]
|
514
514
|
when 10
|
515
515
|
@heartbeat_interval = data[:heartbeat_interval]
|
516
|
-
@tasks << handle_heartbeat(@heartbeat_interval)
|
517
516
|
if @first
|
518
517
|
payload = {
|
519
518
|
token: @token,
|
@@ -523,6 +522,13 @@ module Discorb
|
|
523
522
|
}
|
524
523
|
payload[:presence] = @identify_presence if @identify_presence
|
525
524
|
send_gateway(2, **payload)
|
525
|
+
Async do
|
526
|
+
sleep 2
|
527
|
+
next unless @uncached_guilds.nil?
|
528
|
+
|
529
|
+
raise ClientError, "Failed to connect to gateway.\nHint: This usually means that your intents are invalid."
|
530
|
+
exit 1
|
531
|
+
end
|
526
532
|
else
|
527
533
|
payload = {
|
528
534
|
token: @token,
|
@@ -540,7 +546,7 @@ module Discorb
|
|
540
546
|
connect_gateway(false)
|
541
547
|
else
|
542
548
|
@log.info "Connection is not resumable, reconnecting with opcode 2"
|
543
|
-
|
549
|
+
sleep(2)
|
544
550
|
@connection.close
|
545
551
|
connect_gateway(true)
|
546
552
|
end
|
@@ -555,7 +561,7 @@ module Discorb
|
|
555
561
|
|
556
562
|
def handle_heartbeat(interval)
|
557
563
|
Async do |task|
|
558
|
-
|
564
|
+
sleep((interval / 1000.0 - 1) * rand)
|
559
565
|
loop do
|
560
566
|
@heartbeat_before = Time.now.to_f
|
561
567
|
@connection.write({ op: 1, d: @last_s }.to_json)
|
@@ -578,6 +584,7 @@ module Discorb
|
|
578
584
|
@session_id = data[:session_id]
|
579
585
|
@user = ClientUser.new(self, data[:user])
|
580
586
|
@uncached_guilds = data[:guilds].map { |g| g[:id] }
|
587
|
+
@tasks << handle_heartbeat(@heartbeat_interval)
|
581
588
|
when "GUILD_CREATE"
|
582
589
|
if @uncached_guilds.include?(data[:id])
|
583
590
|
Guild.new(self, data, true)
|
@@ -977,7 +984,11 @@ module Discorb
|
|
977
984
|
@log.info("Successfully resumed connection")
|
978
985
|
dispatch(:resumed)
|
979
986
|
else
|
980
|
-
|
987
|
+
if respond_to?("event_" + event_name.downcase)
|
988
|
+
__send__("event_" + event_name.downcase, data)
|
989
|
+
else
|
990
|
+
@log.debug "Received unknown event: #{event_name}\n#{data.inspect}"
|
991
|
+
end
|
981
992
|
end
|
982
993
|
end
|
983
994
|
end
|
data/lib/discorb/interaction.rb
CHANGED
@@ -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]
|
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[:
|
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)
|
data/lib/discorb/modules.rb
CHANGED
@@ -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
|
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
|
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.
|
4
|
+
version: 0.5.6
|
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-
|
11
|
+
date: 2021-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|