onyxcord 3.2.8 → 4.0.0.beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/onyxcord/application_commands.rb +2 -0
  3. data/lib/onyxcord/bot.rb +12 -6
  4. data/lib/onyxcord/cache/manager.rb +9 -9
  5. data/lib/onyxcord/cogs/bot.rb +28 -0
  6. data/lib/onyxcord/cogs/cog.rb +264 -0
  7. data/lib/onyxcord/cogs/cog_meta.rb +61 -0
  8. data/lib/onyxcord/cogs/extensions.rb +109 -0
  9. data/lib/onyxcord/commands/bot/channels.rb +1 -0
  10. data/lib/onyxcord/commands/bot/execution.rb +1 -0
  11. data/lib/onyxcord/commands/container.rb +51 -0
  12. data/lib/onyxcord/commands/parser.rb +61 -7
  13. data/lib/onyxcord/commands/rate_limiter.rb +2 -2
  14. data/lib/onyxcord/core/bot/application_commands.rb +20 -16
  15. data/lib/onyxcord/core/bot/messaging.rb +2 -2
  16. data/lib/onyxcord/core/bot/oauth.rb +1 -1
  17. data/lib/onyxcord/core/version.rb +1 -1
  18. data/lib/onyxcord/events/interactions/autocomplete.rb +21 -6
  19. data/lib/onyxcord/gateway/client.rb +29 -14
  20. data/lib/onyxcord/interactions/command.rb +27 -2
  21. data/lib/onyxcord/interactions/internal/application_command.rb +1 -1
  22. data/lib/onyxcord/interactions/registry.rb +36 -0
  23. data/lib/onyxcord/internal/event_bus.rb +5 -3
  24. data/lib/onyxcord/internal/event_executor.rb +7 -0
  25. data/lib/onyxcord/internal/http.rb +18 -2
  26. data/lib/onyxcord/internal/json.rb +26 -22
  27. data/lib/onyxcord/internal/rate_limiter/async_rest.rb +4 -3
  28. data/lib/onyxcord/internal/rate_limiter/rest.rb +5 -3
  29. data/lib/onyxcord/light/light_bot.rb +3 -3
  30. data/lib/onyxcord/models/application.rb +1 -1
  31. data/lib/onyxcord/models/channel.rb +19 -17
  32. data/lib/onyxcord/models/component.rb +3 -3
  33. data/lib/onyxcord/models/interaction.rb +5 -5
  34. data/lib/onyxcord/models/member.rb +8 -8
  35. data/lib/onyxcord/models/message.rb +5 -5
  36. data/lib/onyxcord/models/poll.rb +2 -2
  37. data/lib/onyxcord/models/profile.rb +4 -4
  38. data/lib/onyxcord/models/role.rb +1 -1
  39. data/lib/onyxcord/models/scheduled_event.rb +3 -3
  40. data/lib/onyxcord/models/server.rb +46 -34
  41. data/lib/onyxcord/models/user.rb +1 -1
  42. data/lib/onyxcord/models/webhook.rb +7 -7
  43. data/lib/onyxcord/rest/client.rb +38 -6
  44. data/lib/onyxcord/voice/client.rb +2 -0
  45. data/lib/onyxcord/voice/network/udp.rb +4 -1
  46. data/lib/onyxcord/voice/network/websocket.rb +8 -3
  47. data/lib/onyxcord/webhooks/view/container_builder.rb +6 -1
  48. data/lib/onyxcord.rb +5 -1
  49. metadata +5 -1
@@ -37,6 +37,11 @@ module OnyxCord
37
37
  raise ArgumentError, 'EventExecutor::Pool#post requires a block' unless block
38
38
  raise 'Event executor has been shut down' if @closed
39
39
 
40
+ if @queue.respond_to?(:max) && @queue.size >= @queue.max
41
+ OnyxCord::LOGGER.warn('Event executor queue is full — dropping event') if defined?(OnyxCord::LOGGER)
42
+ return
43
+ end
44
+
40
45
  @queue << block
41
46
  end
42
47
 
@@ -55,6 +60,8 @@ module OnyxCord
55
60
  @size.times { @queue << STOP }
56
61
  @workers.each do |w|
57
62
  w.join unless w == Thread.current
63
+ rescue Interrupt, SystemExit
64
+ raise
58
65
  rescue StandardError
59
66
  nil
60
67
  end
@@ -135,7 +135,7 @@ module OnyxCord
135
135
  end
136
136
 
137
137
  def multipart_body(body, boundary)
138
- output = (+'').b
138
+ output = String.new(encoding: Encoding::BINARY)
139
139
 
140
140
  multipart_parts(body).each do |part|
141
141
  key = part[:name]
@@ -159,7 +159,23 @@ module OnyxCord
159
159
  end
160
160
 
161
161
  def multipart_content_type(filename)
162
- File.extname(filename).casecmp('.txt').zero? ? 'text/plain' : 'application/octet-stream'
162
+ ext = File.extname(filename).downcase
163
+ case ext
164
+ when '.txt' then 'text/plain'
165
+ when '.json' then 'application/json'
166
+ when '.xml' then 'application/xml'
167
+ when '.png' then 'image/png'
168
+ when '.jpg', '.jpeg' then 'image/jpeg'
169
+ when '.gif' then 'image/gif'
170
+ when '.webp' then 'image/webp'
171
+ when '.mp3' then 'audio/mpeg'
172
+ when '.mp4' then 'video/mp4'
173
+ when '.ogg' then 'audio/ogg'
174
+ when '.wav' then 'audio/wav'
175
+ when '.pdf' then 'application/pdf'
176
+ when '.zip' then 'application/zip'
177
+ else 'application/octet-stream'
178
+ end
163
179
  end
164
180
 
165
181
  def multipart?(body)
@@ -2,49 +2,53 @@
2
2
 
3
3
  require 'oj'
4
4
 
5
- # Configure Oj in compat mode so that all stdlib JSON.parse / .to_json calls
6
- # are transparently accelerated. This is loaded early by the main onyxcord.rb
7
- # entry point so every module benefits automatically.
5
+ # JSON utilities backed by Oj with *local* options.
6
+ # We deliberately avoid `Oj.default_options` to keep the global process clean.
7
+
8
8
  module OnyxCord
9
9
  module Internal
10
10
  # Fast Oj-backed JSON wrapper providing compatibility with stdlib JSON methods.
11
11
  module JSON
12
- Oj.default_options = { mode: :compat, symbol_keys: false }
12
+ # Default options for Oj. Kept local so that other libraries in the process
13
+ # are not affected by a global override.
14
+ OJ_OPTIONS = { mode: :compat, symbol_keys: false }.freeze
13
15
 
14
16
  module_function
15
17
 
16
- # Fast JSON decode using Oj via stdlib JSON compatibility.
18
+ # Decode a JSON string into a Ruby object.
17
19
  # @param data [String] The JSON string to decode.
20
+ # @param args [Hash] Additional Oj.load options (merged with defaults).
18
21
  # @return [Hash, Array, String, Numeric, nil]
19
- def decode(data, *args)
20
- ::JSON.parse(data, *args)
22
+ def decode(data, **args)
23
+ Oj.load(data, **OJ_OPTIONS, **args)
21
24
  end
22
25
 
23
- # Fast JSON encode using Oj via stdlib JSON compatibility.
26
+ # Encode a Ruby object as JSON.
24
27
  # @param data [Object] The object to encode as JSON.
28
+ # @param args [Hash] Additional Oj.dump options (merged with defaults).
25
29
  # @return [String]
26
- def encode(data, *args)
27
- ::JSON.generate(data, *args)
30
+ def encode(data, **args)
31
+ Oj.dump(data, **OJ_OPTIONS, **args)
28
32
  end
29
33
 
30
- # Alias parse to decode for standard library compatibility
31
- def parse(data, *args)
32
- ::JSON.parse(data, *args)
34
+ # Alias parse to decode
35
+ def parse(data, **args)
36
+ decode(data, **args)
33
37
  end
34
38
 
35
- # Alias generate to encode for standard library compatibility
36
- def generate(data, *args)
37
- ::JSON.generate(data, *args)
39
+ # Alias generate to encode
40
+ def generate(data, **args)
41
+ encode(data, **args)
38
42
  end
39
43
 
40
- # Alias load to decode for Oj/JSON compatibility
41
- def load(data, *args)
42
- ::JSON.parse(data, *args)
44
+ # Alias load to decode (Oj/JSON compatibility)
45
+ def load(data, **args)
46
+ decode(data, **args)
43
47
  end
44
48
 
45
- # Alias dump to encode for Oj/JSON compatibility
46
- def dump(data, *args)
47
- ::JSON.generate(data, *args)
49
+ # Alias dump to encode (Oj/JSON compatibility)
50
+ def dump(data, **args)
51
+ encode(data, **args)
48
52
  end
49
53
  end
50
54
  end
@@ -21,8 +21,9 @@ module OnyxCord
21
21
  end
22
22
 
23
23
  def before_request(route, major_parameter)
24
- wait_for(@global_lock)
24
+ # Acquire locks in consistent order (route → global) to prevent deadlock.
25
25
  wait_for(mutex_for(route, major_parameter))
26
+ wait_for(@global_lock) if @global_lock.locked?
26
27
  end
27
28
 
28
29
  def record_response(route, major_parameter, headers)
@@ -106,12 +107,12 @@ module OnyxCord
106
107
  def retry_after(response, headers)
107
108
  body = response.respond_to?(:body) ? response.body : response.to_s
108
109
  if body && !body.empty?
109
- data = JSON.parse(body)
110
+ data = OnyxCord::Internal::JSON.parse(body)
110
111
  return data['retry_after'].to_f if data['retry_after']
111
112
  end
112
113
 
113
114
  (headers[:retry_after] || 0).to_f
114
- rescue JSON::ParserError
115
+ rescue OnyxCord::Internal::JSON::ParseError
115
116
  (headers[:retry_after] || 0).to_f
116
117
  end
117
118
 
@@ -49,7 +49,9 @@ module OnyxCord
49
49
 
50
50
  def handle_rate_limit(route, major_parameter, response)
51
51
  headers = normalize_headers(response.headers)
52
- mutex = headers[:x_ratelimit_global] == 'true' || headers[:x_ratelimit_scope] == 'global' ? @global_mutex : mutex_for(route, major_parameter)
52
+ global = [true, 'true', 1, '1'].include?(headers[:x_ratelimit_global]) ||
53
+ headers[:x_ratelimit_scope] == 'global'
54
+ mutex = global ? @global_mutex : mutex_for(route, major_parameter)
53
55
  wait_seconds = retry_after(response, headers)
54
56
 
55
57
  sync_wait(wait_seconds, mutex) if wait_seconds.positive?
@@ -103,12 +105,12 @@ module OnyxCord
103
105
  def retry_after(response, headers)
104
106
  body = response.respond_to?(:body) ? response.body : response.to_s
105
107
  if body && !body.empty?
106
- data = JSON.parse(body)
108
+ data = OnyxCord::Internal::JSON.parse(body)
107
109
  return data['retry_after'].to_f if data['retry_after']
108
110
  end
109
111
 
110
112
  (headers[:retry_after] || 0).to_f
111
- rescue JSON::ParserError
113
+ rescue OnyxCord::Internal::JSON::ParseError
112
114
  (headers[:retry_after] || 0).to_f
113
115
  end
114
116
 
@@ -32,13 +32,13 @@ module OnyxCord::Light
32
32
  # @return [LightProfile] the details of the user this bot is connected to.
33
33
  def profile
34
34
  response = OnyxCord::REST::User.profile(@token)
35
- LightProfile.new(JSON.parse(response), self)
35
+ LightProfile.new(OnyxCord::Internal::JSON.parse(response), self)
36
36
  end
37
37
 
38
38
  # @return [Array<LightServer>] the servers this bot is connected to.
39
39
  def servers
40
40
  response = OnyxCord::REST::User.servers(@token)
41
- JSON.parse(response).map { |e| LightServer.new(e, self) }
41
+ OnyxCord::Internal::JSON.parse(response).map { |e| LightServer.new(e, self) }
42
42
  end
43
43
 
44
44
  # Joins a server using an instant invite.
@@ -52,7 +52,7 @@ module OnyxCord::Light
52
52
  # @return [Array<Connection>] this account's connections.
53
53
  def connections
54
54
  response = OnyxCord::REST::User.connections(@token)
55
- JSON.parse(response).map { |e| Connection.new(e, self) }
55
+ OnyxCord::Internal::JSON.parse(response).map { |e| Connection.new(e, self) }
56
56
  end
57
57
  end
58
58
  end
@@ -236,7 +236,7 @@ module OnyxCord
236
236
  data[:flags] = ((@flags & ~to_flags.call(remove_flags)) | to_flags.call(add_flags))
237
237
  end
238
238
 
239
- update_data(JSON.parse(REST::Application.update_current_application(@bot.token, **data)))
239
+ update_data(OnyxCord::Internal::JSON.parse(REST::Application.update_current_application(@bot.token, **data)))
240
240
  nil
241
241
  end
242
242
 
@@ -418,7 +418,7 @@ module OnyxCord
418
418
  # Check if this channel is marked as NSFW.
419
419
  # @return [true, false] Whether or not this channel is marked as NSFW.
420
420
  def nsfw?
421
- thread? ? parent.nsfw? : @nsfw
421
+ thread? ? (parent&.nsfw? || false) : @nsfw
422
422
  end
423
423
 
424
424
  # Get the time at when this channel was created at.
@@ -781,7 +781,7 @@ module OnyxCord
781
781
  # @return [Array<Message>] the retrieved messages.
782
782
  def history(amount, before_id = nil, after_id = nil, around_id = nil)
783
783
  logs = REST::Channel.messages(@bot.token, @id, amount, before_id, after_id, around_id)
784
- JSON.parse(logs).map { |message| Message.new(message, @bot) }
784
+ OnyxCord::Internal::JSON.parse(logs).map { |message| Message.new(message, @bot) }
785
785
  end
786
786
 
787
787
  # Retrieves message history, but only message IDs for use with prune.
@@ -789,7 +789,7 @@ module OnyxCord
789
789
  # @!visibility private
790
790
  def history_ids(amount, before_id = nil, after_id = nil, around_id = nil)
791
791
  logs = REST::Channel.messages(@bot.token, @id, amount, before_id, after_id, around_id)
792
- JSON.parse(logs).map { |message| message['id'].to_i }
792
+ OnyxCord::Internal::JSON.parse(logs).map { |message| message['id'].to_i }
793
793
  end
794
794
 
795
795
  # Returns a single message from this channel's history by ID.
@@ -799,7 +799,7 @@ module OnyxCord
799
799
  raise ArgumentError, 'message_id cannot be nil' if message_id.nil?
800
800
 
801
801
  response = REST::Channel.message(@bot.token, @id, message_id)
802
- Message.new(JSON.parse(response), @bot)
802
+ Message.new(OnyxCord::Internal::JSON.parse(response), @bot)
803
803
  rescue OnyxCord::Errors::UnknownMessage
804
804
  nil
805
805
  end
@@ -812,7 +812,7 @@ module OnyxCord
812
812
  def pins(limit: 50)
813
813
  get_pins = proc do |fetch_limit, before = nil|
814
814
  resp = REST::Channel.pinned_messages(@bot.token, @id, fetch_limit, before&.iso8601)
815
- JSON.parse(resp)['items'].map { |pin| Message.new(pin['message'].merge({ 'pinned_at' => pin['pinned_at'] }), @bot) }
815
+ OnyxCord::Internal::JSON.parse(resp)['items'].map { |pin| Message.new(pin['message'].merge({ 'pinned_at' => pin['pinned_at'] }), @bot) }
816
816
  end
817
817
 
818
818
  # Can be done without pagination.
@@ -905,7 +905,7 @@ module OnyxCord
905
905
  # @return [Invite] the created invite.
906
906
  def make_invite(max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil)
907
907
  response = REST::Channel.create_invite(@bot.token, @id, max_age, max_uses, temporary, unique, reason)
908
- Invite.new(JSON.parse(response), @bot)
908
+ Invite.new(OnyxCord::Internal::JSON.parse(response), @bot)
909
909
  end
910
910
 
911
911
  alias_method :invite, :make_invite
@@ -929,7 +929,7 @@ module OnyxCord
929
929
  raise ArgumentError, 'Tried to create a webhook in a non-server channel' unless server
930
930
 
931
931
  response = REST::Channel.create_webhook(@bot.token, @id, name, avatar, reason)
932
- Webhook.new(JSON.parse(response), @bot)
932
+ Webhook.new(OnyxCord::Internal::JSON.parse(response), @bot)
933
933
  end
934
934
 
935
935
  # Requests a list of Webhooks on the channel.
@@ -937,7 +937,7 @@ module OnyxCord
937
937
  def webhooks
938
938
  raise 'Tried to request webhooks from a non-server channel' unless server
939
939
 
940
- webhooks = JSON.parse(REST::Channel.webhooks(@bot.token, @id))
940
+ webhooks = OnyxCord::Internal::JSON.parse(REST::Channel.webhooks(@bot.token, @id))
941
941
  webhooks.map { |webhook_data| Webhook.new(webhook_data, @bot) }
942
942
  end
943
943
 
@@ -946,7 +946,7 @@ module OnyxCord
946
946
  def invites
947
947
  raise 'Tried to request invites from a non-server channel' unless server
948
948
 
949
- invites = JSON.parse(REST::Channel.invites(@bot.token, @id))
949
+ invites = OnyxCord::Internal::JSON.parse(REST::Channel.invites(@bot.token, @id))
950
950
  invites.map { |invite_data| Invite.new(invite_data, @bot) }
951
951
  end
952
952
 
@@ -957,7 +957,7 @@ module OnyxCord
957
957
  def follow(target, reason: nil)
958
958
  raise 'Cannot follow a non-announcement channel' unless news?
959
959
 
960
- JSON.parse(REST::Channel.follow_channel(@bot.token, @id, target.resolve_id, reason))['webhook_id'].to_i
960
+ OnyxCord::Internal::JSON.parse(REST::Channel.follow_channel(@bot.token, @id, target.resolve_id, reason))['webhook_id'].to_i
961
961
  end
962
962
 
963
963
  # Returns the last message or forum post created in this channel.
@@ -990,7 +990,7 @@ module OnyxCord
990
990
  REST::Channel.start_thread_without_message(@bot.token, @id, name, auto_archive_duration, type)
991
991
  end
992
992
 
993
- @bot.ensure_channel(JSON.parse(data))
993
+ @bot.ensure_channel(OnyxCord::Internal::JSON.parse(data))
994
994
  end
995
995
 
996
996
  # Start a thread in a forum or media channel.
@@ -1026,7 +1026,7 @@ module OnyxCord
1026
1026
  builder = builder.to_json_hash
1027
1027
 
1028
1028
  message = { content: builder[:content], embeds: builder[:embeds], allowed_mentions: builder[:allowed_mentions], components: components, sticker_ids: stickers&.map(&:resolve_id), flags: flags }
1029
- response = JSON.parse(REST::Channel.start_thread_in_forum_or_media_channel(@bot.token, @id, name, message.compact, attachments, rate_limit_per_user, auto_archive_duration, tags&.map(&:resolve_id), reason))
1029
+ response = OnyxCord::Internal::JSON.parse(REST::Channel.start_thread_in_forum_or_media_channel(@bot.token, @id, name, message.compact, attachments, rate_limit_per_user, auto_archive_duration, tags&.map(&:resolve_id), reason))
1030
1030
 
1031
1031
  Message.new(response['message'].merge!('channel_id' => response['id'], 'thread' => response), @bot)
1032
1032
  end
@@ -1040,7 +1040,7 @@ module OnyxCord
1040
1040
  # @return [ChannelTag, nil] The tag that was found or `nil` if it couldn't be found.
1041
1041
  def tag(id)
1042
1042
  id = id.resolve_id
1043
- @available_tags.find { |tag| tag == id }
1043
+ @available_tags.find { |t| t.id == id }
1044
1044
  end
1045
1045
 
1046
1046
  # Check if a specific tag has been applied to this thread.
@@ -1056,9 +1056,11 @@ module OnyxCord
1056
1056
  # be applied onto threads created in this channel will be returned instead.
1057
1057
  # @return [Array<ChannelTag>] The available or set channel tags for this channel.
1058
1058
  def tags
1059
- return @available_tags if forum? || !thread_only?
1059
+ return @available_tags if thread_only?
1060
1060
 
1061
- @applied_tags.filter_map { |tag_id| parent&.tag(tag_id) }
1061
+ return @applied_tags.filter_map { |tag_id| parent&.tag(tag_id) } if thread?
1062
+
1063
+ []
1062
1064
  end
1063
1065
 
1064
1066
  # Add one or more tags to this thread channel.
@@ -1207,7 +1209,7 @@ module OnyxCord
1207
1209
  data[:flags] = ((@flags & ~to_flags.call(remove_flags)) | to_flags.call(add_flags))
1208
1210
  end
1209
1211
 
1210
- update_data(JSON.parse(REST::Channel.update!(@bot.token, @id, **data, reason: reason)))
1212
+ update_data(OnyxCord::Internal::JSON.parse(REST::Channel.update!(@bot.token, @id, **data, reason: reason)))
1211
1213
  nil
1212
1214
  end
1213
1215
 
@@ -1249,7 +1251,7 @@ module OnyxCord
1249
1251
  # @note For internal use only
1250
1252
  # @!visibility private
1251
1253
  def update_data(new_data = nil)
1252
- new_data ||= JSON.parse(REST::Channel.resolve(@bot.token, @id))
1254
+ new_data ||= OnyxCord::Internal::JSON.parse(REST::Channel.resolve(@bot.token, @id))
1253
1255
  @type = new_data['type'] || 0
1254
1256
  @topic = new_data['topic']
1255
1257
  @bitrate = new_data['bitrate']
@@ -171,11 +171,11 @@ module OnyxCord
171
171
  attr_reader :emoji
172
172
 
173
173
  # @!visibility private
174
- def initialize(data)
174
+ def initialize(data, bot = nil)
175
175
  @label = data['label']
176
176
  @value = data['value']
177
177
  @description = data['description']
178
- @emoji = Emoji.new(data['emoji'], @bot) if data['emoji']
178
+ @emoji = Emoji.new(data['emoji'], bot) if data['emoji']
179
179
  end
180
180
  end
181
181
 
@@ -209,7 +209,7 @@ module OnyxCord
209
209
  @max_values = data['max_values']
210
210
  @min_values = data['min_values']
211
211
  @placeholder = data['placeholder']
212
- @options = data['options']&.map { |option| Option.new(option) } || []
212
+ @options = data['options']&.map { |option| Option.new(option, bot) } || []
213
213
  end
214
214
  end
215
215
 
@@ -182,7 +182,7 @@ module OnyxCord
182
182
  response = OnyxCord::REST::Interaction.create_interaction_response(@token, @id, CALLBACK_TYPES[:channel_message], data[:content], tts, data[:embeds], data[:allowed_mentions], flags, components.to_a, attachments, nil, wait, data[:poll])
183
183
  return unless wait
184
184
 
185
- Interactions::Message.new(JSON.parse(response)['resource']['message'], @bot, self)
185
+ Interactions::Message.new(OnyxCord::Internal::JSON.parse(response)['resource']['message'], @bot, self)
186
186
  end
187
187
 
188
188
  # Defer an interaction, setting a temporary response that can be later overriden by {Interaction#send_message}.
@@ -255,7 +255,7 @@ module OnyxCord
255
255
  response = OnyxCord::REST::Interaction.create_interaction_response(@token, @id, CALLBACK_TYPES[:update_message], data[:content], tts, data[:embeds], data[:allowed_mentions], flags, components.to_a, attachments, nil, wait, data[:poll])
256
256
  return unless wait
257
257
 
258
- Interactions::Message.new(JSON.parse(response)['resource']['message'], @bot, self)
258
+ Interactions::Message.new(OnyxCord::Internal::JSON.parse(response)['resource']['message'], @bot, self)
259
259
  end
260
260
 
261
261
  # Edit the original response to this interaction.
@@ -281,7 +281,7 @@ module OnyxCord
281
281
  data = builder.to_json_hash
282
282
  resp = OnyxCord::REST::Interaction.edit_original_interaction_response(@token, @application_id, edit_content(content, data), edit_embeds(embeds, data), data[:allowed_mentions], components.to_a, attachments, flags, data[:poll])
283
283
 
284
- Interactions::Message.new(JSON.parse(resp), @bot, self)
284
+ Interactions::Message.new(OnyxCord::Internal::JSON.parse(resp), @bot, self)
285
285
  end
286
286
 
287
287
  # Delete the original interaction response.
@@ -318,7 +318,7 @@ module OnyxCord
318
318
  resp = OnyxCord::REST::Webhook.token_execute_webhook(
319
319
  @token, @application_id, true, data[:content], nil, nil, tts, nil, data[:embeds], data[:allowed_mentions], flags, components.to_a, attachments, data[:poll]
320
320
  )
321
- Interactions::Message.new(JSON.parse(resp), @bot, self)
321
+ Interactions::Message.new(OnyxCord::Internal::JSON.parse(resp), @bot, self)
322
322
  end
323
323
 
324
324
  alias edit_original edit_response
@@ -348,7 +348,7 @@ module OnyxCord
348
348
  resp = OnyxCord::REST::Webhook.token_edit_message(
349
349
  @token, @application_id, message.resolve_id, edit_content(content, data), edit_embeds(embeds, data), data[:allowed_mentions], components.to_a, attachments, flags, data[:poll]
350
350
  )
351
- Interactions::Message.new(JSON.parse(resp), @bot, self)
351
+ Interactions::Message.new(OnyxCord::Internal::JSON.parse(resp), @bot, self)
352
352
  end
353
353
 
354
354
  # @param message [Integer, String, InteractionMessage, Message] The message created by this interaction to be deleted.
@@ -471,7 +471,7 @@ module OnyxCord
471
471
 
472
472
  if (user = data['user'])
473
473
  @user.update_global_name(user['global_name']) if user['global_name']
474
- @user.avatar_id = user['avatar'] if user.key('avatar')
474
+ @user.avatar_id = user['avatar'] if user.key?('avatar')
475
475
  @user.update_avatar_decoration(user['avatar_decoration_data']) if user.key?('avatar_decoration_data')
476
476
  @user.update_collectibles(user['collectibles']) if user.key?('collectibles')
477
477
  @user.update_primary_server(user['primary_guild']) if user.key?('primary_guild')
@@ -512,17 +512,17 @@ module OnyxCord
512
512
 
513
513
  # @!visibility private
514
514
  def update_member_data(new_data)
515
- update_data(JSON.parse(REST::Server.update_member(@bot.token, @server_id, @user.id, **new_data)))
515
+ update_data(OnyxCord::Internal::JSON.parse(REST::Server.update_member(@bot.token, @server_id, @user.id, **new_data)))
516
516
  end
517
517
 
518
518
  # @!visibility private
519
519
  def update_current_member_data(new_data)
520
- update_data(JSON.parse(REST::Server.update_current_member(@bot.token, @server_id,
521
- new_data.key?(:nick) ? new_data[:nick] : :undef,
522
- new_data[:reason],
523
- new_data.key?(:bio) ? new_data[:bio] : :undef,
524
- new_data.key?(:banner) ? new_data[:banner] : :undef,
525
- new_data.key?(:avatar) ? new_data[:avatar] : :undef)))
520
+ update_data(OnyxCord::Internal::JSON.parse(REST::Server.update_current_member(@bot.token, @server_id,
521
+ new_data.key?(:nick) ? new_data[:nick] : :undef,
522
+ new_data[:reason],
523
+ new_data.key?(:bio) ? new_data[:bio] : :undef,
524
+ new_data.key?(:banner) ? new_data[:banner] : :undef,
525
+ new_data.key?(:avatar) ? new_data[:avatar] : :undef)))
526
526
  end
527
527
  end
528
528
  end
@@ -317,7 +317,7 @@ module OnyxCord
317
317
  flags = OnyxCord::MessageComponents.apply_v2_flag(flags, new_components)
318
318
 
319
319
  response = REST::Channel.edit_message(@bot.token, @channel.id, @id, new_content, :undef, new_embeds, new_components, flags)
320
- Message.new(JSON.parse(response), @bot)
320
+ Message.new(OnyxCord::Internal::JSON.parse(response), @bot)
321
321
  end
322
322
 
323
323
  # Deletes this message.
@@ -347,7 +347,7 @@ module OnyxCord
347
347
  # @return [Message] the updated message object.
348
348
  def crosspost
349
349
  response = REST::Channel.crosspost_message(@bot.token, @channel.id, @id)
350
- Message.new(JSON.parse(response), @bot)
350
+ Message.new(OnyxCord::Internal::JSON.parse(response), @bot)
351
351
  end
352
352
 
353
353
  # Add an {Await} for a message with the same user and channel.
@@ -420,7 +420,7 @@ module OnyxCord
420
420
  def suppress_embeds
421
421
  flags = @flags | (1 << 2)
422
422
  response = REST::Channel.edit_message(@bot.token, @channel.id, @id, :undef, :undef, :undef, :undef, flags)
423
- Message.new(JSON.parse(response), @bot)
423
+ Message.new(OnyxCord::Internal::JSON.parse(response), @bot)
424
424
  end
425
425
 
426
426
  # Check if this message mentions a specific user or role.
@@ -459,7 +459,7 @@ module OnyxCord
459
459
 
460
460
  get_reactions = proc do |fetch_limit, after_id = nil|
461
461
  resp = REST::Channel.get_reactions(@bot.token, @channel.id, @id, reaction, nil, after_id, fetch_limit, type)
462
- JSON.parse(resp).map { |d| User.new(d, @bot) }
462
+ OnyxCord::Internal::JSON.parse(resp).map { |d| User.new(d, @bot) }
463
463
  end
464
464
 
465
465
  # Can be done without pagination
@@ -515,7 +515,7 @@ module OnyxCord
515
515
 
516
516
  # The inspect method is overwritten to give more useful output
517
517
  def inspect
518
- "<Message content=\"#{@content}\" id=#{@id} timestamp=#{@timestamp} author=#{@author} channel=#{@channel}>"
518
+ "<Message content=\"#{@content}\" id=#{@id} timestamp=#{creation_time} author=#{@author} channel=#{@channel}>"
519
519
  end
520
520
 
521
521
  # @return [String] a URL that a user can use to navigate to this message in the client
@@ -91,7 +91,7 @@ module OnyxCord
91
91
  def close
92
92
  raise OnyxCord::Errors::NoPermission, 'Cannot close the poll' if !@message.from_bot? || closed?
93
93
 
94
- Message.new(JSON.parse(REST::Channel.end_poll(@bot.token, @message.channel.id, @message.id)), @bot)
94
+ Message.new(OnyxCord::Internal::JSON.parse(REST::Channel.end_poll(@bot.token, @message.channel.id, @message.id)), @bot)
95
95
  end
96
96
 
97
97
  # Check if two poll objects are equivalent.
@@ -188,7 +188,7 @@ module OnyxCord
188
188
 
189
189
  get_users = lambda do |limit, after|
190
190
  data = REST::Channel.get_poll_voters(@bot.token, channel_id, @message_id, @id, after:, limit:)
191
- JSON.parse(data)['users'].collect { |poll_voter_data| @bot.ensure_user(poll_voter_data) }
191
+ OnyxCord::Internal::JSON.parse(data)['users'].collect { |poll_voter_data| @bot.ensure_user(poll_voter_data) }
192
192
  end
193
193
 
194
194
  return get_users.call(limit, after_time) if limit && limit <= 100
@@ -70,10 +70,10 @@ module OnyxCord
70
70
 
71
71
  # @!visibility private
72
72
  def update_profile_data(new_data)
73
- update_data(JSON.parse(REST::User.update_current_user(@bot.token,
74
- new_data[:username] || :undef,
75
- new_data.key?(:avatar) ? new_data[:avatar] : :undef,
76
- new_data.key?(:banner) ? new_data[:banner] : :undef)))
73
+ update_data(OnyxCord::Internal::JSON.parse(REST::User.update_current_user(@bot.token,
74
+ new_data[:username] || :undef,
75
+ new_data.key?(:avatar) ? new_data[:avatar] : :undef,
76
+ new_data.key?(:banner) ? new_data[:banner] : :undef)))
77
77
  end
78
78
  end
79
79
  end
@@ -431,7 +431,7 @@ module OnyxCord
431
431
  }
432
432
  end
433
433
 
434
- update_data(JSON.parse(REST::Server.update_role!(@bot.token, @server.id, @id, **data)))
434
+ update_data(OnyxCord::Internal::JSON.parse(REST::Server.update_role!(@bot.token, @server.id, @id, **data)))
435
435
  nil
436
436
  end
437
437
 
@@ -191,7 +191,7 @@ module OnyxCord
191
191
  builder[:recurrence_rule] = builder.to_h
192
192
  end
193
193
 
194
- update_data(JSON.parse(REST::Server.update_scheduled_event(@bot.token, @server_id, @id, **data)))
194
+ update_data(OnyxCord::Internal::JSON.parse(REST::Server.update_scheduled_event(@bot.token, @server_id, @id, **data)))
195
195
  nil
196
196
  end
197
197
 
@@ -207,7 +207,7 @@ module OnyxCord
207
207
  # Get the total amount of users who are subscribed to the scheduled event.
208
208
  # @return [Integer] The total amount of users who are currently subscribed to the scheduled event.
209
209
  def user_count
210
- @user_count ||= JSON.parse(REST::Server.get_scheduled_event(@bot.token, @server_id, @id, with_user_count: true))['user_count']
210
+ @user_count ||= OnyxCord::Internal::JSON.parse(REST::Server.get_scheduled_event(@bot.token, @server_id, @id, with_user_count: true))['user_count']
211
211
  end
212
212
 
213
213
  alias_method :subscriber_count, :user_count
@@ -218,7 +218,7 @@ module OnyxCord
218
218
  # @return [Array<User, Member>] the users or members that have subscribed to the scheduled event.
219
219
  def users(limit: 100, member: false)
220
220
  get_users = proc do |fetch_limit, after = nil|
221
- response = JSON.parse(REST::Server.get_scheduled_event_users(@bot.token, @server_id, @id, limit: fetch_limit, with_member: member, after: after))
221
+ response = OnyxCord::Internal::JSON.parse(REST::Server.get_scheduled_event_users(@bot.token, @server_id, @id, limit: fetch_limit, with_member: member, after: after))
222
222
  response.map { |data| data['member'] ? Member.new(data['member'], server, @bot).tap { |member| server&.cache_member(member) } : User.new(data['user'], @bot) }
223
223
  end
224
224