discordrb 1.7.1 → 1.7.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: 0c3fe1d82b773f30ce3cd65fdb933734e0242356
4
- data.tar.gz: 0c28cf978735af1868f3bec8a12c1ee2a12b5cac
3
+ metadata.gz: f91839616b4ad8e792ebfbd149f2ecfcdc50e614
4
+ data.tar.gz: 45afd38f057ffb4d9366eac1bf404bfca064363e
5
5
  SHA512:
6
- metadata.gz: 6f466e2de8b97084a729402eabb301442a27358c20ac362004fb8957ff93444b78a6207176104953f3cfe5d684c549e59801c8b400fbe9229d80e211d903db87
7
- data.tar.gz: 667503328f7ccbd4430c0190790c5e07da68304031e7ef8b93c0f39ec51cc28c12f1762f2f8eeb89afd49140cb433becbde22df38cfb52e5642033a0bbd8cbaf
6
+ metadata.gz: cf7c6250b3fc4bb927d76d7696d9f980559c1018e15a063306bba71d5c172dbd4c00ea01e26d85732fc2d056a1315ecaf672fc6e141d69d669b316d72c61efd6
7
+ data.tar.gz: 786ff878add75d25bdd5f49169f0ecd21515da2371e826dde0b5356d19bdcd293aab6bb842fb3b74109e03a72ee36f518b28fed85deca435e9b8b9bf5a3bb314
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.7.2
4
+ * The `bot` object can now be read from all events, not just from command ones.
5
+ * You can now set the `filter_volume` on VoiceBot, which corresponds to the old way of doing volume handling, in case the new way is too slow for you.
6
+
3
7
  ## 1.7.1
4
8
  * A `clear!` method was added to EventContainer that removes all events from it, so you can overwrite modules by defining them again. (It's unnecessary for CommandContainers because commands can never be duplicate.)
5
9
 
@@ -3,7 +3,7 @@ require 'discordrb/await'
3
3
 
4
4
  module Discordrb::Events
5
5
  # @see Bot#await
6
- class AwaitEvent
6
+ class AwaitEvent < Event
7
7
  # The await that was triggered.
8
8
  # @return [Await] The await
9
9
  attr_reader :await
@@ -2,7 +2,7 @@ require 'discordrb/events/generic'
2
2
 
3
3
  module Discordrb::Events
4
4
  # Raised when a user is banned
5
- class UserBanEvent
5
+ class UserBanEvent < Event
6
6
  # @return [User] the user that was banned
7
7
  attr_reader :user
8
8
 
@@ -3,7 +3,7 @@ require 'discordrb/data'
3
3
 
4
4
  module Discordrb::Events
5
5
  # Raised when a channel is created
6
- class ChannelCreateEvent
6
+ class ChannelCreateEvent < Event
7
7
  attr_reader :type, :topic, :position, :name, :is_private, :id, :server
8
8
 
9
9
  def initialize(data, bot)
@@ -3,7 +3,7 @@ require 'discordrb/data'
3
3
 
4
4
  module Discordrb::Events
5
5
  # Raised when a channel is deleted
6
- class ChannelDeleteEvent
6
+ class ChannelDeleteEvent < Event
7
7
  attr_reader :type, :topic, :position, :name, :is_private, :id, :server
8
8
 
9
9
  def initialize(data, bot)
@@ -3,7 +3,7 @@ require 'discordrb/data'
3
3
 
4
4
  module Discordrb::Events
5
5
  # Raised when a channel is updated (e.g. topic changes)
6
- class ChannelUpdateEvent
6
+ class ChannelUpdateEvent < Event
7
7
  attr_reader :type, :topic, :position, :name, :is_private, :channel, :server
8
8
 
9
9
  def initialize(data, bot)
@@ -49,6 +49,11 @@ module Discordrb::Events
49
49
  end
50
50
  end
51
51
 
52
+ # Generic event class that can be extended
53
+ class Event
54
+ attr_reader :bot
55
+ end
56
+
52
57
  # Generic event handler that can be extended
53
58
  class EventHandler
54
59
  def initialize(attributes, block)
@@ -3,7 +3,7 @@ require 'discordrb/data'
3
3
 
4
4
  module Discordrb::Events
5
5
  # Raised when a role is created on a server
6
- class GuildRoleCreateEvent
6
+ class GuildRoleCreateEvent < Event
7
7
  attr_reader :role, :server
8
8
 
9
9
  def initialize(data, bot)
@@ -3,7 +3,7 @@ require 'discordrb/data'
3
3
 
4
4
  module Discordrb::Events
5
5
  # Raised when a role is deleted from a server
6
- class GuildRoleDeleteEvent
6
+ class GuildRoleDeleteEvent < Event
7
7
  attr_reader :id, :server
8
8
 
9
9
  def initialize(data, bot)
@@ -3,7 +3,7 @@ require 'discordrb/data'
3
3
 
4
4
  module Discordrb::Events
5
5
  # Event raised when a role updates on a server
6
- class GuildRoleUpdateEvent
6
+ class GuildRoleUpdateEvent < Event
7
7
  attr_reader :role, :server
8
8
 
9
9
  def initialize(data, bot)
@@ -3,7 +3,7 @@ require 'discordrb/data'
3
3
 
4
4
  module Discordrb::Events
5
5
  # Generic subclass for server events (create/update/delete)
6
- class GuildEvent
6
+ class GuildEvent < Event
7
7
  attr_reader :server
8
8
 
9
9
  def initialize(data, bot)
@@ -2,13 +2,13 @@ require 'discordrb/events/generic'
2
2
 
3
3
  module Discordrb::Events
4
4
  # @see Discordrb::EventContainer#ready
5
- class ReadyEvent; end
5
+ class ReadyEvent < Event; end
6
6
 
7
7
  # Event handler for {ReadyEvent}
8
8
  class ReadyEventHandler < TrueEventHandler; end
9
9
 
10
10
  # @see Discordrb::EventContainer#disconnected
11
- class DisconnectEvent; end
11
+ class DisconnectEvent < Event; end
12
12
 
13
13
  # Event handler for {DisconnectEvent}
14
14
  class DisconnectEventHandler < TrueEventHandler; end
@@ -3,7 +3,7 @@ require 'discordrb/data'
3
3
 
4
4
  module Discordrb::Events
5
5
  # Generic subclass for server member events (add/update/delete)
6
- class GuildMemberEvent
6
+ class GuildMemberEvent < Event
7
7
  attr_reader :user, :roles, :server
8
8
 
9
9
  def initialize(data, bot)
@@ -2,7 +2,7 @@ require 'discordrb/events/generic'
2
2
 
3
3
  module Discordrb::Events
4
4
  # Event raised when a text message is sent to a channel
5
- class MessageEvent
5
+ class MessageEvent < Event
6
6
  attr_reader :message, :saved_message
7
7
 
8
8
  delegate :author, :channel, :content, :timestamp, to: :message
@@ -123,7 +123,7 @@ module Discordrb::Events
123
123
  class PrivateMessageEventHandler < MessageEventHandler; end
124
124
 
125
125
  # A subset of MessageEvent that only contains a message ID and a channel
126
- class MessageIDEvent
126
+ class MessageIDEvent < Event
127
127
  # @return [Integer] the ID associated with this event
128
128
  attr_reader :id
129
129
 
@@ -3,7 +3,7 @@ require 'discordrb/data'
3
3
 
4
4
  module Discordrb::Events
5
5
  # Event raised when a user's presence state updates (idle or online)
6
- class PresenceEvent
6
+ class PresenceEvent < Event
7
7
  attr_reader :server, :user, :status
8
8
 
9
9
  def initialize(data, bot)
@@ -41,7 +41,7 @@ module Discordrb::Events
41
41
  end
42
42
 
43
43
  # Event raised when a user starts or stops playing a game
44
- class PlayingEvent
44
+ class PlayingEvent < Event
45
45
  attr_reader :server, :user, :game
46
46
 
47
47
  def initialize(data, bot)
@@ -2,7 +2,7 @@ require 'discordrb/events/generic'
2
2
 
3
3
  module Discordrb::Events
4
4
  # Event raised when a user starts typing
5
- class TypingEvent
5
+ class TypingEvent < Event
6
6
  attr_reader :channel, :user, :timestamp
7
7
 
8
8
  def initialize(data, bot)
@@ -3,7 +3,7 @@ require 'discordrb/data'
3
3
 
4
4
  module Discordrb::Events
5
5
  # Event raised when a user's voice state updates
6
- class VoiceStateUpdateEvent
6
+ class VoiceStateUpdateEvent < Event
7
7
  attr_reader :user, :token, :suppress, :session_id, :self_mute, :self_deaf, :mute, :deaf, :server, :channel
8
8
 
9
9
  def initialize(data, bot)
@@ -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.1'.freeze
4
+ VERSION = '1.7.2'.freeze
5
5
  end
@@ -16,11 +16,16 @@ module Discordrb::Voice
16
16
  # @return [true, false] whether avconv should be used instead of ffmpeg.
17
17
  attr_accessor :use_avconv
18
18
 
19
+ # @see VoiceBot#filter_volume=
20
+ # @return [Integer] the volume used as a filter to ffmpeg/avconv.
21
+ attr_accessor :filter_volume
22
+
19
23
  # Create a new encoder
20
24
  def initialize
21
25
  @sample_rate = 48_000
22
26
  @frame_size = 960
23
27
  @channels = 2
28
+ @filter_volume = 1
24
29
 
25
30
  if OPUS_AVAILABLE
26
31
  @opus = Opus::Encoder.new(@sample_rate, @frame_size, @channels)
@@ -73,7 +78,7 @@ module Discordrb::Voice
73
78
  # @param file [String] The path or URL to encode.
74
79
  # @return [IO] the audio, encoded as s16le PCM
75
80
  def encode_file(file)
76
- command = "#{ffmpeg_command} -loglevel 0 -i \"#{file}\" -f s16le -ar 48000 -ac 2 pipe:1"
81
+ command = "#{ffmpeg_command} -loglevel 0 -i \"#{file}\" -f s16le -ar 48000 -ac 2 #{filter_volume_argument} pipe:1"
77
82
  IO.popen(command)
78
83
  end
79
84
 
@@ -83,7 +88,7 @@ module Discordrb::Voice
83
88
  # @return [IO] the audio, encoded as s16le PCM
84
89
  def encode_io(io)
85
90
  ret_io, writer = IO.pipe
86
- command = "#{ffmpeg_command} -loglevel 0 -i - -f s16le -ar 48000 -ac 2 pipe:1"
91
+ command = "#{ffmpeg_command} -loglevel 0 -i - -f s16le -ar 48000 -ac 2 #{filter_volume_argument} pipe:1"
87
92
  spawn(command, in: io, out: writer)
88
93
  ret_io
89
94
  end
@@ -93,5 +98,10 @@ module Discordrb::Voice
93
98
  def ffmpeg_command
94
99
  @use_avconv ? 'avconv' : 'ffmpeg'
95
100
  end
101
+
102
+ def filter_volume_argument
103
+ return '' if @filter_volume == 1
104
+ @use_avconv ? "-vol #{(@filter_volume * 256).ceil}" : "-af volume=#{@filter_volume}"
105
+ end
96
106
  end
97
107
  end
@@ -92,6 +92,19 @@ module Discordrb::Voice
92
92
  @udp.encrypted?
93
93
  end
94
94
 
95
+ # Set the filter volume. This volume is applied as a filter for decoded audio data. It has the advantage that using
96
+ # it is much faster than regular volume, but it can only be changed before starting to play something.
97
+ # @param value [Integer] The value to set the volume to. For possible values, see {#volume}
98
+ def filter_volume=(value)
99
+ @encoder.filter_volume = value
100
+ end
101
+
102
+ # @see #filter_volume=
103
+ # @return [Integer] the volume used as a filter for ffmpeg/avconv.
104
+ def filter_volume
105
+ @encoder.filter_volume
106
+ end
107
+
95
108
  # Pause playback. This is not instant; it may take up to 20 ms for this change to take effect. (This is usually
96
109
  # negligible.)
97
110
  def pause
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.1
4
+ version: 1.7.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-02-23 00:00:00.000000000 Z
11
+ date: 2016-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faye-websocket