discordrb 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of discordrb might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -1
- data/lib/discordrb/bot.rb +5 -6
- data/lib/discordrb/data.rb +38 -3
- data/lib/discordrb/events/guilds.rb +1 -1
- data/lib/discordrb/version.rb +1 -1
- data/lib/discordrb/voice/network.rb +7 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 572e630200bd7bf1c7d6909b544cf8f69fc1b86e
|
4
|
+
data.tar.gz: fb27acb8b8261dad408b43255eb2a4d526eab7ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44451c1101cf93c8eabfc3017cca46ca9c236a3dd3be88d6203f1463756558701f5edb94854be88fca2e6d9870ad9a6a09ee41962520fdd4a39636921fbe53df
|
7
|
+
data.tar.gz: c7e73b58ef30d7f783541d0a3799f759db38f2bdef8409cc82ed889afd44bcda77f93acaf567bb6dfb0d453202ea2cd7186f6066af29afbd89a4b182ace266c3
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,27 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2.0.2
|
4
|
+
|
5
|
+
- Added `Server#text_channels` and `#voice_channels` ([#79](https://github.com/meew0/discordrb/issues/79))
|
6
|
+
- Added `Server#online_users` ([#80](https://github.com/meew0/discordrb/issues/80))
|
7
|
+
- Added `Member#role?` ([#83](https://github.com/meew0/discordrb/issues/83))
|
8
|
+
- Added three utility methods `User#online?`, `#offline?`, and `#idle?`
|
9
|
+
- `Bot#send_message` can now take channel objects as well as the ID
|
10
|
+
|
11
|
+
### Bugfixes
|
12
|
+
|
13
|
+
- Removing the bot from a server will no longer result in a gateway message error
|
14
|
+
- Fixed an exception raised if a previously unavailable guild goes online after the stream timeout
|
15
|
+
- `server_create` will no longer be raised for newly available guilds
|
16
|
+
- Fixed the annoying message about constant reassignment at startup
|
17
|
+
- Fixed an error where rarely a server's owner wouldn't be initialized correctly
|
18
|
+
|
3
19
|
## 2.0.1
|
4
20
|
|
5
21
|
- Added some more examples ([#75](https://github.com/meew0/discordrb/pull/75), thanks @greenbigfrog)
|
6
22
|
- Users can now be ignored from messages at gateway level (`Bot#ignore_user`, `Bot#unignore_user`)
|
7
23
|
- `Member#add_role` and `Member#remove_role` were re-added from User - they were missing before
|
8
24
|
|
9
|
-
|
10
25
|
### Bugfixes
|
11
26
|
|
12
27
|
- Fixed some typos in the documentation
|
data/lib/discordrb/bot.rb
CHANGED
@@ -390,6 +390,7 @@ module Discordrb
|
|
390
390
|
# @param tts [true, false] Whether or not this message should be sent using Discord text-to-speech.
|
391
391
|
# @return [Message] The message that was sent.
|
392
392
|
def send_message(channel_id, content, tts = false)
|
393
|
+
channel_id = channel_id.resolve_id
|
393
394
|
debug("Sending message to #{channel_id} with content '#{content}'")
|
394
395
|
|
395
396
|
response = API.send_message(token, channel_id, content, [], tts)
|
@@ -739,11 +740,6 @@ module Discordrb
|
|
739
740
|
# Internal handler for GUILD_DELETE
|
740
741
|
def delete_guild(data)
|
741
742
|
id = data['id'].to_i
|
742
|
-
|
743
|
-
@users.each do |_, user|
|
744
|
-
user.delete_roles(id)
|
745
|
-
end
|
746
|
-
|
747
743
|
@servers.delete(id)
|
748
744
|
end
|
749
745
|
|
@@ -1190,9 +1186,12 @@ module Discordrb
|
|
1190
1186
|
|
1191
1187
|
# Check for false specifically (no data means the server has never been unavailable)
|
1192
1188
|
if data['unavailable'].is_a? FalseClass
|
1193
|
-
@unavailable_servers -= 1
|
1189
|
+
@unavailable_servers -= 1 if @unavailable_servers
|
1194
1190
|
|
1195
1191
|
notify_ready if @unavailable_servers == 0
|
1192
|
+
|
1193
|
+
# Return here so the event doesn't get triggered
|
1194
|
+
return
|
1196
1195
|
end
|
1197
1196
|
|
1198
1197
|
event = ServerCreateEvent.new(data, self)
|
data/lib/discordrb/data.rb
CHANGED
@@ -196,6 +196,12 @@ module Discordrb
|
|
196
196
|
@bot.profile.id == @id
|
197
197
|
end
|
198
198
|
|
199
|
+
[:offline, :idle, :online].each do |e|
|
200
|
+
define_method(e.to_s + '?') do
|
201
|
+
@status.to_sym == e
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
199
205
|
# The inspect method is overwritten to give more useful output
|
200
206
|
def inspect
|
201
207
|
"<User username=#{@username} id=#{@id} discriminator=#{@discriminator}>"
|
@@ -338,6 +344,13 @@ module Discordrb
|
|
338
344
|
@server.owner == self
|
339
345
|
end
|
340
346
|
|
347
|
+
# @param role [Role, Integer, #resolve_id] the role to check or its ID.
|
348
|
+
# @return [true, false] whether this member has the specified role.
|
349
|
+
def role?(role)
|
350
|
+
role = role.resolve_id
|
351
|
+
@roles.any? { |e| e.id == role }
|
352
|
+
end
|
353
|
+
|
341
354
|
# Adds one or more roles to this member.
|
342
355
|
# @param role [Role, Array<Role>] The role(s) to add.
|
343
356
|
def add_role(role)
|
@@ -1147,7 +1160,7 @@ module Discordrb
|
|
1147
1160
|
attr_reader :afk_channel
|
1148
1161
|
|
1149
1162
|
# @!visibility private
|
1150
|
-
def initialize(data, bot)
|
1163
|
+
def initialize(data, bot, exists = true)
|
1151
1164
|
@bot = bot
|
1152
1165
|
@owner_id = data['owner_id'].to_i
|
1153
1166
|
@id = data['id'].to_i
|
@@ -1167,7 +1180,8 @@ module Discordrb
|
|
1167
1180
|
@chunked = false
|
1168
1181
|
@processed_chunk_members = 0
|
1169
1182
|
|
1170
|
-
|
1183
|
+
# Only get the owner of the server actually exists (i. e. not for ServerDeleteEvent)
|
1184
|
+
@owner = member(@owner_id) if exists
|
1171
1185
|
end
|
1172
1186
|
|
1173
1187
|
# @return [Channel] The default channel on this server (usually called #general)
|
@@ -1189,7 +1203,7 @@ module Discordrb
|
|
1189
1203
|
id = id.resolve_id
|
1190
1204
|
return @members[id] if member_cached?(id)
|
1191
1205
|
|
1192
|
-
member = bot.member(@id, id)
|
1206
|
+
member = @bot.member(@id, id)
|
1193
1207
|
@members[id] = member
|
1194
1208
|
end
|
1195
1209
|
|
@@ -1205,6 +1219,27 @@ module Discordrb
|
|
1205
1219
|
|
1206
1220
|
alias_method :users, :members
|
1207
1221
|
|
1222
|
+
# @param include_idle [true, false] Whether to count idle members as online.
|
1223
|
+
# @param include_bots [true, false] Whether to include bot accounts in the count.
|
1224
|
+
# @return [Array<Member>] an array of online members on this server.
|
1225
|
+
def online_members(include_idle: false, include_bots: true)
|
1226
|
+
@members.values.select do |e|
|
1227
|
+
((include_idle ? e.idle? : false) || e.online?) && (include_bots ? true : !e.bot_account?)
|
1228
|
+
end
|
1229
|
+
end
|
1230
|
+
|
1231
|
+
alias_method :online_users, :online_members
|
1232
|
+
|
1233
|
+
# @return [Array<Channel>] an array of text channels on this server
|
1234
|
+
def text_channels
|
1235
|
+
@channels.select(&:text?)
|
1236
|
+
end
|
1237
|
+
|
1238
|
+
# @return [Array<Channel>] an array of voice channels on this server
|
1239
|
+
def voice_channels
|
1240
|
+
@channels.select(&:voice?)
|
1241
|
+
end
|
1242
|
+
|
1208
1243
|
# Adds a role to the role cache
|
1209
1244
|
# @note For internal use only
|
1210
1245
|
# @!visibility private
|
@@ -61,7 +61,7 @@ module Discordrb::Events
|
|
61
61
|
class ServerDeleteEvent < ServerEvent
|
62
62
|
# Overide init_server to account for the deleted server
|
63
63
|
def init_server(data, bot)
|
64
|
-
@server = Discordrb::Server.new(data, bot)
|
64
|
+
@server = Discordrb::Server.new(data, bot, false)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
data/lib/discordrb/version.rb
CHANGED
@@ -8,14 +8,16 @@ require 'json'
|
|
8
8
|
require 'discordrb/websocket'
|
9
9
|
|
10
10
|
begin
|
11
|
-
RBNACL_AVAILABLE =
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
RBNACL_AVAILABLE = if ENV['DISCORDRB_NONACL']
|
12
|
+
false
|
13
|
+
else
|
14
|
+
require 'rbnacl'
|
15
|
+
true
|
16
|
+
end
|
16
17
|
rescue LoadError
|
17
18
|
puts "libsodium not available! You can continue to use discordrb as normal but voice support won't work.
|
18
19
|
Read https://github.com/meew0/discordrb/wiki/Installing-libsodium for more details."
|
20
|
+
RBNACL_AVAILABLE = false
|
19
21
|
end
|
20
22
|
|
21
23
|
module Discordrb::Voice
|