discordrb 3.2.1 → 3.3.0

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.

Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +3 -3
  4. data/.travis.yml +28 -3
  5. data/.yardopts +1 -1
  6. data/CHANGELOG.md +555 -144
  7. data/CONTRIBUTING.md +1 -1
  8. data/Gemfile +0 -4
  9. data/README.md +86 -15
  10. data/Rakefile +2 -2
  11. data/bin/travis_build_docs.sh +17 -0
  12. data/discordrb-webhooks.gemspec +2 -1
  13. data/discordrb.gemspec +12 -5
  14. data/lib/discordrb.rb +2 -2
  15. data/lib/discordrb/api.rb +94 -25
  16. data/lib/discordrb/api/channel.rb +53 -17
  17. data/lib/discordrb/api/invite.rb +7 -4
  18. data/lib/discordrb/api/server.rb +173 -36
  19. data/lib/discordrb/api/user.rb +18 -4
  20. data/lib/discordrb/api/webhook.rb +83 -0
  21. data/lib/discordrb/await.rb +1 -1
  22. data/lib/discordrb/bot.rb +191 -102
  23. data/lib/discordrb/cache.rb +39 -9
  24. data/lib/discordrb/commands/command_bot.rb +79 -24
  25. data/lib/discordrb/commands/container.rb +16 -2
  26. data/lib/discordrb/commands/parser.rb +46 -7
  27. data/lib/discordrb/commands/rate_limiter.rb +8 -6
  28. data/lib/discordrb/container.rb +51 -7
  29. data/lib/discordrb/data.rb +1729 -286
  30. data/lib/discordrb/errors.rb +34 -1
  31. data/lib/discordrb/events/generic.rb +1 -1
  32. data/lib/discordrb/events/guilds.rb +1 -0
  33. data/lib/discordrb/events/message.rb +18 -12
  34. data/lib/discordrb/events/presence.rb +7 -2
  35. data/lib/discordrb/events/reactions.rb +13 -4
  36. data/lib/discordrb/events/roles.rb +7 -6
  37. data/lib/discordrb/events/typing.rb +1 -1
  38. data/lib/discordrb/events/webhooks.rb +61 -0
  39. data/lib/discordrb/gateway.rb +85 -32
  40. data/lib/discordrb/light.rb +1 -1
  41. data/lib/discordrb/logger.rb +8 -7
  42. data/lib/discordrb/permissions.rb +41 -4
  43. data/lib/discordrb/version.rb +1 -1
  44. data/lib/discordrb/voice/encoder.rb +10 -8
  45. data/lib/discordrb/voice/voice_bot.rb +4 -4
  46. data/lib/discordrb/websocket.rb +2 -2
  47. metadata +59 -14
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'discordrb/light/light_bot'
4
4
 
5
- # This module contains classes to allow connections to bots without a connection to the gateway socket, i. e. bots
5
+ # This module contains classes to allow connections to bots without a connection to the gateway socket, i.e. bots
6
6
  # that only use the REST part of the API.
7
7
  module Discordrb::Light
8
8
  end
@@ -33,7 +33,8 @@ module Discordrb
33
33
  warn: { long: 'WARN', short: '!', format_code: "\u001B[33m" }, # yellow
34
34
  error: { long: 'ERROR', short: '✗', format_code: "\u001B[31m" }, # red
35
35
  out: { long: 'OUT', short: '→', format_code: "\u001B[36m" }, # cyan
36
- in: { long: 'IN', short: '←', format_code: "\u001B[35m" } # purple
36
+ in: { long: 'IN', short: '←', format_code: "\u001B[35m" }, # purple
37
+ ratelimit: { long: 'RATELIMIT', short: 'R', format_code: "\u001B[41m" } # red background
37
38
  }.freeze
38
39
 
39
40
  # The ANSI format code that resets formatting
@@ -65,15 +66,15 @@ module Discordrb
65
66
  def mode=(value)
66
67
  case value
67
68
  when :debug
68
- @enabled_modes = [:debug, :good, :info, :warn, :error, :out, :in]
69
+ @enabled_modes = %i[debug good info warn error out in ratelimit]
69
70
  when :verbose
70
- @enabled_modes = [:good, :info, :warn, :error, :out, :in]
71
+ @enabled_modes = %i[good info warn error out in ratelimit]
71
72
  when :normal
72
- @enabled_modes = [:info, :warn, :error]
73
+ @enabled_modes = %i[info warn error ratelimit]
73
74
  when :quiet
74
- @enabled_modes = [:warn, :error]
75
+ @enabled_modes = %i[warn error]
75
76
  when :silent
76
- @enabled_modes = []
77
+ @enabled_modes = %i[]
77
78
  end
78
79
  end
79
80
 
@@ -91,7 +92,7 @@ module Discordrb
91
92
  timestamp = Time.now.strftime(LOG_TIMESTAMP_FORMAT)
92
93
 
93
94
  # Redact token if set
94
- log = if @token
95
+ log = if @token && @token != ''
95
96
  message.to_s.gsub(@token, 'REDACTED_TOKEN')
96
97
  else
97
98
  message.to_s
@@ -14,8 +14,8 @@ module Discordrb
14
14
  4 => :manage_channels, # 16
15
15
  5 => :manage_server, # 32
16
16
  6 => :add_reactions, # 64
17
- # 7 # 128
18
- # 8 # 256
17
+ 7 => :view_audit_log, # 128
18
+ 8 => :priority_speaker, # 256
19
19
  # 9 # 512
20
20
  10 => :read_messages, # 1024
21
21
  11 => :send_messages, # 2048
@@ -56,6 +56,7 @@ module Discordrb
56
56
  end
57
57
 
58
58
  alias_method :can_administrate=, :can_administrator=
59
+ alias_method :administrate, :administrator
59
60
 
60
61
  attr_reader :bits
61
62
 
@@ -74,14 +75,50 @@ module Discordrb
74
75
  end
75
76
  end
76
77
 
78
+ # Return the corresponding bits for an array of permission flag symbols.
79
+ # This is a class method that can be used to calculate bits instead
80
+ # of instancing a new Permissions object.
81
+ # @example Get the bits for permissions that could allow/deny read messages, connect, and speak
82
+ # Permissions.bits [:read_messages, :connect, :speak] #=> 3146752
83
+ # @param list [Array<Symbol>]
84
+ # @return [Integer] the computed permissions integer
85
+ def self.bits(list)
86
+ value = 0
87
+
88
+ Flags.each do |position, flag|
89
+ value += 2**position if list.include? flag
90
+ end
91
+
92
+ value
93
+ end
94
+
77
95
  # Create a new Permissions object either as a blank slate to add permissions to (for example for
78
96
  # {Channel#define_overwrite}) or from existing bit data to read out.
79
- # @param bits [Integer] The permission bits that should be set from the beginning.
97
+ # @example Create a permissions object that could allow/deny read messages, connect, and speak by setting flags
98
+ # permission = Permissions.new
99
+ # permission.can_read_messages = true
100
+ # permission.can_connect = true
101
+ # permission.can_speak = true
102
+ # @example Create a permissions object that could allow/deny read messages, connect, and speak by an array of symbols
103
+ # Permissions.new [:read_messages, :connect, :speak]
104
+ # @param bits [Integer, Array<Symbol>] The permission bits that should be set from the beginning, or an array of permission flag symbols
80
105
  # @param writer [RoleWriter] The writer that should be used to update data when a permission is set.
81
106
  def initialize(bits = 0, writer = nil)
82
107
  @writer = writer
83
- @bits = bits
108
+
109
+ @bits = if bits.is_a? Array
110
+ self.class.bits(bits)
111
+ else
112
+ bits
113
+ end
114
+
84
115
  init_vars
85
116
  end
117
+
118
+ # Comparison based on permission bits
119
+ def ==(other)
120
+ false unless other.is_a? Discordrb::Permissions
121
+ bits == other.bits
122
+ end
86
123
  end
87
124
  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 = '3.2.1'.freeze
6
+ VERSION = '3.3.0'.freeze
7
7
  end
@@ -24,13 +24,13 @@ module Discordrb::Voice
24
24
 
25
25
  # Create a new encoder
26
26
  def initialize
27
- @sample_rate = 48_000
28
- @frame_size = 960
29
- @channels = 2
27
+ sample_rate = 48_000
28
+ frame_size = 960
29
+ channels = 2
30
30
  @filter_volume = 1
31
31
 
32
32
  raise LoadError, 'Opus unavailable - voice not supported! Please install opus for voice support to work.' unless OPUS_AVAILABLE
33
- @opus = Opus::Encoder.new(@sample_rate, @frame_size, @channels)
33
+ @opus = Opus::Encoder.new(sample_rate, frame_size, channels)
34
34
  end
35
35
 
36
36
  # Set the opus encoding bitrate
@@ -73,19 +73,21 @@ module Discordrb::Voice
73
73
  # an audio track. For a list of supported formats, see https://ffmpeg.org/general.html#Audio-Codecs. It even accepts
74
74
  # URLs, though encoding them is pretty slow - I recommend to make a stream of it and then use {#encode_io} instead.
75
75
  # @param file [String] The path or URL to encode.
76
+ # @param options [String] ffmpeg options to pass after the -i flag
76
77
  # @return [IO] the audio, encoded as s16le PCM
77
- def encode_file(file)
78
- command = "#{ffmpeg_command} -loglevel 0 -i \"#{file}\" -f s16le -ar 48000 -ac 2 #{filter_volume_argument} pipe:1"
78
+ def encode_file(file, options = '')
79
+ command = "#{ffmpeg_command} -loglevel 0 -i \"#{file}\" #{options} -f s16le -ar 48000 -ac 2 #{filter_volume_argument} pipe:1"
79
80
  IO.popen(command)
80
81
  end
81
82
 
82
83
  # Encodes an arbitrary IO audio stream using ffmpeg. Accepts pretty much any media format, even videos with audio
83
84
  # tracks. For a list of supported audio formats, see https://ffmpeg.org/general.html#Audio-Codecs.
84
85
  # @param io [IO] The stream to encode.
86
+ # @param options [String] ffmpeg options to pass after the -i flag
85
87
  # @return [IO] the audio, encoded as s16le PCM
86
- def encode_io(io)
88
+ def encode_io(io, options = '')
87
89
  ret_io, writer = IO.pipe
88
- command = "#{ffmpeg_command} -loglevel 0 -i - -f s16le -ar 48000 -ac 2 #{filter_volume_argument} pipe:1"
90
+ command = "#{ffmpeg_command} -loglevel 0 -i - #{options} -f s16le -ar 48000 -ac 2 #{filter_volume_argument} pipe:1"
89
91
  spawn(command, in: io, out: writer)
90
92
  ret_io
91
93
  end
@@ -233,15 +233,15 @@ module Discordrb::Voice
233
233
  # Plays an encoded audio file of arbitrary format to the channel.
234
234
  # @see Encoder#encode_file
235
235
  # @see #play
236
- def play_file(file)
237
- play @encoder.encode_file(file)
236
+ def play_file(file, options = '')
237
+ play @encoder.encode_file(file, options)
238
238
  end
239
239
 
240
240
  # Plays a stream of encoded audio data of arbitrary format to the channel.
241
241
  # @see Encoder#encode_io
242
242
  # @see #play
243
- def play_io(io)
244
- play @encoder.encode_io(io)
243
+ def play_io(io, options = '')
244
+ play @encoder.encode_io(io, options)
245
245
  end
246
246
 
247
247
  # Plays a stream of audio data in the DCA format. This format has the advantage that no recoding has to be
@@ -2,8 +2,6 @@
2
2
 
3
3
  require 'websocket-client-simple'
4
4
 
5
- puts "Using WSCS version: #{WebSocket::Client::Simple::VERSION}"
6
-
7
5
  # The WSCS module which we're hooking
8
6
  # @see Websocket::Client::Simple::Client
9
7
  module WebSocket::Client::Simple
@@ -31,6 +29,8 @@ module Discordrb
31
29
  # @param error_handler [#call] The handler that should be called when an error occurs in another handler. The error
32
30
  # will be passed as the first parameter to the handler.
33
31
  def initialize(endpoint, open_handler, message_handler, close_handler, error_handler)
32
+ Discordrb::LOGGER.debug "Using WSCS version: #{::WebSocket::Client::Simple::VERSION}"
33
+
34
34
  @open_handler = open_handler
35
35
  @message_handler = message_handler
36
36
  @close_handler = close_handler
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: 3.2.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - meew0
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-18 00:00:00.000000000 Z
11
+ date: 2018-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 2.1.0.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 2.1.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: opus-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.4.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: ffi
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.9.24
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.9.24
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: discordrb-webhooks
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 3.2.0.1
89
+ version: 3.3.0
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 3.2.0.1
96
+ version: 3.3.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +128,28 @@ dependencies:
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: 0.8.7.6
131
+ version: 0.9.9
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: 0.8.7.6
138
+ version: 0.9.9
139
+ - !ruby/object:Gem::Dependency
140
+ name: redcarpet
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 3.4.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 3.4.0
125
153
  - !ruby/object:Gem::Dependency
126
154
  name: rspec
127
155
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +184,28 @@ dependencies:
156
184
  requirements:
157
185
  - - '='
158
186
  - !ruby/object:Gem::Version
159
- version: 0.45.0
187
+ version: 0.49.1
160
188
  type: :development
161
189
  prerelease: false
162
190
  version_requirements: !ruby/object:Gem::Requirement
163
191
  requirements:
164
192
  - - '='
165
193
  - !ruby/object:Gem::Version
166
- version: 0.45.0
194
+ version: 0.49.1
195
+ - !ruby/object:Gem::Dependency
196
+ name: simplecov
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 0.16.0
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 0.16.0
167
209
  description: A Ruby implementation of the Discord (https://discordapp.com) API.
168
210
  email:
169
211
  - ''
@@ -186,6 +228,7 @@ files:
186
228
  - Rakefile
187
229
  - bin/console
188
230
  - bin/setup
231
+ - bin/travis_build_docs.sh
189
232
  - discordrb-webhooks.gemspec
190
233
  - discordrb.gemspec
191
234
  - lib/discordrb.rb
@@ -194,6 +237,7 @@ files:
194
237
  - lib/discordrb/api/invite.rb
195
238
  - lib/discordrb/api/server.rb
196
239
  - lib/discordrb/api/user.rb
240
+ - lib/discordrb/api/webhook.rb
197
241
  - lib/discordrb/await.rb
198
242
  - lib/discordrb/bot.rb
199
243
  - lib/discordrb/cache.rb
@@ -219,6 +263,7 @@ files:
219
263
  - lib/discordrb/events/roles.rb
220
264
  - lib/discordrb/events/typing.rb
221
265
  - lib/discordrb/events/voice_state_update.rb
266
+ - lib/discordrb/events/webhooks.rb
222
267
  - lib/discordrb/gateway.rb
223
268
  - lib/discordrb/light.rb
224
269
  - lib/discordrb/light/data.rb
@@ -235,7 +280,8 @@ files:
235
280
  homepage: https://github.com/meew0/discordrb
236
281
  licenses:
237
282
  - MIT
238
- metadata: {}
283
+ metadata:
284
+ changelog_uri: https://github.com/meew0/discordrb/blob/master/CHANGELOG.md
239
285
  post_install_message:
240
286
  rdoc_options: []
241
287
  require_paths:
@@ -244,7 +290,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
244
290
  requirements:
245
291
  - - ">="
246
292
  - !ruby/object:Gem::Version
247
- version: 2.1.0
293
+ version: 2.2.4
248
294
  required_rubygems_version: !ruby/object:Gem::Requirement
249
295
  requirements:
250
296
  - - ">="
@@ -252,9 +298,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
298
  version: '0'
253
299
  requirements: []
254
300
  rubyforge_project:
255
- rubygems_version: 2.6.10
301
+ rubygems_version: 2.7.7
256
302
  signing_key:
257
303
  specification_version: 4
258
304
  summary: Discord API for Ruby
259
305
  test_files: []
260
- has_rdoc: