rubycord 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
data/lib/rubycord.rb ADDED
@@ -0,0 +1,140 @@
1
+ require "rubycord/version"
2
+ require "rubycord/bot"
3
+ require "rubycord/commands/command_bot"
4
+ require "rubycord/logger"
5
+
6
+ # All rubycord functionality, to be extended by other files
7
+ module Rubycord
8
+ Thread.current[:rubycord_name] = "main"
9
+
10
+ # The default debug logger used by rubycord.
11
+ LOGGER = Logger.new(ENV.fetch("RUBYCORD_FANCY_LOG", false))
12
+
13
+ # The Unix timestamp Discord IDs are based on
14
+ DISCORD_EPOCH = 1_420_070_400_000
15
+
16
+ # Used to declare what events you wish to recieve from Discord.
17
+ # @see https://discord.com/developers/docs/topics/gateway#gateway-intents
18
+ INTENTS = {
19
+ servers: 1 << 0,
20
+ server_members: 1 << 1,
21
+ server_moderation: 1 << 2,
22
+ server_emojis_and_stickers: 1 << 3,
23
+ server_integrations: 1 << 4,
24
+ server_webhooks: 1 << 5,
25
+ server_invites: 1 << 6,
26
+ server_voice_states: 1 << 7,
27
+ server_presences: 1 << 8,
28
+ server_messages: 1 << 9,
29
+ server_message_reactions: 1 << 10,
30
+ server_message_typing: 1 << 11,
31
+ direct_messages: 1 << 12,
32
+ direct_message_reactions: 1 << 13,
33
+ direct_message_typing: 1 << 14,
34
+ message_content: 1 << 15,
35
+ server_scheduled_events: 1 << 16,
36
+ auto_moderation_configuration: 1 << 20,
37
+ auto_moderation_execution: 1 << 21,
38
+ server_message_polls: 1 << 24,
39
+ direct_message_polls: 1 << 25
40
+ }.freeze
41
+
42
+ # All available intents
43
+ ALL_INTENTS = INTENTS.values.reduce(&:|)
44
+
45
+ # All unprivileged intents
46
+ # @see https://discord.com/developers/docs/topics/gateway#privileged-intents
47
+ UNPRIVILEGED_INTENTS = ALL_INTENTS & ~(INTENTS[:server_members] | INTENTS[:server_presences] | INTENTS[:message_content])
48
+
49
+ # No intents
50
+ NO_INTENTS = 0
51
+
52
+ # Compares two objects based on IDs - either the objects' IDs are equal, or one object is equal to the other's ID.
53
+ def self.id_compare(one_id, other)
54
+ other.respond_to?(:resolve_id) ? (one_id.resolve_id == other.resolve_id) : (one_id == other)
55
+ end
56
+
57
+ # The maximum length a Discord message can have
58
+ CHARACTER_LIMIT = 2000
59
+
60
+ # For creating timestamps with {timestamp}
61
+ # @see https://discord.com/developers/docs/reference#message-formatting-timestamp-styles
62
+ TIMESTAMP_STYLES = {
63
+ short_time: "t", # 16:20
64
+ long_time: "T", # 16:20:30
65
+ short_date: "d", # 20/04/2021
66
+ long_date: "D", # 20 April 2021
67
+ short_datetime: "f", # 20 April 2021 16:20
68
+ long_datetime: "F", # Tuesday, 20 April 2021 16:20
69
+ relative: "R" # 2 months ago
70
+ }.freeze
71
+
72
+ # Splits a message into chunks of 2000 characters. Attempts to split by lines if possible.
73
+ # @param msg [String] The message to split.
74
+ # @return [Array<String>] the message split into chunks
75
+ def self.split_message(msg)
76
+ # If the messages is empty, return an empty array
77
+ return [] if msg.empty?
78
+
79
+ # Split the message into lines
80
+ lines = msg.lines
81
+
82
+ # Turn the message into a "triangle" of consecutively longer slices, for example the array [1,2,3,4] would become
83
+ # [
84
+ # [1],
85
+ # [1, 2],
86
+ # [1, 2, 3],
87
+ # [1, 2, 3, 4]
88
+ # ]
89
+ tri = (0...lines.length).map { |i| lines.combination(i + 1).first }
90
+
91
+ # Join the individual elements together to get an array of strings with consecutively more lines
92
+ joined = tri.map(&:join)
93
+
94
+ # Find the largest element that is still below the character limit, or if none such element exists return the first
95
+ ideal = joined.max_by { |e| (e.length > CHARACTER_LIMIT) ? -1 : e.length }
96
+
97
+ # If it's still larger than the character limit (none was smaller than it) split it into the largest chunk without
98
+ # cutting words apart, breaking on the nearest space within character limit, otherwise just return an array with one element
99
+ ideal_ary = (ideal.length > CHARACTER_LIMIT) ? ideal.split(/(.{1,#{CHARACTER_LIMIT}}\b|.{1,#{CHARACTER_LIMIT}})/o).reject(&:empty?) : [ideal]
100
+
101
+ # Slice off the ideal part and strip newlines
102
+ rest = msg[ideal.length..].strip
103
+
104
+ # If none remains, return an empty array -> we're done
105
+ return [] unless rest
106
+
107
+ # Otherwise, call the method recursively to split the rest of the string and add it onto the ideal array
108
+ ideal_ary + split_message(rest)
109
+ end
110
+
111
+ # @param time [Time, Integer] The time to create the timestamp from, or a unix timestamp integer.
112
+ # @param style [Symbol, String] One of the keys from {TIMESTAMP_STYLES} or a string with the style.
113
+ # @return [String]
114
+ # @example
115
+ # Rubycord.timestamp(Time.now, :short_time)
116
+ # # => "<t:1632146954:t>"
117
+ def self.timestamp(time, style = nil)
118
+ if style.nil?
119
+ "<t:#{time.to_i}>"
120
+ else
121
+ "<t:#{time.to_i}:#{TIMESTAMP_STYLES[style] || style}>"
122
+ end
123
+ end
124
+ end
125
+
126
+ # In rubycord, Integer and {String} are monkey-patched to allow for easy resolution of IDs
127
+ class Integer
128
+ # @return [Integer] The Discord ID represented by this integer, i.e. the integer itself
129
+ def resolve_id
130
+ self
131
+ end
132
+ end
133
+
134
+ # In rubycord, {Integer} and String are monkey-patched to allow for easy resolution of IDs
135
+ class String
136
+ # @return [Integer] The Discord ID represented by this string, i.e. the string converted to an integer
137
+ def resolve_id
138
+ to_i
139
+ end
140
+ end
metadata ADDED
@@ -0,0 +1,231 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubycord
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dakurei
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: base64
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bigdecimal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.8
41
+ - !ruby/object:Gem::Dependency
42
+ name: ffi
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.9.24
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.9.24
55
+ - !ruby/object:Gem::Dependency
56
+ name: opus-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rest-client
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: websocket-client-simple
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.3.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.3.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubycord-webhooks
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.0.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.0
111
+ description: A Ruby implementation of the Discord (https://discord.com) API.
112
+ email:
113
+ - maxime.palanchini@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - lib/rubycord.rb
119
+ - lib/rubycord/allowed_mentions.rb
120
+ - lib/rubycord/api.rb
121
+ - lib/rubycord/api/application.rb
122
+ - lib/rubycord/api/channel.rb
123
+ - lib/rubycord/api/interaction.rb
124
+ - lib/rubycord/api/invite.rb
125
+ - lib/rubycord/api/server.rb
126
+ - lib/rubycord/api/user.rb
127
+ - lib/rubycord/api/webhook.rb
128
+ - lib/rubycord/await.rb
129
+ - lib/rubycord/bot.rb
130
+ - lib/rubycord/cache.rb
131
+ - lib/rubycord/colour_rgb.rb
132
+ - lib/rubycord/commands/command_bot.rb
133
+ - lib/rubycord/commands/container.rb
134
+ - lib/rubycord/commands/events.rb
135
+ - lib/rubycord/commands/parser.rb
136
+ - lib/rubycord/commands/rate_limiter.rb
137
+ - lib/rubycord/container.rb
138
+ - lib/rubycord/data.rb
139
+ - lib/rubycord/data/activity.rb
140
+ - lib/rubycord/data/application.rb
141
+ - lib/rubycord/data/attachment.rb
142
+ - lib/rubycord/data/audit_logs.rb
143
+ - lib/rubycord/data/channel.rb
144
+ - lib/rubycord/data/component.rb
145
+ - lib/rubycord/data/embed.rb
146
+ - lib/rubycord/data/emoji.rb
147
+ - lib/rubycord/data/integration.rb
148
+ - lib/rubycord/data/interaction.rb
149
+ - lib/rubycord/data/invite.rb
150
+ - lib/rubycord/data/member.rb
151
+ - lib/rubycord/data/message.rb
152
+ - lib/rubycord/data/overwrite.rb
153
+ - lib/rubycord/data/profile.rb
154
+ - lib/rubycord/data/reaction.rb
155
+ - lib/rubycord/data/recipient.rb
156
+ - lib/rubycord/data/role.rb
157
+ - lib/rubycord/data/server.rb
158
+ - lib/rubycord/data/user.rb
159
+ - lib/rubycord/data/voice_region.rb
160
+ - lib/rubycord/data/voice_state.rb
161
+ - lib/rubycord/data/webhook.rb
162
+ - lib/rubycord/errors.rb
163
+ - lib/rubycord/events/await.rb
164
+ - lib/rubycord/events/bans.rb
165
+ - lib/rubycord/events/channels.rb
166
+ - lib/rubycord/events/generic.rb
167
+ - lib/rubycord/events/guilds.rb
168
+ - lib/rubycord/events/interactions.rb
169
+ - lib/rubycord/events/invites.rb
170
+ - lib/rubycord/events/lifetime.rb
171
+ - lib/rubycord/events/members.rb
172
+ - lib/rubycord/events/message.rb
173
+ - lib/rubycord/events/presence.rb
174
+ - lib/rubycord/events/raw.rb
175
+ - lib/rubycord/events/reactions.rb
176
+ - lib/rubycord/events/roles.rb
177
+ - lib/rubycord/events/threads.rb
178
+ - lib/rubycord/events/typing.rb
179
+ - lib/rubycord/events/voice_server_update.rb
180
+ - lib/rubycord/events/voice_state_update.rb
181
+ - lib/rubycord/events/webhooks.rb
182
+ - lib/rubycord/gateway.rb
183
+ - lib/rubycord/id_object.rb
184
+ - lib/rubycord/light.rb
185
+ - lib/rubycord/light/data.rb
186
+ - lib/rubycord/light/integrations.rb
187
+ - lib/rubycord/light/light_bot.rb
188
+ - lib/rubycord/logger.rb
189
+ - lib/rubycord/paginator.rb
190
+ - lib/rubycord/permissions.rb
191
+ - lib/rubycord/version.rb
192
+ - lib/rubycord/voice/encoder.rb
193
+ - lib/rubycord/voice/network.rb
194
+ - lib/rubycord/voice/sodium.rb
195
+ - lib/rubycord/voice/voice_bot.rb
196
+ - lib/rubycord/webhooks.rb
197
+ - lib/rubycord/webhooks/builder.rb
198
+ - lib/rubycord/webhooks/client.rb
199
+ - lib/rubycord/webhooks/embeds.rb
200
+ - lib/rubycord/webhooks/modal.rb
201
+ - lib/rubycord/webhooks/version.rb
202
+ - lib/rubycord/webhooks/view.rb
203
+ - lib/rubycord/websocket.rb
204
+ homepage: https://github.com/dakurei-gems/rubycord
205
+ licenses:
206
+ - MIT
207
+ metadata:
208
+ allowed_push_host: https://rubygems.org
209
+ homepage_uri: https://github.com/dakurei-gems/rubycord
210
+ source_code_uri: https://github.com/dakurei-gems/rubycord
211
+ changelog_uri: https://github.com/dakurei-gems/rubycord/blob/main/CHANGELOG.md
212
+ post_install_message:
213
+ rdoc_options: []
214
+ require_paths:
215
+ - lib
216
+ required_ruby_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: 3.1.3
221
+ required_rubygems_version: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - ">="
224
+ - !ruby/object:Gem::Version
225
+ version: '0'
226
+ requirements: []
227
+ rubygems_version: 3.5.17
228
+ signing_key:
229
+ specification_version: 4
230
+ summary: Discord API for Ruby
231
+ test_files: []