discordrb 2.0.3 → 2.0.4

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: e85a40f2b3cc06af57ecf04357e35453c6fc48ef
4
- data.tar.gz: a5b5ff40e9ae47db4875392e74f6a4ce8d91bf2e
3
+ metadata.gz: 86b237c8122ce65285f26a72379d063594d64468
4
+ data.tar.gz: 676f4b7428f7f01a670eff05c85d7a14092affab
5
5
  SHA512:
6
- metadata.gz: cde28c5fa4b45858fa2646b19a677a8d59659d3abeb6b3b0a33f0808d6e9ec5ef830dc73be77fc05d6bb5392204a0d61742adc1fc7331b564ef38183ac47d96d
7
- data.tar.gz: 02f17a29a2ebeec59047a799ce9a3564123dc7fdf8962d2940110738cb0285e8ee51daed9e5130ff5667f2621c588c689ec203c6e6f0fb282f6727b233ecef2a
6
+ metadata.gz: 0f18865d96e89381d9aad624558331915f90bfe622f9ed0e280d7c04a3702676548e0ab093b38523fb620aef0212c5415dd39e8d14428950d38ce923d706bc10
7
+ data.tar.gz: 54533279a8439c4dbadefe1bb2e70f6c660565f10dcb544fa6aa389e9ccaf7b0611857a5f8bd1055e771fc11b555b05ab030d11b4ad9c837752e0fd851cfce73
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.4
4
+
5
+ - Added a utility method `Invite#url` ([#86](https://github.com/meew0/discordrb/issues/86)/[#101](https://github.com/meew0/discordrb/pull/101), thanks @PoVa)
6
+
7
+ ### Bugfixes
8
+
9
+ - Fix a caching inconsistency where a server's channels and a bot's channels wouldn't be identical. This caused server channels to not update properly ([#105](https://github.com/meew0/discordrb/issues/105))
10
+ - Setting avatars should now work again on Windows ([#96](https://github.com/meew0/discordrb/issues/96))
11
+ - Message edit events should no longer be raised with nil authors ([#95](https://github.com/meew0/discordrb/issues/95))
12
+ - Invites can now be created again ([#87](https://github.com/meew0/discordrb/issues/87))
13
+ - Voice states are now preserved for chunked members, fixes an issue where a voice channel's users would ignore all voice states that occurred before the call ([#103](https://github.com/meew0/discordrb/issues/103))
14
+ - Fixed some possible problems with heartbeats not being sent with unstable connections
15
+
3
16
  ## 2.0.3
4
17
 
5
18
  - All examples now fully use v2 ([#92](https://github.com/meew0/discordrb/pull/92), thanks @snapcase)
data/examples/ping.rb CHANGED
@@ -4,6 +4,11 @@ require 'discordrb'
4
4
 
5
5
  bot = Discordrb::Bot.new token: 'B0T.T0KEN.here', application_id: 160123456789876543
6
6
 
7
+ # Here we output the invite URL to the console so the bot account can be invited to the channel. This only has to be
8
+ # done once, afterwards, you can remove this part if you want
9
+ puts "This bot's invite URL is #{bot.invite_url}."
10
+ puts 'Click on it to invite it to your server.'
11
+
7
12
  bot.message(with_text: 'Ping!') do |event|
8
13
  event.respond 'Pong!'
9
14
  end
data/lib/discordrb/bot.rb CHANGED
@@ -228,8 +228,12 @@ module Discordrb
228
228
  @heartbeat_thread = Thread.new do
229
229
  Thread.current[:discordrb_name] = 'heartbeat'
230
230
  loop do
231
- sleep @heartbeat_interval
232
- send_heartbeat if @heartbeat_active
231
+ if @heartbeat_active
232
+ send_heartbeat
233
+ sleep @heartbeat_interval
234
+ else
235
+ sleep 1
236
+ end
233
237
  end
234
238
  end
235
239
 
@@ -1007,6 +1011,7 @@ module Discordrb
1007
1011
  @heartbeat_interval = data['heartbeat_interval'].to_f / 1000.0
1008
1012
  @heartbeat_active = true
1009
1013
  debug("Desired heartbeat_interval: #{@heartbeat_interval}")
1014
+ send_heartbeat
1010
1015
 
1011
1016
  @profile = Profile.new(data['user'], self, @email, @password)
1012
1017
 
@@ -1089,6 +1094,11 @@ module Discordrb
1089
1094
  message = Message.new(data, self)
1090
1095
  return if message.from_bot? && !should_parse_self
1091
1096
 
1097
+ unless message.author
1098
+ LOGGER.warn("Edited a message with nil author! Content: #{message.content.inspect}, channel: #{message.channel.inspect}")
1099
+ return
1100
+ end
1101
+
1092
1102
  event = MessageEditEvent.new(message, self)
1093
1103
  raise_event(event)
1094
1104
  when :MESSAGE_DELETE
@@ -1340,6 +1350,9 @@ module Discordrb
1340
1350
  }
1341
1351
 
1342
1352
  @ws.send(data.to_json)
1353
+ rescue => e
1354
+ LOGGER.error('Got an error while sending a heartbeat! Carrying on anyway because heartbeats are vital for the connection to stay alive')
1355
+ LOGGER.log_exception(e)
1343
1356
  end
1344
1357
 
1345
1358
  def raise_event(event)
@@ -129,12 +129,13 @@ module Discordrb
129
129
 
130
130
  # Ensures a given channel object is cached and if not, cache it from the given data hash.
131
131
  # @param data [Hash] A data hash representing a channel.
132
+ # @param server [Server, nil] The server the channel is on, if known.
132
133
  # @return [Channel] the channel represented by the data hash.
133
- def ensure_channel(data)
134
+ def ensure_channel(data, server = nil)
134
135
  if @channels.include?(data['id'].to_i)
135
136
  @channels[data['id'].to_i]
136
137
  else
137
- @channels[data['id'].to_i] = Channel.new(data, self)
138
+ @channels[data['id'].to_i] = Channel.new(data, self, server)
138
139
  end
139
140
  end
140
141
 
@@ -218,6 +218,14 @@ module Discordrb
218
218
  attr_reader :deaf
219
219
  alias_method :deafened?, :deaf
220
220
 
221
+ # @return [true, false] whether this member has muted themselves.
222
+ attr_reader :self_mute
223
+ alias_method :self_muted?, :self_mute
224
+
225
+ # @return [true, false] whether this member has deafened themselves.
226
+ attr_reader :self_deaf
227
+ alias_method :self_deafened?, :self_deaf
228
+
221
229
  # @return [Time] when this member joined the server.
222
230
  attr_reader :joined_at
223
231
 
@@ -480,6 +488,9 @@ module Discordrb
480
488
  # something readable (e. g. File) or as a data URL.
481
489
  def avatar=(avatar)
482
490
  if avatar.respond_to? :read
491
+ # Set the file to binary mode if supported, so we don't get problems with Windows
492
+ avatar.binmode if avatar.respond_to?(:binmode)
493
+
483
494
  avatar_string = 'data:image/jpg;base64,'
484
495
  avatar_string += Base64.strict_encode64(avatar.read)
485
496
  update_profile_data(avatar: avatar_string)
@@ -631,12 +642,53 @@ module Discordrb
631
642
  end
632
643
  end
633
644
 
645
+ # A channel referenced by an invite. It has less data than regular channels, so it's a separate class
646
+ class InviteChannel
647
+ include IDObject
648
+
649
+ # @return [String] this channel's name.
650
+ attr_reader :name
651
+
652
+ # @return [String] this channel's type (text or voice)
653
+ attr_reader :type
654
+
655
+ # @!visibility private
656
+ def initialize(data, bot)
657
+ @bot = bot
658
+
659
+ @id = data['id'].to_i
660
+ @name = data['name']
661
+ @type = data['type']
662
+ end
663
+ end
664
+
665
+ # A server referenced to by an invite
666
+ class InviteServer
667
+ include IDObject
668
+
669
+ # @return [String] this server's name.
670
+ attr_reader :name
671
+
672
+ # @return [String, nil] the hash of the server's invite splash screen (for partnered servers) or nil if none is
673
+ # present
674
+ attr_reader :splash_hash
675
+
676
+ # @!visibility private
677
+ def initialize(data, bot)
678
+ @bot = bot
679
+
680
+ @id = data['id'].to_i
681
+ @name = data['name']
682
+ @splash_hash = data['splash_hash']
683
+ end
684
+ end
685
+
634
686
  # A Discord invite to a channel
635
687
  class Invite
636
- # @return [Channel] the channel this invite references.
688
+ # @return [InviteChannel] the channel this invite references.
637
689
  attr_reader :channel
638
690
 
639
- # @return [Server] the server this invite references.
691
+ # @return [InviteServer] the server this invite references.
640
692
  attr_reader :server
641
693
 
642
694
  # @return [Integer] the amount of uses left on this invite.
@@ -668,8 +720,8 @@ module Discordrb
668
720
  def initialize(data, bot)
669
721
  @bot = bot
670
722
 
671
- @channel = Channel.new(data['channel'], bot)
672
- @server = Server.new(data['guild'], bot)
723
+ @channel = InviteChannel.new(data['channel'], bot)
724
+ @server = InviteServer.new(data['guild'], bot)
673
725
  @uses = data['uses']
674
726
  @inviter = data['inviter'] ? (@bot.user(data['inviter']['id'].to_i) || User.new(data['inviter'], bot)) : nil
675
727
  @temporary = data['temporary']
@@ -695,6 +747,11 @@ module Discordrb
695
747
  def inspect
696
748
  "<Invite code=#{@code} channel=#{@channel} uses=#{@uses} temporary=#{@temporary} revoked=#{@revoked} xkcd=#{@xkcd}>"
697
749
  end
750
+
751
+ # Creates an invite URL.
752
+ def url
753
+ "https://discord.gg/#{@code}"
754
+ end
698
755
  end
699
756
 
700
757
  # A Discord channel, including data like the topic
@@ -1461,6 +1518,17 @@ module Discordrb
1461
1518
  return unless members
1462
1519
  members.each do |element|
1463
1520
  member = Member.new(element, self, @bot)
1521
+ if @members[member.id] && @members[member.id].voice_channel
1522
+ @bot.debug("Preserving voice state of member #{member.id} while chunking")
1523
+ old_member = @members[member.id]
1524
+ member.update_voice_state(
1525
+ old_member.voice_channel,
1526
+ old_member.mute,
1527
+ old_member.deaf,
1528
+ old_member.self_mute,
1529
+ old_member.self_deaf
1530
+ )
1531
+ end
1464
1532
  @members[member.id] = member
1465
1533
  end
1466
1534
  end
@@ -1485,7 +1553,7 @@ module Discordrb
1485
1553
 
1486
1554
  return unless channels
1487
1555
  channels.each do |element|
1488
- channel = Channel.new(element, @bot, self)
1556
+ channel = @bot.ensure_channel(element, self)
1489
1557
  @channels << channel
1490
1558
  @channels_by_id[channel.id] = channel
1491
1559
  end
@@ -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.3'.freeze
6
+ VERSION = '2.0.4'.freeze
7
7
  end
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.3
4
+ version: 2.0.4
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-15 00:00:00.000000000 Z
11
+ date: 2016-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client