discordrb 1.7.3 → 1.7.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: bcde95d0c926eba8368ed3553686b396a4a500db
4
- data.tar.gz: 387df5587eaeab2eb24a8cb085ea4e951ffff3bf
3
+ metadata.gz: 36dd991249332783c1bd50f94ddbb555cc8483d2
4
+ data.tar.gz: 2b68f3bb825c2e6f49290356d7f7ebcbbb8e509e
5
5
  SHA512:
6
- metadata.gz: 3374e7195c49d28d84cd936ff1e44b5232bbc65ad7df4fae6e9a22c2047730086b254af9e4ffde0d38c9b9a203be80fd8b1d86ef659816f9ee17fe6f3d39ca72
7
- data.tar.gz: 271acc3f47814bf89b188fe02038d106a16c016b10eca67630a423e416a32c21815e743204a9028ed20991b4af5217860511690e04223c2e303d70da1c0205c4
6
+ metadata.gz: b22aa3bfb28c470f931eec7e060414f349e3cd46c29cd725cdc3235e372ece0dbaccd1d72b7b6077afb0f12b76ed112abc869a844acb152c5e8eb2e0c1ef0210
7
+ data.tar.gz: 12ee016ea86fb2fcd721855f32466552b4e471212c247005b864c416359b969e1b5ce943141eceede6177405d12c2b210f364533a55a44210fb0ab8e96eb90f9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.7.4
4
+ * Added methods `Channel#text?` and `Channel#voice?` to check a channel's type.
5
+ * Frequently allocated strings have been turned into symbols or frozen constants, this should improve performance slightly.
6
+
7
+ ### Bugfixes
8
+ * `VoiceBot#destroy` will now properly disconnect you and should no longer cause segfaults.
9
+ * Fixed a bug where you couldn't set any settings on a role created using `Server#create_role`.
10
+ * Fixed `Profile#avatar=` doing absolutely nothing.
11
+
3
12
  ## 1.7.3
4
13
  * The server banlist can now be accessed more nicely using `Server#bans`.
5
14
  * Some abstractions for OAuth application creation were added - `bot.create_oauth_application` and `bot.update_oauth_application`. See the docs about how to use them.
data/lib/discordrb/bot.rb CHANGED
@@ -265,6 +265,27 @@ module Discordrb
265
265
  @voice
266
266
  end
267
267
 
268
+ # Disconnects the client from all voice connections across Discord.
269
+ # @param destroy_vws [true, false] Whether or not the VWS should also be destroyed. If you're calling this method
270
+ # directly, you should leave it as true.
271
+ def voice_destroy(destroy_vws = true)
272
+ data = {
273
+ op: 4,
274
+ d: {
275
+ guild_id: nil,
276
+ channel_id: nil,
277
+ self_mute: false,
278
+ self_deaf: false
279
+ }
280
+ }
281
+
282
+ debug("Voice channel destroy packet is: #{data.to_json}")
283
+ @ws.send(data.to_json)
284
+
285
+ @voice.destroy if @voice && destroy_vws
286
+ @voice = nil
287
+ end
288
+
268
289
  # Revokes an invite to a server. Will fail unless you have the *Manage Server* permission.
269
290
  # It is recommended that you use {Invite#delete} instead.
270
291
  # @param code [String, Invite] The invite to revoke. For possible formats see {#resolve_invite_code}.
@@ -787,8 +808,9 @@ module Discordrb
787
808
  fail 'Invalid Packet' unless packet['op'] == 0 # TODO
788
809
 
789
810
  data = packet['d']
790
- case packet['t']
791
- when 'READY'
811
+ type = packet['t'].intern
812
+ case type
813
+ when :READY
792
814
  # Activate the heartbeats
793
815
  @heartbeat_interval = data['heartbeat_interval'].to_f / 1000.0
794
816
  @heartbeat_active = true
@@ -830,7 +852,7 @@ module Discordrb
830
852
 
831
853
  # Tell the run method that everything was successful
832
854
  @ws_success = true
833
- when 'GUILD_MEMBERS_CHUNK'
855
+ when :GUILD_MEMBERS_CHUNK
834
856
  id = data['guild_id'].to_i
835
857
  members = data['members']
836
858
 
@@ -850,7 +872,7 @@ module Discordrb
850
872
  else
851
873
  debug "Got one chunk for server #{id}, parsing took #{duration} seconds"
852
874
  end
853
- when 'MESSAGE_CREATE'
875
+ when :MESSAGE_CREATE
854
876
  create_message(data)
855
877
 
856
878
  message = Message.new(data, self)
@@ -869,22 +891,22 @@ module Discordrb
869
891
  event = PrivateMessageEvent.new(message, self)
870
892
  raise_event(event)
871
893
  end
872
- when 'MESSAGE_UPDATE'
894
+ when :MESSAGE_UPDATE
873
895
  update_message(data)
874
896
 
875
897
  event = MessageEditEvent.new(data, self)
876
898
  raise_event(event)
877
- when 'MESSAGE_DELETE'
899
+ when :MESSAGE_DELETE
878
900
  delete_message(data)
879
901
 
880
902
  event = MessageDeleteEvent.new(data, self)
881
903
  raise_event(event)
882
- when 'TYPING_START'
904
+ when :TYPING_START
883
905
  start_typing(data)
884
906
 
885
907
  event = TypingEvent.new(data, self)
886
908
  raise_event(event)
887
- when 'PRESENCE_UPDATE'
909
+ when :PRESENCE_UPDATE
888
910
  now_playing = data['game']
889
911
  presence_user = user(data['user']['id'].to_i)
890
912
  played_before = presence_user.nil? ? nil : presence_user.game
@@ -897,81 +919,81 @@ module Discordrb
897
919
  end
898
920
 
899
921
  raise_event(event)
900
- when 'VOICE_STATE_UPDATE'
922
+ when :VOICE_STATE_UPDATE
901
923
  update_voice_state(data)
902
924
 
903
925
  event = VoiceStateUpdateEvent.new(data, self)
904
926
  raise_event(event)
905
- when 'VOICE_SERVER_UPDATE'
927
+ when :VOICE_SERVER_UPDATE
906
928
  update_voice_server(data)
907
929
 
908
930
  # no event as this is irrelevant to users
909
- when 'CHANNEL_CREATE'
931
+ when :CHANNEL_CREATE
910
932
  create_channel(data)
911
933
 
912
934
  event = ChannelCreateEvent.new(data, self)
913
935
  raise_event(event)
914
- when 'CHANNEL_UPDATE'
936
+ when :CHANNEL_UPDATE
915
937
  update_channel(data)
916
938
 
917
939
  event = ChannelUpdateEvent.new(data, self)
918
940
  raise_event(event)
919
- when 'CHANNEL_DELETE'
941
+ when :CHANNEL_DELETE
920
942
  delete_channel(data)
921
943
 
922
944
  event = ChannelDeleteEvent.new(data, self)
923
945
  raise_event(event)
924
- when 'GUILD_MEMBER_ADD'
946
+ when :GUILD_MEMBER_ADD
925
947
  add_guild_member(data)
926
948
 
927
949
  event = GuildMemberAddEvent.new(data, self)
928
950
  raise_event(event)
929
- when 'GUILD_MEMBER_UPDATE'
951
+ when :GUILD_MEMBER_UPDATE
930
952
  update_guild_member(data)
931
953
 
932
954
  event = GuildMemberUpdateEvent.new(data, self)
933
955
  raise_event(event)
934
- when 'GUILD_MEMBER_REMOVE'
956
+ when :GUILD_MEMBER_REMOVE
935
957
  delete_guild_member(data)
936
958
 
937
959
  event = GuildMemberDeleteEvent.new(data, self)
938
960
  raise_event(event)
939
- when 'GUILD_BAN_ADD'
961
+ when :GUILD_BAN_ADD
940
962
  add_user_ban(data)
941
963
 
942
964
  event = UserBanEvent.new(data, self)
943
965
  raise_event(event)
944
- when 'GUILD_BAN_REMOVE'
966
+ when :GUILD_BAN_REMOVE
945
967
  remove_user_ban(data)
946
968
 
947
969
  event = UserUnbanEvent.new(data, self)
948
970
  raise_event(event)
949
- when 'GUILD_ROLE_UPDATE'
971
+ when :GUILD_ROLE_UPDATE
950
972
  update_guild_role(data)
951
973
 
952
974
  event = GuildRoleUpdateEvent.new(data, self)
953
975
  raise_event(event)
954
- when 'GUILD_ROLE_CREATE'
976
+ when :GUILD_ROLE_CREATE
955
977
  create_guild_role(data)
956
978
 
957
979
  event = GuildRoleCreateEvent.new(data, self)
958
980
  raise_event(event)
959
- when 'GUILD_ROLE_DELETE'
981
+ when :GUILD_ROLE_DELETE
960
982
  delete_guild_role(data)
961
983
 
962
984
  event = GuildRoleDeleteEvent.new(data, self)
963
985
  raise_event(event)
964
- when 'GUILD_CREATE'
986
+ when :GUILD_CREATE
965
987
  create_guild(data)
966
988
 
967
989
  event = GuildCreateEvent.new(data, self)
968
990
  raise_event(event)
969
- when 'GUILD_UPDATE'
991
+ when :GUILD_UPDATE
970
992
  update_guild(data)
971
993
 
972
994
  event = GuildUpdateEvent.new(data, self)
973
995
  raise_event(event)
974
- when 'GUILD_DELETE'
996
+ when :GUILD_DELETE
975
997
  delete_guild(data)
976
998
 
977
999
  event = GuildDeleteEvent.new(data, self)
@@ -262,7 +262,7 @@ module Discordrb
262
262
  # Changes the bot's avatar.
263
263
  # @param avatar [String, File] A JPG file to be used as the avatar, either as a File object or as a base64-encoded String.
264
264
  def avatar=(avatar)
265
- if avatar.is_a? File
265
+ if avatar.respond_to? :read
266
266
  avatar_string = 'data:image/jpg;base64,'
267
267
  avatar_string += Base64.strict_encode64(avatar.read)
268
268
  update_server_data(avatar: avatar_string)
@@ -288,7 +288,7 @@ module Discordrb
288
288
  new_data[:email] || @email,
289
289
  @password,
290
290
  new_data[:username] || @username,
291
- new_data[:avatar_id] || @avatar_id,
291
+ new_data[:avatar],
292
292
  new_data[:new_password] || nil)
293
293
  update_data(new_data)
294
294
  end
@@ -474,10 +474,13 @@ module Discordrb
474
474
 
475
475
  # A Discord channel, including data like the topic
476
476
  class Channel
477
+ TEXT_TYPE = 'text'.freeze
478
+ VOICE_TYPE = 'voice'.freeze
479
+
477
480
  # @return [String] this channel's name.
478
481
  attr_reader :name
479
482
 
480
- # @return [Server] the server this channel is on.
483
+ # @return [Server, nil] the server this channel is on. If this channel is a PM channel, it will be nil.
481
484
  attr_reader :server
482
485
 
483
486
  # @return [String] the type of this channel (currently either 'text' or 'voice')
@@ -523,7 +526,7 @@ module Discordrb
523
526
  data = data[-1] if data.is_a?(Array)
524
527
 
525
528
  @id = data['id'].to_i
526
- @type = data['type'] || 'text'
529
+ @type = data['type'] || TEXT_TYPE
527
530
  @topic = data['topic']
528
531
  @position = data['position']
529
532
 
@@ -555,6 +558,16 @@ module Discordrb
555
558
  Discordrb.id_compare(@id, other)
556
559
  end
557
560
 
561
+ # @return [true, false] whether or not this channel is a text channel
562
+ def text?
563
+ @type == TEXT_TYPE
564
+ end
565
+
566
+ # @return [true, false] whether or not this channel is a voice channel
567
+ def voice?
568
+ @type == VOICE_TYPE
569
+ end
570
+
558
571
  # Sends a message to this channel.
559
572
  # @param content [String] The content to send. Should not be longer than 2000 characters or it will result in an error.
560
573
  # @return [Message] the message that was sent.
@@ -905,7 +918,7 @@ module Discordrb
905
918
  # @return [Role] the created role.
906
919
  def create_role
907
920
  response = API.create_role(@bot.token, @id)
908
- role = Role.new(JSON.parse(response), @bot)
921
+ role = Role.new(JSON.parse(response), @bot, self)
909
922
  @roles << role
910
923
  role
911
924
  end
@@ -11,6 +11,16 @@ module Discordrb::Events
11
11
  # The event that triggered the await.
12
12
  # @return [Event] The event
13
13
  attr_reader :event
14
+
15
+ # @!attribute [r] key
16
+ # @return [Symbol] the await's key.
17
+ # @see Await#key
18
+ # @!attribute [r] type
19
+ # @return [Class] the await's event class.
20
+ # @see Await#type
21
+ # @!attribute [r] attributes
22
+ # @return [Hash] a hash of attributes defined on the await.
23
+ # @see Await#attributes
14
24
  delegate :key, :type, :attributes, to: :await
15
25
 
16
26
  # For internal use only
@@ -5,7 +5,23 @@ module Discordrb::Events
5
5
  class MessageEvent < Event
6
6
  attr_reader :message, :saved_message
7
7
 
8
+ # @!attribute [r] author
9
+ # @return [User] who sent this message.
10
+ # @see Message#author
11
+ # @!attribute [r] channel
12
+ # @return [Channel] the channel in which this message was sent.
13
+ # @see Message#channel
14
+ # @!attribute [r] content
15
+ # @return [String] the message's content.
16
+ # @see Message#content
17
+ # @!attribute [r] timestamp
18
+ # @return [Time] the time at which the message was sent.
19
+ # @see Message#timestamp
8
20
  delegate :author, :channel, :content, :timestamp, to: :message
21
+
22
+ # @!attribute [r] server
23
+ # @return [Server, nil] the server where this message was sent, or nil if it was sent in PM.
24
+ # @see Channel#server
9
25
  delegate :server, to: :channel
10
26
 
11
27
  def initialize(message, bot)
@@ -1,4 +1,6 @@
1
1
  module Discordrb
2
+ LOG_TIMESTAMP_FORMAT = '%Y-%m-%d %H:%M:%S.%L %z'.freeze
3
+
2
4
  # Logs debug messages
3
5
  class Logger
4
6
  # @return [true, false] whether or not this logger should be in debug mode (all debug messages will be printed)
@@ -7,7 +9,7 @@ module Discordrb
7
9
  # Writes a debug message to the console.
8
10
  # @param important [true, false] Whether this message should be printed regardless of debug mode being on or off.
9
11
  def debug(message, important = false)
10
- puts "[DEBUG : #{Thread.current[:discordrb_name]} @ #{Time.now.strftime('%Y-%m-%d %H:%M:%S.%L %z')}] #{message}" if @debug || important
12
+ puts "[DEBUG : #{Thread.current[:discordrb_name]} @ #{Time.now.strftime(LOG_TIMESTAMP_FORMAT)}] #{message}" if @debug || important
11
13
  end
12
14
 
13
15
  # Logs an exception to the console.
@@ -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.3'.freeze
4
+ VERSION = '1.7.4'.freeze
5
5
  end
@@ -47,11 +47,6 @@ module Discordrb::Voice
47
47
  @opus.encode(buffer, 1920)
48
48
  end
49
49
 
50
- # Destroys this encoder and the opus connection, preventing any future encodings.
51
- def destroy
52
- @opus.destroy
53
- end
54
-
55
50
  # Adjusts the volume of a given buffer of s16le PCM data.
56
51
  # @param buf [String] An unencoded PCM (s16le) buffer.
57
52
  # @param mult [Float] The volume multiplier, 1 for same volume.
@@ -256,7 +256,7 @@ module Discordrb::Voice
256
256
 
257
257
  # Disconnects the websocket and kills the thread
258
258
  def destroy
259
- @thread.kill if @thread
259
+ @heartbeat_running = false
260
260
  end
261
261
 
262
262
  private
@@ -267,7 +267,8 @@ module Discordrb::Voice
267
267
  end
268
268
 
269
269
  def heartbeat_loop
270
- loop do
270
+ @heartbeat_running = true
271
+ while @heartbeat_running
271
272
  if @heartbeat_interval
272
273
  sleep @heartbeat_interval / 1000.0
273
274
  send_heartbeat
@@ -288,8 +289,8 @@ module Discordrb::Voice
288
289
 
289
290
  @client.on(:open) { instance.websocket_open }
290
291
  @client.on(:message) { |msg| instance.websocket_message(msg.data) }
291
- @client.on(:error) { |e| puts e.to_s }
292
- @client.on(:close) { |e| puts e.to_s }
292
+ @client.on(:error) { |e| puts "VWS error: #{e}" }
293
+ @client.on(:close) { |e| puts "VWS close: #{e}" }
293
294
 
294
295
  # Block any further execution
295
296
  heartbeat_loop
@@ -141,8 +141,8 @@ module Discordrb::Voice
141
141
  # Permanently disconnects from the voice channel; to reconnect you will have to call {Bot#voice_connect} again.
142
142
  def destroy
143
143
  stop_playing
144
+ @bot.voice_destroy(false)
144
145
  @ws.destroy
145
- @encoder.destroy
146
146
  end
147
147
 
148
148
  # Plays a stream of raw data to the channel. All playback methods are blocking, i. e. they wait for the playback to
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.3
4
+ version: 1.7.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-02-27 00:00:00.000000000 Z
11
+ date: 2016-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faye-websocket