discordrb 2.0.2 → 2.0.3

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: 572e630200bd7bf1c7d6909b544cf8f69fc1b86e
4
- data.tar.gz: fb27acb8b8261dad408b43255eb2a4d526eab7ed
3
+ metadata.gz: e85a40f2b3cc06af57ecf04357e35453c6fc48ef
4
+ data.tar.gz: a5b5ff40e9ae47db4875392e74f6a4ce8d91bf2e
5
5
  SHA512:
6
- metadata.gz: 44451c1101cf93c8eabfc3017cca46ca9c236a3dd3be88d6203f1463756558701f5edb94854be88fca2e6d9870ad9a6a09ee41962520fdd4a39636921fbe53df
7
- data.tar.gz: c7e73b58ef30d7f783541d0a3799f759db38f2bdef8409cc82ed889afd44bcda77f93acaf567bb6dfb0d453202ea2cd7186f6066af29afbd89a4b182ace266c3
6
+ metadata.gz: cde28c5fa4b45858fa2646b19a677a8d59659d3abeb6b3b0a33f0808d6e9ec5ef830dc73be77fc05d6bb5392204a0d61742adc1fc7331b564ef38183ac47d96d
7
+ data.tar.gz: 02f17a29a2ebeec59047a799ce9a3564123dc7fdf8962d2940110738cb0285e8ee51daed9e5130ff5667f2621c588c689ec203c6e6f0fb282f6727b233ecef2a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.3
4
+
5
+ - All examples now fully use v2 ([#92](https://github.com/meew0/discordrb/pull/92), thanks @snapcase)
6
+ - The message that occurs when a command is missing permission can now be changed or disabled ([#94](https://github.com/meew0/discordrb/pull/94), thanks @snapcase)
7
+ - The log message that occurs when you disconnect from the WebSocket is now more compact ([#90](https://github.com/meew0/discordrb/issues/90))
8
+ - `Bot#ignored?` now exists to check whether a user is ignored
9
+
10
+ ### Bugfixes
11
+
12
+ - A problem where getting channel history would sometimes cause an exception has been fixed ([#88](https://github.com/meew0/discordrb/issues/88))
13
+ - `split_message` should now behave correctly in a specific edge case ([#85](https://github.com/meew0/discordrb/pull/85), thanks @AnhNhan)
14
+ - DCA playback should no longer cause an error when playback ends due to a specific reason
15
+
3
16
  ## 2.0.2
4
17
 
5
18
  - Added `Server#text_channels` and `#voice_channels` ([#79](https://github.com/meew0/discordrb/issues/79))
data/examples/eval.rb CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  require 'discordrb'
4
4
 
5
- bot = Discordrb::Commands::CommandBot.new 'email@example.com', 'hunter2'
5
+ bot = Discordrb::Commands::CommandBot.new token: 'B0T.T0KEN.here', application_id: 160123456789876543, prefix: '!'
6
6
 
7
- bot.command(:eval, help_available: false) do |event, code|
8
- break if event.user.id == 000000 # Replace number with your ID
7
+ bot.command(:eval, help_available: false) do |event, *code|
8
+ break unless event.user.id == 000000 # Replace number with your ID
9
9
 
10
10
  begin
11
- eval(code)
11
+ eval code.join(' ')
12
12
  rescue
13
13
  "An error occured 😞"
14
14
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'discordrb'
4
4
 
5
- bot = Discordrb::Commands::CommandBot.new 'email@example.com', 'hunter2'
5
+ bot = Discordrb::Commands::CommandBot.new token: 'B0T.T0KEN.here', application_id: 160123456789876543, prefix: '!'
6
6
 
7
7
  bot.command(:ping) do |event|
8
8
  m = event.respond('Pong!')
data/examples/shutdown.rb CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  require 'discordrb'
4
4
 
5
- bot = Discordrb::Commands::CommandBot.new 'email@example.com', 'hunter2'
5
+ bot = Discordrb::Commands::CommandBot.new token: 'B0T.T0KEN.here', application_id: 160123456789876543, prefix: '!'
6
6
 
7
7
  bot.command(:exit, help_available: false) do |event|
8
- break if event.user.id == 000000 # Replace number with your ID
8
+ break unless event.user.id == 000000 # Replace number with your ID
9
9
 
10
10
  bot.send_message(event.channel.id, 'Bot is shutting down')
11
11
  exit
data/lib/discordrb/bot.rb CHANGED
@@ -242,12 +242,9 @@ module Discordrb
242
242
  loop do
243
243
  websocket_connect
244
244
 
245
- # websocket_connect is blocking so being in here means we're disconnected
246
- LOGGER.warn('Oh dear, we got disconnected!')
247
-
248
245
  if @reconnect_url
249
246
  # We got an op 7! Don't wait before reconnecting
250
- debug('Got an op 7, reconnecting right away')
247
+ LOGGER.info('Got an op 7, reconnecting right away')
251
248
  else
252
249
  wait_for_reconnect
253
250
  end
@@ -543,6 +540,13 @@ module Discordrb
543
540
  @ignored_ids.delete(user.resolve_id)
544
541
  end
545
542
 
543
+ # Checks whether a user is being ignored.
544
+ # @param user [User, Integer, #resolve_id] The user, or its ID, to check.
545
+ # @return [true, false] whether or not the user is ignored.
546
+ def ignored?(user)
547
+ @ignored_ids.include?(user.resolve_id)
548
+ end
549
+
546
550
  # @see Logger#debug
547
551
  def debug(message)
548
552
  LOGGER.debug(message)
@@ -1056,7 +1060,7 @@ module Discordrb
1056
1060
  server = server(id)
1057
1061
  server.process_chunk(data['members'])
1058
1062
  when :MESSAGE_CREATE
1059
- if @ignored_ids.include?(data['author']['id'].to_i)
1063
+ if ignored?(data['author']['id'].to_i)
1060
1064
  debug("Ignored author with ID #{data['author']['id']}")
1061
1065
  return
1062
1066
  end
@@ -1216,16 +1220,14 @@ module Discordrb
1216
1220
  end
1217
1221
 
1218
1222
  def websocket_close(event)
1219
- LOGGER.error('Disconnected from WebSocket!')
1220
-
1221
1223
  # Don't handle nil events (for example if the disconnect came from our side)
1222
1224
  return unless event
1223
1225
 
1224
1226
  # Handle actual close frames and errors separately
1225
1227
  if event.respond_to? :code
1226
- LOGGER.error(" (Reason: #{event.data})")
1227
- LOGGER.error(" (Code: #{event.code})")
1228
+ LOGGER.error(%(Disconnected from WebSocket - code #{event.code} with reason: "#{event.data}"))
1228
1229
  else
1230
+ LOGGER.error('Disconnected from WebSocket due to an exception!')
1229
1231
  LOGGER.log_exception event
1230
1232
  end
1231
1233
 
@@ -1321,7 +1323,7 @@ module Discordrb
1321
1323
  # unexpected way
1322
1324
  def wait_for_reconnect
1323
1325
  # We disconnected in an unexpected way! Wait before reconnecting so we don't spam Discord's servers.
1324
- debug("Disconnected! Attempting to reconnect in #{@falloff} seconds.")
1326
+ debug("Attempting to reconnect in #{@falloff} seconds.")
1325
1327
  sleep @falloff
1326
1328
 
1327
1329
  # Calculate new falloff
@@ -155,7 +155,8 @@ module Discordrb::Commands
155
155
  result = command.call(event, arguments, chained)
156
156
  stringify(result)
157
157
  else
158
- event.respond "You don't have permission to execute command `#{name}`!"
158
+ event.respond command.attributes[:permission_message].gsub('%name%', name.to_s) if command.attributes[:permission_message]
159
+ return
159
160
  end
160
161
  end
161
162
 
@@ -14,6 +14,9 @@ module Discordrb::Commands
14
14
  # @param attributes [Hash] The attributes to initialize the command with.
15
15
  # @option attributes [Integer] :permission_level The minimum permission level that can use this command, inclusive.
16
16
  # See {CommandBot#set_user_permission} and {CommandBot#set_role_permission}.
17
+ # @option attributes [String, false] :permission_message Message to display when a user does not have sufficient
18
+ # permissions to execute a command. %name% in the message will be replaced with the name of the command. Disable
19
+ # the message by setting this option to false.
17
20
  # @option attributes [true, false] :chain_usable Whether this command is able to be used inside of a command chain
18
21
  # or sub-chain. Typically used for administrative commands that shouldn't be done carelessly.
19
22
  # @option attributes [true, false] :help_available Whether this command is visible in the help command. See the
@@ -16,6 +16,9 @@ module Discordrb::Commands
16
16
  # The lowest permission level that can use the command
17
17
  permission_level: attributes[:permission_level] || 0,
18
18
 
19
+ # Message to display when a user does not have sufficient permissions to execute a command
20
+ permission_message: (attributes[:permission_message].is_a? FalseClass) ? nil : (attributes[:permission_message] || "You don't have permission to execute command %name%!"),
21
+
19
22
  # Whether this command is usable in a command chain
20
23
  chain_usable: attributes[:chain_usable].nil? ? true : attributes[:chain_usable],
21
24
 
@@ -42,7 +42,7 @@ module Discordrb
42
42
  tri = [*0..(lines.length - 1)].map { |i| lines.combination(i + 1).first }
43
43
 
44
44
  # Join the individual elements together to get an array of strings with consecutively more lines
45
- joined = tri.map { |e| e.join("\n") }
45
+ joined = tri.map(&:join)
46
46
 
47
47
  # Find the largest element that is still below the character limit, or if none such element exists return the first
48
48
  ideal = joined.max_by { |e| e.length > CHARACTER_LIMIT ? -1 : e.length }
@@ -1059,7 +1059,7 @@ module Discordrb
1059
1059
  # directly because the bot may also send messages to the channel
1060
1060
  Recipient.new(bot.user(data['author']['id'].to_i), @channel, bot)
1061
1061
  else
1062
- @channel.server.member(data['author']['id'].to_i)
1062
+ @channel.server.member(data['author']['id'].to_i, false)
1063
1063
  end
1064
1064
  end
1065
1065
 
@@ -1199,9 +1199,11 @@ module Discordrb
1199
1199
 
1200
1200
  # Gets a member on this server based on user ID
1201
1201
  # @param id [Integer] The user ID to look for
1202
- def member(id)
1202
+ # @param request [true, false] Whether the member should be requested from Discord if it's not cached
1203
+ def member(id, request = true)
1203
1204
  id = id.resolve_id
1204
1205
  return @members[id] if member_cached?(id)
1206
+ return nil unless request
1205
1207
 
1206
1208
  member = @bot.member(@id, id)
1207
1209
  @members[id] = member
@@ -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.2'.freeze
6
+ VERSION = '2.0.3'.freeze
7
7
  end
@@ -249,11 +249,18 @@ module Discordrb::Voice
249
249
  play_internal do
250
250
  begin
251
251
  # Read header
252
- header = input_stream.read(2).unpack('s<')[0]
252
+ header_str = input_stream.read(2)
253
+
254
+ unless header_str
255
+ @bot.debug 'Finished DCA parsing (header is nil)'
256
+ break
257
+ end
258
+
259
+ header = header_str.unpack('s<')[0]
253
260
 
254
261
  raise 'Negative header in DCA file! Your file is likely corrupted.' if header < 0
255
262
  rescue EOFError
256
- @bot.debug 'Finished DCA parsing'
263
+ @bot.debug 'Finished DCA parsing (EOFError)'
257
264
  break
258
265
  end
259
266
 
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.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - meew0
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-10 00:00:00.000000000 Z
11
+ date: 2016-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client