discordrb 2.1.1 → 2.1.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: c44d3aabc75cea8c55af00a64f2d8f095d1b0435
4
- data.tar.gz: d0769329fa9175353b605ba4993d1be07a0c9927
3
+ metadata.gz: a2c02619526d20cdc2271007727d9d6dde54d99e
4
+ data.tar.gz: 8ef9e1bb4e10d628c8700e77954d52b56e35dd13
5
5
  SHA512:
6
- metadata.gz: 7ccf838cda0542222deb998e4bc335fccabd479b15d34c7b7df51e437b142f04f05bda5c7b0d0f41c6f30503cbaeea80d90b8751187e8dfe72ed6e4a4f093c93
7
- data.tar.gz: cb2cb4640fa336a79a17f22b90c913d8f88edcda6dad403e66530257f7a16756cac99461b7c1508ed21252555333274be8161546dd1667061af214681ecae295
6
+ metadata.gz: e5379d34964d6c0b613cab7f7ea3867bf1ea34cd060aba580bdd457eb3a25fd143ef3825a8b5e4c2b81a98c8d431da50de552cf5631d04b5c489023232787964
7
+ data.tar.gz: 84398d02eb4482b53cb1727caf418e548b9c9a1769352eb28a71671958a2a5b6f7c810d4c0ec3ee51acf7dec200eca3db0cb57913921dcfadb19150d828bd8a3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.1.2
4
+
5
+ - A reader was added (`Bot#awaits`) to read the hash of awaits, so ones that aren't necessary anymore can be deleted.
6
+ - `Channel#prune` now uses the bulk delete endpoint which means it will be much faster and no longer rate limited ([#118](https://github.com/meew0/discordrb/pull/118), thanks @snapcase)
7
+
8
+ ### Bugfixes
9
+
10
+ - A few unresolved links in the documentation were fixed.
11
+ - The tracking of streamed servers was updated so that very long lists of servers should now all be processed.
12
+ - Resolution methods now return nil if the object to resolve can't be found, which should alleviate some rare caching problems ([#124](https://github.com/meew0/discordrb/pull/124), thanks @Snazzah)
13
+ - In the rare event that Discord sends a voice state update for a nonexistent member, there should no longer be a gateway error ([#125](https://github.com/meew0/discordrb/issues/125))
14
+ - Network errors (`EPIPE` and the like) should no longer cause an exception while processing ([#127](https://github.com/meew0/discordrb/issues/127))
15
+ - Uncached members in messages are now logged.
16
+
3
17
  ## 2.1.1
4
18
 
5
19
  *Bugfix-only release.*
data/README.md CHANGED
@@ -71,7 +71,7 @@ For example
71
71
 
72
72
  C:/Ruby23-x64/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- ffi_c (LoadError)
73
73
 
74
- Your ffi setup is screwed up, run `gem install ffi --platform=ruby` to fix it. If it says something about build tools, follow the steps in the first troubleshooting section.
74
+ Your ffi setup is screwed up, first run `gem uninstall ffi` (uninstall all versions if it asks you, say yes to any unmet dependencies), then run `gem install ffi --platform=ruby` to fix it. If it says something about build tools, follow the steps in the first troubleshooting section.
75
75
 
76
76
  **If you're having trouble getting voice playback to work**:
77
77
 
data/lib/discordrb/api.rb CHANGED
@@ -415,6 +415,18 @@ module Discordrb::API
415
415
  )
416
416
  end
417
417
 
418
+ # Delete messages in bulk
419
+ def bulk_delete(token, channel_id, messages = [])
420
+ request(
421
+ __method__,
422
+ :post,
423
+ "#{api_base}/channels/#{channel_id}/messages/bulk_delete",
424
+ { messages: messages }.to_json,
425
+ Authorization: token,
426
+ content_type: :json
427
+ )
428
+ end
429
+
418
430
  # Edit a message
419
431
  def edit_message(token, channel_id, message_id, message, mentions = [])
420
432
  request(
data/lib/discordrb/bot.rb CHANGED
@@ -112,6 +112,9 @@ module Discordrb
112
112
  # @return [Array(Integer, Integer)] the current shard key
113
113
  attr_reader :shard_key
114
114
 
115
+ # @return [Hash<Symbol => Await>] the list of registered {Await}s.
116
+ attr_reader :awaits
117
+
115
118
  include EventContainer
116
119
  include Cache
117
120
 
@@ -325,8 +328,8 @@ module Discordrb
325
328
 
326
329
  # Connects to a voice channel, initializes network connections and returns the {Voice::VoiceBot} over which audio
327
330
  # data can then be sent. After connecting, the bot can also be accessed using {#voice}. If the bot is already
328
- # connected to voice, the existing connection will be terminated - you don't have to call {VoiceBot#destroy}
329
- # before calling this method.
331
+ # connected to voice, the existing connection will be terminated - you don't have to call
332
+ # {Discordrb::Voice::VoiceBot#destroy} before calling this method.
330
333
  # @param chan [Channel] The voice channel to connect to.
331
334
  # @param encrypted [true, false] Whether voice communication should be encrypted using RbNaCl's SecretBox
332
335
  # (uses an XSalsa20 stream cipher for encryption and Poly1305 for authentication)
@@ -646,6 +649,11 @@ module Discordrb
646
649
 
647
650
  user = server.member(user_id)
648
651
 
652
+ unless user
653
+ warn "Invalid user for voice state update: #{user_id} on #{server_id}, ignoring"
654
+ return
655
+ end
656
+
649
657
  channel_id = data['channel_id']
650
658
  channel = nil
651
659
  channel = self.channel(channel_id.to_i) if channel_id
@@ -994,7 +1002,7 @@ module Discordrb
994
1002
  v#{GATEWAY_VERSION} #{packet}" unless opcode == Opcodes::DISPATCH
995
1003
 
996
1004
  # Check whether there are still unavailable servers and there have been more than 10 seconds since READY
997
- if @unavailable_servers && @unavailable_servers > 0 && (Time.now - @ready_time) > 10
1005
+ if @unavailable_servers && @unavailable_servers > 0 && (Time.now - @unavailable_timeout_time) > 10
998
1006
  # The server streaming timed out!
999
1007
  LOGGER.warn("Server streaming timed out with #{@unavailable_servers} servers remaining")
1000
1008
  LOGGER.warn("This means some servers are unavailable due to an outage. Notifying ready now, we'll have to live without these servers")
@@ -1059,6 +1067,7 @@ module Discordrb
1059
1067
  end
1060
1068
 
1061
1069
  @ready_time = Time.now
1070
+ @unavailable_timeout_time = Time.now
1062
1071
  when :RESUMED
1063
1072
  # The RESUMED event is received after a successful op 6 (resume). It does nothing except tell the bot the
1064
1073
  # connection is initiated (like READY would) and set a new heartbeat interval.
@@ -1212,6 +1221,7 @@ module Discordrb
1212
1221
  # Check for false specifically (no data means the server has never been unavailable)
1213
1222
  if data['unavailable'].is_a? FalseClass
1214
1223
  @unavailable_servers -= 1 if @unavailable_servers
1224
+ @unavailable_timeout_time = Time.now
1215
1225
 
1216
1226
  notify_ready if @unavailable_servers == 0
1217
1227
 
@@ -1247,19 +1257,19 @@ module Discordrb
1247
1257
  # Handle actual close frames and errors separately
1248
1258
  if event.respond_to? :code
1249
1259
  LOGGER.error(%(Disconnected from WebSocket - code #{event.code} with reason: "#{event.data}"))
1260
+
1261
+ if event.code.to_i == 4006
1262
+ # If we got disconnected with a 4006, it means we sent a resume when Discord wanted an identify. To battle this,
1263
+ # we invalidate the local session so we'll just send an identify next time
1264
+ debug('Apparently we just sent the wrong type of initiation packet (resume rather than identify) to Discord. (Sorry!)
1265
+ Invalidating session so this is fixed next time')
1266
+ invalidate_session
1267
+ end
1250
1268
  else
1251
1269
  LOGGER.error('Disconnected from WebSocket due to an exception!')
1252
1270
  LOGGER.log_exception event
1253
1271
  end
1254
1272
 
1255
- if event.code.to_i == 4006
1256
- # If we got disconnected with a 4006, it means we sent a resume when Discord wanted an identify. To battle this,
1257
- # we invalidate the local session so we'll just send an identify next time
1258
- debug('Apparently we just sent the wrong type of initiation packet (resume rather than identify) to Discord. (Sorry!)
1259
- Invalidating session so this is fixed next time')
1260
- invalidate_session
1261
- end
1262
-
1263
1273
  raise_event(DisconnectEvent.new(self))
1264
1274
 
1265
1275
  # Stop sending heartbeats
@@ -35,7 +35,11 @@ module Discordrb
35
35
  return @channels[id] if @channels[id]
36
36
 
37
37
  begin
38
- response = API.channel(token, id)
38
+ begin
39
+ response = API.channel(token, id)
40
+ rescue RestClient::ResourceNotFound
41
+ return nil
42
+ end
39
43
  channel = Channel.new(JSON.parse(response), self, server)
40
44
  @channels[id] = channel
41
45
  rescue Discordrb::Errors::NoPermission
@@ -54,7 +58,11 @@ module Discordrb
54
58
  return @users[id] if @users[id]
55
59
 
56
60
  LOGGER.out("Resolving user #{id}")
57
- response = API.user(token, id)
61
+ begin
62
+ response = API.user(token, id)
63
+ rescue RestClient::ResourceNotFound
64
+ return nil
65
+ end
58
66
  user = User.new(JSON.parse(response), self)
59
67
  @users[id] = user
60
68
  end
@@ -68,7 +76,11 @@ module Discordrb
68
76
  return @servers[id] if @servers[id]
69
77
 
70
78
  LOGGER.out("Resolving server #{id}")
71
- response = API.server(token, id)
79
+ begin
80
+ response = API.server(token, id)
81
+ rescue RestClient::ResourceNotFound
82
+ return nil
83
+ end
72
84
  server = Server.new(JSON.parse(response), self)
73
85
  @servers[id] = server
74
86
  end
@@ -85,7 +97,11 @@ module Discordrb
85
97
  return server.member(user_id) if server.member_cached?(user_id)
86
98
 
87
99
  LOGGER.out("Resolving member #{server_id} on server #{user_id}")
88
- response = API.member(token, server_id, user_id)
100
+ begin
101
+ response = API.member(token, server_id, user_id)
102
+ rescue RestClient::ResourceNotFound
103
+ return nil
104
+ end
89
105
  member = Member.new(JSON.parse(response), server, self)
90
106
  server.cache_member(member)
91
107
  end
@@ -1005,26 +1005,14 @@ module Discordrb
1005
1005
  JSON.parse(logs).map { |message| Message.new(message, @bot) }
1006
1006
  end
1007
1007
 
1008
- # Deletes the last N messages on this channel. Each delete request is performed in a separate thread for performance
1009
- # reasons, so if a large number of messages are pruned, many threads will be created.
1010
- # @note As of the April 29 update, the message delete request is rate limited, which means this method will take
1011
- # a long time. It will eventually be updated to use batch deletes once those are released, but that will be in the
1012
- # far future.
1013
- # @param amount [Integer] How many messages to delete. Must be 100 or less (Discord limitation)
1014
- # @raise [ArgumentError] if more than 100 messages are requested.
1008
+ # Delete the last N messages on this channel.
1009
+ # @param amount [Integer] How many messages to delete. Must be a value between 2 and 100 (Discord limitation)
1010
+ # @raise [ArgumentError] if the amount of messages is not a value between 2 and 100
1015
1011
  def prune(amount)
1016
- raise ArgumentError, "Can't prune more than 100 messages!" if amount > 100
1012
+ raise ArgumentError, 'Can only prune between 2 and 100 messages!' unless amount.between?(2, 100)
1017
1013
 
1018
- threads = []
1019
- history(amount).each do |message|
1020
- threads << Thread.new { message.delete }
1021
- end
1022
-
1023
- # Make sure all requests have finished
1024
- threads.each(&:join)
1025
-
1026
- # Delete the threads
1027
- threads.map! { nil }
1014
+ messages = history(amount).map(&:id)
1015
+ API.bulk_delete(@bot.token, @id, messages)
1028
1016
  end
1029
1017
 
1030
1018
  # Updates the cached permission overwrites
@@ -1163,7 +1151,9 @@ module Discordrb
1163
1151
  # directly because the bot may also send messages to the channel
1164
1152
  Recipient.new(bot.user(data['author']['id'].to_i), @channel, bot)
1165
1153
  else
1166
- @channel.server.member(data['author']['id'].to_i, false)
1154
+ member = @channel.server.member(data['author']['id'].to_i, false)
1155
+ Discordrb::LOGGER.warn("Member with ID #{data['author']['id']} not cached even though it should be.") unless member
1156
+ member
1167
1157
  end
1168
1158
  end
1169
1159
 
@@ -1320,6 +1310,8 @@ module Discordrb
1320
1310
 
1321
1311
  member = @bot.member(@id, id)
1322
1312
  @members[id] = member
1313
+ rescue
1314
+ nil
1323
1315
  end
1324
1316
 
1325
1317
  # @return [Array<Member>] an array of all the members on this server.
@@ -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.1.1'.freeze
6
+ VERSION = '2.1.2'.freeze
7
7
  end
@@ -227,7 +227,7 @@ module Discordrb::Voice
227
227
 
228
228
  # Plays a stream of audio data in the DCA format. This format has the advantage that no recoding has to be
229
229
  # done - the file contains the data exactly as Discord needs it.
230
- # @note DCA playback will not be affected by the volume modifier ({volume=}) because the modifier operates on raw
230
+ # @note DCA playback will not be affected by the volume modifier ({#volume}) because the modifier operates on raw
231
231
  # PCM, not opus data. Modifying the volume of DCA data would involve decoding it, multiplying the samples and
232
232
  # re-encoding it, which defeats its entire purpose (no recoding).
233
233
  # @see https://github.com/bwmarrin/dca
@@ -3,6 +3,9 @@
3
3
  require 'websocket-client-simple'
4
4
 
5
5
  puts "Using WSCS version: #{WebSocket::Client::Simple::VERSION}"
6
+
7
+ # The WSCS module which we're hooking
8
+ # @see Websocket::Client::Simple::Client
6
9
  module WebSocket::Client::Simple
7
10
  # Patch to the WSCS class to allow reading the internal thread
8
11
  class Client
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discordrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - meew0
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-08 00:00:00.000000000 Z
11
+ date: 2016-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client