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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62c28a349c8f96a8a2774df678a355ea648ffada
4
- data.tar.gz: fa5f7258abac813c417549a9a9a56aaa76c42de0
3
+ metadata.gz: 572e630200bd7bf1c7d6909b544cf8f69fc1b86e
4
+ data.tar.gz: fb27acb8b8261dad408b43255eb2a4d526eab7ed
5
5
  SHA512:
6
- metadata.gz: 8ccbce3f46ad696ed1e285c7fc6625eb06c7855d21afe41768093e82d126557b68b8acc27b530ff6864745077d27879d95c7119b043de9d117a4cce41e0a2c89
7
- data.tar.gz: a308092e8dba4c4d7e491b921576c39ea5b40a2c362fe2df8a98c946f8f8cd0bb6e7a3c6f68e2189c8734041282c654d8353b0989dbedffad8a828b25d336882
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)
@@ -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
- @owner = member(@owner_id)
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
 
@@ -3,5 +3,5 @@
3
3
  # Discordrb and all its functionality, in this case only the version.
4
4
  module Discordrb
5
5
  # The current version of discordrb.
6
- VERSION = '2.0.1'.freeze
6
+ VERSION = '2.0.2'.freeze
7
7
  end
@@ -8,14 +8,16 @@ require 'json'
8
8
  require 'discordrb/websocket'
9
9
 
10
10
  begin
11
- RBNACL_AVAILABLE = false
12
- unless ENV.key?('DISCORDRB_NONACL')
13
- require 'rbnacl'
14
- RBNACL_AVAILABLE = true
15
- end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discordrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - meew0