rubycord 1.0.0

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 (88) hide show
  1. checksums.yaml +7 -0
  2. data/lib/rubycord/allowed_mentions.rb +34 -0
  3. data/lib/rubycord/api/application.rb +200 -0
  4. data/lib/rubycord/api/channel.rb +597 -0
  5. data/lib/rubycord/api/interaction.rb +52 -0
  6. data/lib/rubycord/api/invite.rb +42 -0
  7. data/lib/rubycord/api/server.rb +557 -0
  8. data/lib/rubycord/api/user.rb +153 -0
  9. data/lib/rubycord/api/webhook.rb +138 -0
  10. data/lib/rubycord/api.rb +356 -0
  11. data/lib/rubycord/await.rb +49 -0
  12. data/lib/rubycord/bot.rb +1757 -0
  13. data/lib/rubycord/cache.rb +259 -0
  14. data/lib/rubycord/colour_rgb.rb +41 -0
  15. data/lib/rubycord/commands/command_bot.rb +519 -0
  16. data/lib/rubycord/commands/container.rb +110 -0
  17. data/lib/rubycord/commands/events.rb +9 -0
  18. data/lib/rubycord/commands/parser.rb +325 -0
  19. data/lib/rubycord/commands/rate_limiter.rb +142 -0
  20. data/lib/rubycord/container.rb +753 -0
  21. data/lib/rubycord/data/activity.rb +269 -0
  22. data/lib/rubycord/data/application.rb +48 -0
  23. data/lib/rubycord/data/attachment.rb +109 -0
  24. data/lib/rubycord/data/audit_logs.rb +343 -0
  25. data/lib/rubycord/data/channel.rb +996 -0
  26. data/lib/rubycord/data/component.rb +227 -0
  27. data/lib/rubycord/data/embed.rb +249 -0
  28. data/lib/rubycord/data/emoji.rb +80 -0
  29. data/lib/rubycord/data/integration.rb +120 -0
  30. data/lib/rubycord/data/interaction.rb +798 -0
  31. data/lib/rubycord/data/invite.rb +135 -0
  32. data/lib/rubycord/data/member.rb +370 -0
  33. data/lib/rubycord/data/message.rb +412 -0
  34. data/lib/rubycord/data/overwrite.rb +106 -0
  35. data/lib/rubycord/data/profile.rb +89 -0
  36. data/lib/rubycord/data/reaction.rb +31 -0
  37. data/lib/rubycord/data/recipient.rb +32 -0
  38. data/lib/rubycord/data/role.rb +246 -0
  39. data/lib/rubycord/data/server.rb +1002 -0
  40. data/lib/rubycord/data/user.rb +261 -0
  41. data/lib/rubycord/data/voice_region.rb +43 -0
  42. data/lib/rubycord/data/voice_state.rb +39 -0
  43. data/lib/rubycord/data/webhook.rb +232 -0
  44. data/lib/rubycord/data.rb +40 -0
  45. data/lib/rubycord/errors.rb +737 -0
  46. data/lib/rubycord/events/await.rb +46 -0
  47. data/lib/rubycord/events/bans.rb +58 -0
  48. data/lib/rubycord/events/channels.rb +186 -0
  49. data/lib/rubycord/events/generic.rb +126 -0
  50. data/lib/rubycord/events/guilds.rb +191 -0
  51. data/lib/rubycord/events/interactions.rb +480 -0
  52. data/lib/rubycord/events/invites.rb +123 -0
  53. data/lib/rubycord/events/lifetime.rb +29 -0
  54. data/lib/rubycord/events/members.rb +91 -0
  55. data/lib/rubycord/events/message.rb +337 -0
  56. data/lib/rubycord/events/presence.rb +127 -0
  57. data/lib/rubycord/events/raw.rb +45 -0
  58. data/lib/rubycord/events/reactions.rb +156 -0
  59. data/lib/rubycord/events/roles.rb +86 -0
  60. data/lib/rubycord/events/threads.rb +94 -0
  61. data/lib/rubycord/events/typing.rb +70 -0
  62. data/lib/rubycord/events/voice_server_update.rb +45 -0
  63. data/lib/rubycord/events/voice_state_update.rb +103 -0
  64. data/lib/rubycord/events/webhooks.rb +62 -0
  65. data/lib/rubycord/gateway.rb +867 -0
  66. data/lib/rubycord/id_object.rb +37 -0
  67. data/lib/rubycord/light/data.rb +60 -0
  68. data/lib/rubycord/light/integrations.rb +71 -0
  69. data/lib/rubycord/light/light_bot.rb +56 -0
  70. data/lib/rubycord/light.rb +6 -0
  71. data/lib/rubycord/logger.rb +118 -0
  72. data/lib/rubycord/paginator.rb +55 -0
  73. data/lib/rubycord/permissions.rb +251 -0
  74. data/lib/rubycord/version.rb +5 -0
  75. data/lib/rubycord/voice/encoder.rb +113 -0
  76. data/lib/rubycord/voice/network.rb +366 -0
  77. data/lib/rubycord/voice/sodium.rb +96 -0
  78. data/lib/rubycord/voice/voice_bot.rb +408 -0
  79. data/lib/rubycord/webhooks/builder.rb +100 -0
  80. data/lib/rubycord/webhooks/client.rb +132 -0
  81. data/lib/rubycord/webhooks/embeds.rb +248 -0
  82. data/lib/rubycord/webhooks/modal.rb +78 -0
  83. data/lib/rubycord/webhooks/version.rb +7 -0
  84. data/lib/rubycord/webhooks/view.rb +192 -0
  85. data/lib/rubycord/webhooks.rb +12 -0
  86. data/lib/rubycord/websocket.rb +70 -0
  87. data/lib/rubycord.rb +140 -0
  88. metadata +231 -0
@@ -0,0 +1,269 @@
1
+ module Rubycord
2
+ # Contains information about user activities such as the game they are playing,
3
+ # music they are listening to, or their live stream.
4
+ class Activity
5
+ # Values corresponding to the flags bitmask
6
+ FLAGS = {
7
+ instance: 1 << 0, # this activity is an instanced game session
8
+ join: 1 << 1, # this activity is joinable
9
+ spectate: 1 << 2, # this activity can be spectated
10
+ join_request: 1 << 3, # this activity allows asking to join
11
+ sync: 1 << 4, # this activity is a spotify track
12
+ play: 1 << 5 # this game can be played or opened from discord
13
+ }.freeze
14
+
15
+ # @return [String] the activity's name
16
+ attr_reader :name
17
+
18
+ # @return [Integer, nil] activity type. Can be {GAME}, {STREAMING}, {LISTENING}, {CUSTOM}, or {COMPETING}
19
+ attr_reader :type
20
+
21
+ # @return [String, nil] stream URL, when the activity type is {STREAMING}
22
+ attr_reader :url
23
+
24
+ # @return [String, nil] the application ID for the game
25
+ attr_reader :application_id
26
+
27
+ # @return [String, nil] details about what the player is currently doing
28
+ attr_reader :details
29
+
30
+ # @return [String, nil] the user's current party status
31
+ attr_reader :state
32
+
33
+ # @return [true, false] whether or not the activity is an instanced game session
34
+ attr_reader :instance
35
+
36
+ # @return [Integer] a bitmask of activity flags
37
+ # @see FLAGS
38
+ attr_reader :flags
39
+
40
+ # @return [Timestamps, nil] times for the start and/or end of the activity
41
+ attr_reader :timestamps
42
+
43
+ # @return [Secrets, nil] secrets for rich presence, joining, and spectating
44
+ attr_reader :secrets
45
+
46
+ # @return [Assets, nil] images for the presence and their texts
47
+ attr_reader :assets
48
+
49
+ # @return [Party, nil] information about the player's current party
50
+ attr_reader :party
51
+
52
+ # @return [Emoji, nil] emoji data for custom statuses
53
+ attr_reader :emoji
54
+
55
+ # @return [Time] the time when the activity was added to the user's session
56
+ attr_reader :created_at
57
+
58
+ # Type indicating the activity is for a game
59
+ GAME = 0
60
+ # Type indicating the activity is a stream
61
+ STREAMING = 1
62
+ # Type indicating the activity is for music
63
+ LISTENING = 2
64
+ # This type is currently unused in the client but can be reported by bots
65
+ WATCHING = 3
66
+ # Type indicating the activity is a custom status
67
+ CUSTOM = 4
68
+ # Type indicating the activity is for a competitive game
69
+ COMPETING = 5
70
+
71
+ # @!visibility private
72
+ def initialize(data, bot)
73
+ @name = data["name"]
74
+ @type = data["type"]
75
+ @url = data["url"]
76
+ @application_id = data["application_id"]
77
+ @details = data["details"]
78
+ @state = data["state"]
79
+ @instance = data["instance"]
80
+ @flags = data["flags"] || 0
81
+ @created_at = Time.at(data["created_at"].to_i)
82
+
83
+ @timestamps = Timestamps.new(data["timestamps"]) if data["timestamps"]
84
+ @secrets = Secret.new(data["secrets"]) if data["secrets"]
85
+ @assets = Assets.new(data["assets"], @application_id) if data["assets"]
86
+ @party = Party.new(data["party"]) if data["party"]
87
+ @emoji = Emoji.new(data["emoji"], bot, nil) if data["emoji"]
88
+ end
89
+
90
+ # @return [true, false] Whether or not the `join` flag is set for this activity
91
+ def join?
92
+ flag_set? :join
93
+ end
94
+
95
+ # @return [true, false] Whether or not the `spectate` flag is set for this activity
96
+ def spectate?
97
+ flag_set? :spectate
98
+ end
99
+
100
+ # @return [true, false] Whether or not the `join_request` flag is set for this activity
101
+ def join_request?
102
+ flag_set? :join_request
103
+ end
104
+
105
+ # @return [true, false] Whether or not the `sync` flag is set for this activity
106
+ def sync?
107
+ flag_set? :sync
108
+ end
109
+
110
+ # @return [true, false] Whether or not the `play` flag is set for this activity
111
+ def play?
112
+ flag_set? :play
113
+ end
114
+
115
+ # @return [true, false] Whether or not the `instance` flag is set for this activity
116
+ def instance?
117
+ @instance || flag_set?(:instance)
118
+ end
119
+
120
+ # @!visibility private
121
+ def flag_set?(sym)
122
+ !(@flags & FLAGS[sym]).zero?
123
+ end
124
+
125
+ # Timestamps for the start and end of instanced activities
126
+ class Timestamps
127
+ # @return [Time, nil]
128
+ attr_reader :start
129
+
130
+ # @return [Time, nil]
131
+ attr_reader :end
132
+
133
+ # @!visibility private
134
+ def initialize(data)
135
+ @start = Time.at(data["start"] / 1000) if data["start"]
136
+ @end = Time.at(data["end"] / 1000) if data["end"]
137
+ end
138
+ end
139
+
140
+ # Contains secrets used for rich presence
141
+ class Secrets
142
+ # @return [String, nil] secret for joining a party
143
+ attr_reader :join
144
+
145
+ # @return [String, nil] secret for spectating
146
+ attr_reader :spectate
147
+
148
+ # @return [String, nil] secret for a specific instanced match
149
+ attr_reader :match
150
+
151
+ # @!visibility private
152
+ def initialize(data)
153
+ @join = data["join"]
154
+ @spectate = data["spectate"]
155
+ @match = data["match"]
156
+ end
157
+ end
158
+
159
+ # Assets for rich presence images and hover text
160
+ class Assets
161
+ # @return [String, nil] the asset ID for the large image of this activity
162
+ attr_reader :large_image_id
163
+
164
+ # @return [String, nil] text displayed when hovering over the large iamge
165
+ attr_reader :large_text
166
+
167
+ # @return [String, nil] the asset ID for the small image of this activity
168
+ attr_reader :small_image_id
169
+
170
+ # @return [String, nil]
171
+ attr_reader :small_text
172
+
173
+ # @return [String, nil] the application ID for these assets.
174
+ attr_reader :application_id
175
+
176
+ # @!visibility private
177
+ def initialize(data, application_id)
178
+ @application_id = application_id
179
+ @large_image_id = data["large_image"]
180
+ @large_text = data["large_text"]
181
+ @small_image_id = data["small_image"]
182
+ @small_text = data["small_text"]
183
+ end
184
+
185
+ # Utility function to get an Asset's large image URL.
186
+ # @param format [String, nil] If `nil`, the URL will default to `webp`. You can otherwise specify one of `webp`, `jpg`, or `png`.
187
+ # @return [String] the URL to the large image asset.
188
+ def large_image_url(format = "webp")
189
+ API.asset_url(@application_id, @large_image_id, format)
190
+ end
191
+
192
+ # Utility function to get an Asset's large image URL.
193
+ # @param format [String, nil] If `nil`, the URL will default to `webp`. You can otherwise specify one of `webp`, `jpg`, or `png`.
194
+ # @return [String] the URL to the small image asset.
195
+ def small_image_url(format = "webp")
196
+ API.asset_url(@application_id, @small_image_id, format)
197
+ end
198
+ end
199
+
200
+ # Contains information about an activity's party
201
+ class Party
202
+ # @return [String, nil]
203
+ attr_reader :id
204
+
205
+ # @return [Integer, nil]
206
+ attr_reader :current_size
207
+
208
+ # @return [Integer, nil]
209
+ attr_reader :max_size
210
+
211
+ # @!visibility private
212
+ def initialize(data)
213
+ @id = data["id"]
214
+ @current_size, @max_size = data["size"]
215
+ end
216
+ end
217
+ end
218
+
219
+ # A collection of the user's activities.
220
+ class ActivitySet
221
+ include Enumerable
222
+
223
+ # @!visibility private
224
+ def initialize(activities = [])
225
+ @activities = activities
226
+ end
227
+
228
+ # @!visibility private
229
+ # Implement each for Enumerable
230
+ def each(&)
231
+ @activities.each(&)
232
+ end
233
+
234
+ # @return [Array<Activity>] all activities
235
+ def to_a
236
+ @activities
237
+ end
238
+
239
+ # @return [Array<Activity>] all activities of type {Activity::GAME}
240
+ def games
241
+ @activities.select { |act| act.type == Activity::GAME }
242
+ end
243
+
244
+ # @return [Array<Activity>] all activities of type {Activity::STREAMING}
245
+ def streaming
246
+ @activities.select { |act| act.type == Activity::STREAMING }
247
+ end
248
+
249
+ # @return [Array<Activity>] all activities of type {Activity::LISTENING}
250
+ def listening
251
+ @activities.select { |act| act.type == Activity::LISTENING }
252
+ end
253
+
254
+ # @return [Array<Activity>] all activities of type {Activity::WATCHING}
255
+ def watching
256
+ @activities.select { |act| act.type == Activity::WATCHING }
257
+ end
258
+
259
+ # @return [Array<Activity>] all activities of type {Activity::CUSTOM}
260
+ def custom_status
261
+ @activities.select { |act| act.type == Activity::CUSTOM }
262
+ end
263
+
264
+ # @return [Array<Activity>] all activities of type {Activity::COMPETING}
265
+ def competing
266
+ @activities.select { |act| act.type == Activity::COMPETING }
267
+ end
268
+ end
269
+ end
@@ -0,0 +1,48 @@
1
+ module Rubycord
2
+ # OAuth Application information
3
+ class Application
4
+ include IDObject
5
+
6
+ # @return [String] the application name
7
+ attr_reader :name
8
+
9
+ # @return [String] the application description
10
+ attr_reader :description
11
+
12
+ # @return [Array<String>] the application's origins permitted to use RPC
13
+ attr_reader :rpc_origins
14
+
15
+ # @return [Integer]
16
+ attr_reader :flags
17
+
18
+ # Gets the user object of the owner. May be limited to username, discriminator,
19
+ # ID, and avatar if the bot cannot reach the owner.
20
+ # @return [User] the user object of the owner
21
+ attr_reader :owner
22
+
23
+ def initialize(data, bot)
24
+ @bot = bot
25
+
26
+ @name = data["name"]
27
+ @id = data["id"].to_i
28
+ @description = data["description"]
29
+ @icon_id = data["icon"]
30
+ @rpc_origins = data["rpc_origins"]
31
+ @flags = data["flags"]
32
+ @owner = @bot.ensure_user(data["owner"])
33
+ end
34
+
35
+ # Utility function to get a application's icon URL.
36
+ # @return [String, nil] the URL of the icon image (nil if no image is set).
37
+ def icon_url
38
+ return nil if @icon_id.nil?
39
+
40
+ API.app_icon_url(@id, @icon_id)
41
+ end
42
+
43
+ # The inspect method is overwritten to give more useful output
44
+ def inspect
45
+ "<Application name=#{@name} id=#{@id}>"
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,109 @@
1
+ module Rubycord
2
+ # Mixin for the attributes attachments should have
3
+ module AttachmentAttributes
4
+ # Types of attachment's flags mapped to their API value.
5
+ # List of flags available here: https://discord.com/developers/docs/resources/message#attachment-object-attachment-flags
6
+ FLAGS = {
7
+ remix: 1 << 2, # IS_REMIX : this attachment has been edited using the remix feature on mobile
8
+ spoiler: 1 << 3 # : this attachment has been set to spoiler mode (not officially listed in doc, but seems to be the case after several tests)
9
+ }.freeze
10
+
11
+ # @return [Integer] attachment flags combined as a bitfield.
12
+ attr_reader :flags
13
+
14
+ # @!method remix?
15
+ # @return [true, false] whether this file has flag IS_REMIX.
16
+ # @!method spoiler?
17
+ # @note Unofficial flag
18
+ # @return [true, false] whether this file has flag IS_SPOILER.
19
+ FLAGS.each do |name, value|
20
+ define_method(:"#{name}?") do
21
+ (@flags & value).positive?
22
+ end
23
+ end
24
+ end
25
+
26
+ # An attachment to a message
27
+ class Attachment
28
+ include IDObject
29
+ include AttachmentAttributes
30
+
31
+ # @return [Message] the message this attachment belongs to.
32
+ attr_reader :message
33
+
34
+ # @return [String] the attachment's filename.
35
+ attr_reader :filename
36
+
37
+ # @return [String, nil] the attachment's title.
38
+ attr_reader :title
39
+
40
+ # @return [String, nil] the attachment's description.
41
+ attr_reader :description
42
+
43
+ # @return [String, nil] the attachment's media type.
44
+ attr_reader :content_type
45
+
46
+ # @return [Integer] the attachment's file size in bytes.
47
+ attr_reader :size
48
+
49
+ # @return [String] the CDN URL this attachment can be downloaded at.
50
+ attr_reader :url
51
+
52
+ # @return [String] the attachment's proxy URL - I'm not sure what exactly this does, but I think it has something to
53
+ # do with CDNs.
54
+ attr_reader :proxy_url
55
+
56
+ # @return [Integer, nil] the height of an image file, in pixels, or `nil` if the file is not an image.
57
+ attr_reader :height
58
+
59
+ # @return [Integer, nil] the width of an image file, in pixels, or `nil` if the file is not an image.
60
+ attr_reader :width
61
+
62
+ # @return [Float, nil] the duration of the audio file (currently for voice messages).
63
+ attr_reader :duration_secs
64
+
65
+ # @return [String, nil] base64 encoded bytearray representing a sampled waveform (currently for voice messages).
66
+ attr_reader :waveform
67
+
68
+ # @!visibility private
69
+ def initialize(data, message, bot)
70
+ @bot = bot
71
+ @message = message
72
+
73
+ @id = data["id"].resolve_id
74
+
75
+ @filename = data["filename"]
76
+ @title = data["title"]
77
+ @description = data["description"]
78
+
79
+ @content_type = data["content_type"]
80
+ @size = data["size"]
81
+
82
+ @url = data["url"]
83
+ @proxy_url = data["proxy_url"]
84
+
85
+ @height = data["height"]
86
+ @width = data["width"]
87
+ @duration_secs = data["duration_secs"]
88
+ @waveform = data["waveform"]
89
+
90
+ @flags = data["flags"].to_i
91
+ @ephemeral = data["ephemeral"]
92
+ end
93
+
94
+ # @return [true, false] whether this file is an image file.
95
+ def image?
96
+ !(@width.nil? || @height.nil?)
97
+ end
98
+
99
+ # @return [true, false] whether this file is an audio file.
100
+ def audio?
101
+ !@duration_secs.nil?
102
+ end
103
+
104
+ # @return [true, false] whether this attachment is ephemeral.
105
+ def ephemeral?
106
+ @ephemeral
107
+ end
108
+ end
109
+ end