discordrb 1.5.3 → 1.5.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/discordrb.gemspec +1 -0
- data/lib/discordrb/bot.rb +26 -7
- data/lib/discordrb/data.rb +0 -4
- data/lib/discordrb/version.rb +1 -1
- data/lib/discordrb/voice/encoder.rb +18 -4
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e493737a94960682725acf9687de8219edac74a
|
4
|
+
data.tar.gz: ea16d4b131834bbc0a6c040e6632a0296d5c1b26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 369259ee5a1536ab978068f4d726d1c2257ab16f1174ec4939e9b67e3268263e8bf20e1ed804745851d0e52cb5bed69e40c42d9e13282334b8006b19d2388b74
|
7
|
+
data.tar.gz: 8e8c09b5f222675d62f8b2126cf1e97168d0c1b0dc0bf384f4162ddd1f90d79c33d54ac13c26498436488b831872def2f2b3aa554bc9aa950a3c1ea450da1d20
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.5.4
|
4
|
+
* The `opus-ruby` and `levenshtein` dependencies are now optional - if you don't need them, it won't crash immediately (only when you try to use voice / `find` with a threshold > 0, respectively)
|
5
|
+
|
6
|
+
### Bugfixes
|
7
|
+
* Voice volume can now be properly set when using avconv (#37, thanks @purintai)
|
8
|
+
* `websocket-client-simple`, which is required for voice, is now specified in the dependencies.
|
9
|
+
|
3
10
|
## 1.5.3
|
4
11
|
* Voice bot length adjustments are now configurable using `bot.voice.adjust_interval` and `bot.voice.adjust_offset` (make sure the latter is less than the first, or no adjustment will be performed at all)
|
5
12
|
* Length adjustments can now be made more smooth using `bot.voice.adjust_average` (true allows for more smooth adjustments, *may* improve stutteriness but might make it worse as well)
|
data/discordrb.gemspec
CHANGED
data/lib/discordrb/bot.rb
CHANGED
@@ -264,20 +264,30 @@ module Discordrb
|
|
264
264
|
# the threshold is, the more misspellings will be allowed.
|
265
265
|
# @return [Array<Channel>] The array of channels that were found. May be empty if none were found.
|
266
266
|
def find(channel_name, server_name = nil, threshold = 0)
|
267
|
-
|
267
|
+
begin
|
268
|
+
require 'levenshtein' if threshold > 0
|
269
|
+
levenshtein_available = true
|
270
|
+
rescue LoadError; levenshtein_available = false; end
|
268
271
|
|
269
272
|
results = []
|
270
273
|
@servers.values.each do |server|
|
271
274
|
server.channels.each do |channel|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
+
if threshold > 0
|
276
|
+
fail LoadError, 'Levenshtein distance unavailable! Either set threshold to 0 or install the `levenshtein-ffi` gem' unless levenshtein_available
|
277
|
+
distance = Levenshtein.distance(channel.name, channel_name)
|
278
|
+
distance += Levenshtein.distance(server_name || server.name, server.name)
|
279
|
+
next if distance > threshold
|
280
|
+
else
|
281
|
+
distance = 0
|
282
|
+
next if channel.name != channel_name || (server_name || server.name) != server.name
|
283
|
+
end
|
275
284
|
|
276
285
|
# Make a singleton accessor "distance"
|
277
286
|
channel.instance_variable_set(:@distance, distance)
|
278
287
|
class << channel
|
279
288
|
attr_reader :distance
|
280
289
|
end
|
290
|
+
|
281
291
|
results << channel
|
282
292
|
end
|
283
293
|
end
|
@@ -291,12 +301,21 @@ module Discordrb
|
|
291
301
|
# the threshold is, the more misspellings will be allowed.
|
292
302
|
# @return [Array<User>] The array of users that were found. May be empty if none were found.
|
293
303
|
def find_user(username, threshold = 0)
|
294
|
-
|
304
|
+
begin
|
305
|
+
require 'levenshtein' if threshold > 0
|
306
|
+
levenshtein_available = true
|
307
|
+
rescue LoadError; levenshtein_available = false; end
|
295
308
|
|
296
309
|
results = []
|
297
310
|
@users.values.each do |user|
|
298
|
-
|
299
|
-
|
311
|
+
if threshold > 0
|
312
|
+
fail LoadError, 'Levenshtein distance unavailable! Either set threshold to 0 or install the `levenshtein-ffi` gem' unless levenshtein_available
|
313
|
+
distance = Levenshtein.distance(user.username, username)
|
314
|
+
next if distance > threshold
|
315
|
+
else
|
316
|
+
distance = 0
|
317
|
+
next if user.username != username
|
318
|
+
end
|
300
319
|
|
301
320
|
# Make a singleton accessor "distance"
|
302
321
|
user.instance_variable_set(:@distance, distance)
|
data/lib/discordrb/data.rb
CHANGED
@@ -19,10 +19,6 @@ module Discordrb
|
|
19
19
|
attr_reader :username, :id, :discriminator, :avatar, :voice_channel, :roles
|
20
20
|
attr_accessor :status, :game, :server_mute, :server_deaf, :self_mute, :self_deaf
|
21
21
|
|
22
|
-
# @roles is a hash of user roles:
|
23
|
-
# Key: Server ID
|
24
|
-
# Value: Array of roles.
|
25
|
-
|
26
22
|
alias_method :name, :username
|
27
23
|
|
28
24
|
def initialize(data, bot)
|
data/lib/discordrb/version.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require 'opus-ruby'
|
3
|
+
OPUS_AVAILABLE = true
|
4
|
+
rescue LoadError
|
5
|
+
OPUS_AVAILABLE = false
|
6
|
+
end
|
2
7
|
|
3
8
|
# Discord voice chat support
|
4
9
|
module Discordrb::Voice
|
@@ -11,7 +16,12 @@ module Discordrb::Voice
|
|
11
16
|
@frame_size = 960
|
12
17
|
@channels = 2
|
13
18
|
@volume = 1.0
|
14
|
-
|
19
|
+
|
20
|
+
if OPUS_AVAILABLE
|
21
|
+
@opus = Opus::Encoder.new(@sample_rate, @frame_size, @channels)
|
22
|
+
else
|
23
|
+
fail LoadError, 'Opus unavailable - voice not supported! Please install opus for voice support to work.'
|
24
|
+
end
|
15
25
|
end
|
16
26
|
|
17
27
|
def encode(buffer)
|
@@ -23,13 +33,13 @@ module Discordrb::Voice
|
|
23
33
|
end
|
24
34
|
|
25
35
|
def encode_file(file)
|
26
|
-
command = "#{ffmpeg_command} -loglevel 0 -i \"#{file}\" -f s16le -ar 48000 -ac 2
|
36
|
+
command = "#{ffmpeg_command} -loglevel 0 -i \"#{file}\" -f s16le -ar 48000 -ac 2 #{ffmpeg_volume} pipe:1"
|
27
37
|
IO.popen(command)
|
28
38
|
end
|
29
39
|
|
30
40
|
def encode_io(io)
|
31
41
|
ret_io, writer = IO.pipe
|
32
|
-
command = "#{ffmpeg_command} -loglevel 0 -i - -f s16le -ar 48000 -ac 2
|
42
|
+
command = "#{ffmpeg_command} -loglevel 0 -i - -f s16le -ar 48000 -ac 2 #{ffmpeg_volume} pipe:1"
|
33
43
|
spawn(command, in: io, out: writer)
|
34
44
|
ret_io
|
35
45
|
end
|
@@ -39,5 +49,9 @@ module Discordrb::Voice
|
|
39
49
|
def ffmpeg_command
|
40
50
|
@use_avconv ? 'avconv' : 'ffmpeg'
|
41
51
|
end
|
52
|
+
|
53
|
+
def ffmpeg_volume
|
54
|
+
@use_avconv ? "-vol #{(@volume * 256).ceil}" : "-af volume=#{@volume}"
|
55
|
+
end
|
42
56
|
end
|
43
57
|
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: 1.5.
|
4
|
+
version: 1.5.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-01-
|
11
|
+
date: 2016-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faye-websocket
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: websocket-client-simple
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: bundler
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|