discordrb 1.7.4 → 1.7.5

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: 36dd991249332783c1bd50f94ddbb555cc8483d2
4
- data.tar.gz: 2b68f3bb825c2e6f49290356d7f7ebcbbb8e509e
3
+ metadata.gz: d661448f2825e14545bff5ef277d349bdc9fe944
4
+ data.tar.gz: f4c846fde0f3248e6c6d3be8d69b4dabfdd6f098
5
5
  SHA512:
6
- metadata.gz: b22aa3bfb28c470f931eec7e060414f349e3cd46c29cd725cdc3235e372ece0dbaccd1d72b7b6077afb0f12b76ed112abc869a844acb152c5e8eb2e0c1ef0210
7
- data.tar.gz: 12ee016ea86fb2fcd721855f32466552b4e471212c247005b864c416359b969e1b5ce943141eceede6177405d12c2b210f364533a55a44210fb0ab8e96eb90f9
6
+ metadata.gz: 49aaa4b14e1da63c24fa1dcb03500b3926c71781e6cbd20e5cd7af296b060dd01082baa6dceaa9630ac55520b316c0fd98d1027df34c6b1e5996303117193196
7
+ data.tar.gz: 9a8d93545ce59f3334fa785ffaa85fd47f511ace03175045614a69441735da09fffe7305b4b6dfe95316d7e1fc2b0c8407a1fc381596d9882ab52b681311e74e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.7.5
4
+ * `Channel#send_message` and `Bot#send_message` now have an extra `tts` parameter (false by default) to specify whether the message should use TTS.
5
+
6
+ ### Bugfixes
7
+ * Attempting to `p` a data class, especially a `User` or `Profile`, should no longer lock up the interpreter due to very deep recursion.
8
+ * Manual TTS using `API.send_message` will now work correctly.
9
+
3
10
  ## 1.7.4
4
11
  * Added methods `Channel#text?` and `Channel#voice?` to check a channel's type.
5
12
  * Frequently allocated strings have been turned into symbols or frozen constants, this should improve performance slightly.
data/discordrb.gemspec CHANGED
@@ -32,5 +32,5 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'rake', '~> 10.0'
33
33
  spec.add_development_dependency 'yard', '~> 0.8.7.6'
34
34
  spec.add_development_dependency 'rspec', '~> 3.4.0'
35
- spec.add_development_dependency 'rubocop', '0.36.0'
35
+ spec.add_development_dependency 'rubocop', '0.37.2'
36
36
  end
data/examples/commands.rb CHANGED
@@ -22,9 +22,9 @@ end
22
22
 
23
23
  bot.command(:random, min_args: 0, max_args: 2, description: 'Generates a random number between 0 and 1, 0 and max or min and max.', usage: 'random [min/max] [max]') do |_event, min, max|
24
24
  if max
25
- rand(min..max)
25
+ rand(min.to_i..max.to_i)
26
26
  elsif min
27
- rand(0..min)
27
+ rand(0..min.to_i)
28
28
  else
29
29
  rand
30
30
  end
data/lib/discordrb/api.rb CHANGED
@@ -305,7 +305,7 @@ module Discordrb::API
305
305
  request(
306
306
  :post,
307
307
  "#{APIBASE}/channels/#{channel_id}/messages",
308
- { content: message, mentions: mentions, tts => tts }.to_json,
308
+ { content: message, mentions: mentions, tts: tts }.to_json,
309
309
  Authorization: token,
310
310
  content_type: :json
311
311
  )
data/lib/discordrb/bot.rb CHANGED
@@ -270,13 +270,13 @@ module Discordrb
270
270
  # directly, you should leave it as true.
271
271
  def voice_destroy(destroy_vws = true)
272
272
  data = {
273
- op: 4,
274
- d: {
275
- guild_id: nil,
276
- channel_id: nil,
277
- self_mute: false,
278
- self_deaf: false
279
- }
273
+ op: 4,
274
+ d: {
275
+ guild_id: nil,
276
+ channel_id: nil,
277
+ self_mute: false,
278
+ self_deaf: false
279
+ }
280
280
  }
281
281
 
282
282
  debug("Voice channel destroy packet is: #{data.to_json}")
@@ -344,11 +344,12 @@ module Discordrb
344
344
  # Sends a text message to a channel given its ID and the message's content.
345
345
  # @param channel_id [Integer] The ID that identifies the channel to send something to.
346
346
  # @param content [String] The text that should be sent as a message. It is limited to 2000 characters (Discord imposed).
347
+ # @param tts [true, false] Whether or not this message should be sent using Discord text-to-speech.
347
348
  # @return [Message] The message that was sent.
348
- def send_message(channel_id, content)
349
+ def send_message(channel_id, content, tts = false)
349
350
  debug("Sending message to #{channel_id} with content '#{content}'")
350
351
 
351
- response = API.send_message(token, channel_id, content)
352
+ response = API.send_message(token, channel_id, content, [], tts)
352
353
  Message.new(JSON.parse(response), self)
353
354
  end
354
355
 
@@ -449,7 +450,7 @@ module Discordrb
449
450
  # @yieldparam event [Event] The event object that was triggered.
450
451
  # @return [Await] The await that was created.
451
452
  def add_await(key, type, attributes = {}, &block)
452
- fail "You can't await an AwaitEvent!" if type == Discordrb::Events::AwaitEvent
453
+ raise "You can't await an AwaitEvent!" if type == Discordrb::Events::AwaitEvent
453
454
  await = Await.new(self, key, type, attributes, block)
454
455
  @awaits ||= {}
455
456
  @awaits[key] = await
@@ -730,11 +731,11 @@ module Discordrb
730
731
 
731
732
  # Login
732
733
  login_response = API.login(@email, @password)
733
- fail Discordrb::Errors::HTTPStatusError, login_response.code if login_response.code >= 400
734
+ raise Discordrb::Errors::HTTPStatusError, login_response.code if login_response.code >= 400
734
735
 
735
736
  # Parse response
736
737
  login_response_object = JSON.parse(login_response)
737
- fail Discordrb::Errors::InvalidAuthenticationError unless login_response_object['token']
738
+ raise Discordrb::Errors::InvalidAuthenticationError unless login_response_object['token']
738
739
 
739
740
  debug('Received token from Discord!')
740
741
 
@@ -805,7 +806,7 @@ module Discordrb
805
806
  debug("Received packet #{event.data}")
806
807
  end
807
808
 
808
- fail 'Invalid Packet' unless packet['op'] == 0 # TODO
809
+ raise 'Invalid Packet' unless packet['op'] == 0 # TODO
809
810
 
810
811
  data = packet['d']
811
812
  type = packet['t'].intern
@@ -71,7 +71,7 @@ module Discordrb::Commands
71
71
  include_commands(container)
72
72
  include_buckets(container)
73
73
  elsif !container_modules.include? Discordrb::EventContainer
74
- fail "Could not include! this particular container - ancestors: #{container_modules}"
74
+ raise "Could not include! this particular container - ancestors: #{container_modules}"
75
75
  end
76
76
  end
77
77
  end
@@ -7,7 +7,7 @@ module Discordrb::Commands
7
7
  # @param time_span [Integer, nil] The time span after which the request count is reset, in seconds, or nil if the bucket should never be reset. (If this is nil, limit should be nil too)
8
8
  # @param delay [Integer, nil] The delay for which the user has to wait after performing a request, in seconds, or nil if the user shouldn't have to wait.
9
9
  def initialize(limit, time_span, delay)
10
- fail ArgumentError, '`limit` and `time_span` have to either both be set or both be nil!' if !limit != !time_span
10
+ raise ArgumentError, '`limit` and `time_span` have to either both be set or both be nil!' if !limit != !time_span
11
11
 
12
12
  @limit = limit
13
13
  @time_span = time_span
@@ -82,7 +82,7 @@ module Discordrb::Commands
82
82
  def resolve_key(thing)
83
83
  return thing.resolve_id if thing.respond_to?(:resolve_id) && !thing.is_a?(String)
84
84
  return thing if thing.is_a?(Integer) || thing.is_a?(Symbol)
85
- fail ArgumentError, "Cannot use a #{thing.class} as a rate limiting key!"
85
+ raise ArgumentError, "Cannot use a #{thing.class} as a rate limiting key!"
86
86
  end
87
87
  end
88
88
 
@@ -330,7 +330,7 @@ module Discordrb
330
330
  # @param container [Module] A module that `extend`s {EventContainer} from which the handlers will be added.
331
331
  def include_events(container)
332
332
  handlers = container.instance_variable_get '@event_handlers'
333
- fail "Couldn't include the container #{container} as it doesn't have any event handlers - have you tried to include a commands container into an event-only bot?" unless handlers
333
+ raise "Couldn't include the container #{container} as it doesn't have any event handlers - have you tried to include a commands container into an event-only bot?" unless handlers
334
334
  @event_handlers ||= {}
335
335
  @event_handlers.merge!(handlers) { |_, old, new| old + new }
336
336
  end
@@ -223,6 +223,10 @@ module Discordrb
223
223
  permission? flag, server, channel
224
224
  end
225
225
  end
226
+
227
+ def inspect
228
+ "<User username=#{@username} id=#{@id} discriminator=#{@discriminator}>"
229
+ end
226
230
  end
227
231
 
228
232
  # This class is a special variant of User that represents the bot's user profile (things like email addresses and the avatar).
@@ -281,6 +285,10 @@ module Discordrb
281
285
  @avatar_id = new_data[:avatar_id] || @avatar_id
282
286
  end
283
287
 
288
+ def inspect
289
+ "<Profile email=#{@email} user=#{super}>"
290
+ end
291
+
284
292
  private
285
293
 
286
294
  def update_server_data(new_data)
@@ -399,6 +407,10 @@ module Discordrb
399
407
  @server.delete_role(@id)
400
408
  end
401
409
 
410
+ def inspect
411
+ "<Role name=#{@name} permissions=#{@permissions.inspect} hoist=#{@hoist} colour=#{@colour.inspect} server=#{@server.inspect}>"
412
+ end
413
+
402
414
  private
403
415
 
404
416
  def update_role_data(new_data)
@@ -470,6 +482,10 @@ module Discordrb
470
482
  end
471
483
 
472
484
  alias_method :revoke, :delete
485
+
486
+ def inspect
487
+ "<Invite code=#{@code} channel=#{@channel} uses=#{@uses} temporary=#{@temporary} revoked=#{@revoked} xkcd=#{@xkcd}>"
488
+ end
473
489
  end
474
490
 
475
491
  # A Discord channel, including data like the topic
@@ -570,9 +586,10 @@ module Discordrb
570
586
 
571
587
  # Sends a message to this channel.
572
588
  # @param content [String] The content to send. Should not be longer than 2000 characters or it will result in an error.
589
+ # @param tts [true, false] Whether or not this message should be sent using Discord text-to-speech.
573
590
  # @return [Message] the message that was sent.
574
- def send_message(content)
575
- @bot.send_message(@id, content)
591
+ def send_message(content, tts = false)
592
+ @bot.send_message(@id, content, tts)
576
593
  end
577
594
 
578
595
  # Sends a file to this channel. If it is an image, it will be embedded.
@@ -650,7 +667,7 @@ module Discordrb
650
667
  # @param amount [Integer] How many messages to delete. Must be 100 or less (Discord limitation)
651
668
  # @raise [ArgumentError] if more than 100 messages are requested.
652
669
  def prune(amount)
653
- fail ArgumentError, "Can't prune more than 100 messages!" if amount > 100
670
+ raise ArgumentError, "Can't prune more than 100 messages!" if amount > 100
654
671
 
655
672
  threads = []
656
673
  history(amount).each do |message|
@@ -700,6 +717,10 @@ module Discordrb
700
717
  alias_method :message, :send_message
701
718
  alias_method :invite, :make_invite
702
719
 
720
+ def inspect
721
+ "<Channel name=#{@name} id=#{@id} topic=\"#{@topic}\" type=#{@type} position=#{@position} server=#{@server}>"
722
+ end
723
+
703
724
  private
704
725
 
705
726
  def update_channel_data
@@ -780,6 +801,10 @@ module Discordrb
780
801
  def from_bot?
781
802
  @author.bot?
782
803
  end
804
+
805
+ def inspect
806
+ "<Message content=\"#{@content}\" id=#{@id} timestamp=#{@timestamp} author=#{@author} channel=#{@channel}>"
807
+ end
783
808
  end
784
809
 
785
810
  # A server on Discord
@@ -1020,6 +1045,10 @@ module Discordrb
1020
1045
  @afk_channel = @bot.channel(@afk_channel_id) if @afk_channel_id != 0 && (!@afk_channel || @afk_channel_id != @afk_channel.id)
1021
1046
  end
1022
1047
 
1048
+ def inspect
1049
+ "<Server name=#{@name} id=#{@id} large=#{@large} region=#{@region} owner=#{@owner} afk_channel_id=#{@afk_channel_id} afk_timeout=#{@afk_timeout}>"
1050
+ end
1051
+
1023
1052
  private
1024
1053
 
1025
1054
  def update_server_data(new_data)
@@ -65,7 +65,7 @@ module Discordrb::Events
65
65
  # Whether or not this event handler matches the given event with its attributes.
66
66
  # @raise [RuntimeError] if this method is called - overwrite it in your event handler!
67
67
  def matches?(_)
68
- fail 'Attempted to call matches?() from a generic EventHandler'
68
+ raise 'Attempted to call matches?() from a generic EventHandler'
69
69
  end
70
70
 
71
71
  # Checks whether this handler matches the given event, and then calls it.
@@ -1,5 +1,5 @@
1
1
  # Discordrb and all its functionality, in this case only the version.
2
2
  module Discordrb
3
3
  # The current version of discordrb.
4
- VERSION = '1.7.4'.freeze
4
+ VERSION = '1.7.5'.freeze
5
5
  end
@@ -30,7 +30,7 @@ module Discordrb::Voice
30
30
  if OPUS_AVAILABLE
31
31
  @opus = Opus::Encoder.new(@sample_rate, @frame_size, @channels)
32
32
  else
33
- fail LoadError, 'Opus unavailable - voice not supported! Please install opus for voice support to work.'
33
+ raise LoadError, 'Opus unavailable - voice not supported! Please install opus for voice support to work.'
34
34
  end
35
35
  end
36
36
 
@@ -91,7 +91,7 @@ module Discordrb::Voice
91
91
  # @param buf [String] The encoded audio data to be encrypted
92
92
  # @return [String] the audio data, encrypted
93
93
  def encrypt_audio(header, buf)
94
- fail 'No secret key found, despite encryption being enabled!' unless @secret_key
94
+ raise 'No secret key found, despite encryption being enabled!' unless @secret_key
95
95
  box = RbNaCl::SecretBox.new(@secret_key)
96
96
 
97
97
  # The nonce is the header of the voice packet with 12 null bytes appended
@@ -119,7 +119,7 @@ module Discordrb::Voice
119
119
  # @param session [String] The voice session ID Discord sends over the regular websocket
120
120
  # @param endpoint [String] The endpoint URL to connect to
121
121
  def initialize(channel, bot, token, session, endpoint)
122
- fail 'RbNaCl is unavailable - unable to create voice bot! Please read https://github.com/meew0/discordrb/wiki/Installing-libsodium' unless RBNACL_AVAILABLE
122
+ raise 'RbNaCl is unavailable - unable to create voice bot! Please read https://github.com/meew0/discordrb/wiki/Installing-libsodium' unless RBNACL_AVAILABLE
123
123
 
124
124
  @channel = channel
125
125
  @bot = bot
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: 1.7.4
4
+ version: 1.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - meew0
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-28 00:00:00.000000000 Z
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faye-websocket
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - '='
158
158
  - !ruby/object:Gem::Version
159
- version: 0.36.0
159
+ version: 0.37.2
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - '='
165
165
  - !ruby/object:Gem::Version
166
- version: 0.36.0
166
+ version: 0.37.2
167
167
  description: A Ruby implementation of the Discord (https://discordapp.com) API.
168
168
  email:
169
169
  - ''