onyxcord 2.1.0 → 3.2.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 (270) hide show
  1. checksums.yaml +4 -4
  2. data/lib/onyxcord/application_commands/command.rb +4 -97
  3. data/lib/onyxcord/application_commands/context.rb +4 -94
  4. data/lib/onyxcord/application_commands/option.rb +4 -75
  5. data/lib/onyxcord/application_commands/registry.rb +4 -45
  6. data/lib/onyxcord/application_commands.rb +8 -5
  7. data/lib/onyxcord/bot.rb +24 -1759
  8. data/lib/onyxcord/{cache.rb → cache/manager.rb} +16 -14
  9. data/lib/onyxcord/cache/stores/gateway.rb +272 -0
  10. data/lib/onyxcord/commands/bot/channels.rb +48 -0
  11. data/lib/onyxcord/commands/bot/execution.rb +174 -0
  12. data/lib/onyxcord/commands/bot/message_dispatch.rb +58 -0
  13. data/lib/onyxcord/commands/bot/permissions.rb +72 -0
  14. data/lib/onyxcord/commands/bot.rb +209 -0
  15. data/lib/onyxcord/commands/container.rb +21 -2
  16. data/lib/onyxcord/commands/parser.rb +30 -1
  17. data/lib/onyxcord/container.rb +16 -960
  18. data/lib/onyxcord/core/bot/application_commands.rb +210 -0
  19. data/lib/onyxcord/core/bot/awaits.rb +112 -0
  20. data/lib/onyxcord/core/bot/invites.rb +42 -0
  21. data/lib/onyxcord/core/bot/messaging.rb +161 -0
  22. data/lib/onyxcord/core/bot/oauth.rb +27 -0
  23. data/lib/onyxcord/core/bot/presence.rb +103 -0
  24. data/lib/onyxcord/core/bot/runtime.rb +183 -0
  25. data/lib/onyxcord/core/bot/voice.rb +69 -0
  26. data/lib/onyxcord/{logger.rb → core/logger.rb} +5 -0
  27. data/lib/onyxcord/core/version.rb +5 -0
  28. data/lib/onyxcord/events/await/base.rb +48 -0
  29. data/lib/onyxcord/events/await.rb +1 -46
  30. data/lib/onyxcord/events/ban/base.rb +54 -0
  31. data/lib/onyxcord/events/ban/remove.rb +11 -0
  32. data/lib/onyxcord/events/bans.rb +2 -58
  33. data/lib/onyxcord/events/channels/base.rb +91 -0
  34. data/lib/onyxcord/events/channels/delete.rb +73 -0
  35. data/lib/onyxcord/events/channels/pins.rb +44 -0
  36. data/lib/onyxcord/events/channels/recipients.rb +77 -0
  37. data/lib/onyxcord/events/channels.rb +4 -239
  38. data/lib/onyxcord/events/guilds/audit_logs.rb +79 -0
  39. data/lib/onyxcord/events/guilds/base.rb +97 -0
  40. data/lib/onyxcord/events/guilds/emoji.rb +147 -0
  41. data/lib/onyxcord/events/guilds.rb +3 -267
  42. data/lib/onyxcord/events/handlers/channels.rb +133 -0
  43. data/lib/onyxcord/events/handlers/core.rb +146 -0
  44. data/lib/onyxcord/events/handlers/guilds.rb +375 -0
  45. data/lib/onyxcord/events/handlers/interactions.rb +238 -0
  46. data/lib/onyxcord/events/handlers/lifetime.rb +71 -0
  47. data/lib/onyxcord/events/handlers/messages.rb +218 -0
  48. data/lib/onyxcord/events/handlers/presence.rb +56 -0
  49. data/lib/onyxcord/events/handlers/raw.rb +39 -0
  50. data/lib/onyxcord/events/handlers/reactions.rb +98 -0
  51. data/lib/onyxcord/events/handlers/scheduled_events.rb +243 -0
  52. data/lib/onyxcord/events/handlers/voice.rb +46 -0
  53. data/lib/onyxcord/events/integration/base.rb +45 -0
  54. data/lib/onyxcord/events/integration/create.rb +11 -0
  55. data/lib/onyxcord/events/integration/delete.rb +48 -0
  56. data/lib/onyxcord/events/integration/update.rb +11 -0
  57. data/lib/onyxcord/events/integrations.rb +4 -98
  58. data/lib/onyxcord/events/interactions/application_commands.rb +185 -0
  59. data/lib/onyxcord/events/interactions/autocomplete.rb +62 -0
  60. data/lib/onyxcord/events/interactions/base.rb +175 -0
  61. data/lib/onyxcord/events/interactions/components.rb +221 -0
  62. data/lib/onyxcord/events/interactions/permissions.rb +53 -0
  63. data/lib/onyxcord/events/interactions.rb +5 -622
  64. data/lib/onyxcord/events/invite/create.rb +79 -0
  65. data/lib/onyxcord/events/invite/delete.rb +55 -0
  66. data/lib/onyxcord/events/invites.rb +2 -125
  67. data/lib/onyxcord/events/lifetime/base.rb +31 -0
  68. data/lib/onyxcord/events/lifetime.rb +1 -29
  69. data/lib/onyxcord/events/member/add.rb +12 -0
  70. data/lib/onyxcord/events/member/base.rb +67 -0
  71. data/lib/onyxcord/events/member/delete.rb +21 -0
  72. data/lib/onyxcord/events/member/update.rb +25 -0
  73. data/lib/onyxcord/events/members.rb +4 -108
  74. data/lib/onyxcord/events/message/base.rb +295 -0
  75. data/lib/onyxcord/events/message/ids.rb +71 -0
  76. data/lib/onyxcord/events/message/mentions.rb +55 -0
  77. data/lib/onyxcord/events/message/updates.rb +27 -0
  78. data/lib/onyxcord/events/message.rb +4 -397
  79. data/lib/onyxcord/events/poll/add.rb +11 -0
  80. data/lib/onyxcord/events/poll/base.rb +106 -0
  81. data/lib/onyxcord/events/poll/remove.rb +11 -0
  82. data/lib/onyxcord/events/polls.rb +3 -116
  83. data/lib/onyxcord/events/presence/playing.rb +77 -0
  84. data/lib/onyxcord/events/presence/status.rb +60 -0
  85. data/lib/onyxcord/events/presence.rb +2 -129
  86. data/lib/onyxcord/events/raw/base.rb +74 -0
  87. data/lib/onyxcord/events/raw.rb +1 -72
  88. data/lib/onyxcord/events/reactions/base.rb +143 -0
  89. data/lib/onyxcord/events/reactions/clear.rb +99 -0
  90. data/lib/onyxcord/events/reactions.rb +2 -216
  91. data/lib/onyxcord/events/role/create.rb +46 -0
  92. data/lib/onyxcord/events/role/delete.rb +40 -0
  93. data/lib/onyxcord/events/role/update.rb +11 -0
  94. data/lib/onyxcord/events/roles.rb +3 -85
  95. data/lib/onyxcord/events/scheduled_events/events.rb +112 -0
  96. data/lib/onyxcord/events/scheduled_events/users.rb +91 -0
  97. data/lib/onyxcord/events/scheduled_events.rb +2 -169
  98. data/lib/onyxcord/events/thread/base.rb +49 -0
  99. data/lib/onyxcord/events/thread/members.rb +44 -0
  100. data/lib/onyxcord/events/thread/update.rb +18 -0
  101. data/lib/onyxcord/events/threads.rb +3 -98
  102. data/lib/onyxcord/events/typing/base.rb +73 -0
  103. data/lib/onyxcord/events/typing.rb +1 -71
  104. data/lib/onyxcord/events/voice/server_update.rb +48 -0
  105. data/lib/onyxcord/events/voice/state_update.rb +137 -0
  106. data/lib/onyxcord/events/voice_server_update.rb +2 -46
  107. data/lib/onyxcord/events/voice_state_update.rb +2 -135
  108. data/lib/onyxcord/events/webhook/update.rb +65 -0
  109. data/lib/onyxcord/events/webhooks.rb +1 -63
  110. data/lib/onyxcord/gateway/client.rb +460 -0
  111. data/lib/onyxcord/interactions/command.rb +120 -0
  112. data/lib/onyxcord/interactions/context.rb +109 -0
  113. data/lib/onyxcord/interactions/internal/application_command.rb +203 -0
  114. data/lib/onyxcord/interactions/internal/message.rb +152 -0
  115. data/lib/onyxcord/interactions/internal/metadata.rb +109 -0
  116. data/lib/onyxcord/interactions/internal/option_builder.rb +230 -0
  117. data/lib/onyxcord/interactions/internal/permission_builder.rb +90 -0
  118. data/lib/onyxcord/interactions/option.rb +88 -0
  119. data/lib/onyxcord/interactions/registry.rb +50 -0
  120. data/lib/onyxcord/interactions.rb +16 -0
  121. data/lib/onyxcord/internal/async_runtime.rb +32 -0
  122. data/lib/onyxcord/internal/event_bus.rb +591 -0
  123. data/lib/onyxcord/internal/event_executor.rb +155 -0
  124. data/lib/onyxcord/internal/gateway/opcodes.rb +22 -0
  125. data/lib/onyxcord/internal/gateway/session.rb +45 -0
  126. data/lib/onyxcord/internal/http.rb +189 -0
  127. data/lib/onyxcord/internal/json.rb +51 -0
  128. data/lib/onyxcord/{message_payload.rb → internal/message_payload.rb} +3 -3
  129. data/lib/onyxcord/internal/rate_limiter/async_rest.rb +151 -0
  130. data/lib/onyxcord/internal/rate_limiter/gateway.rb +44 -0
  131. data/lib/onyxcord/internal/rate_limiter/rest.rb +144 -0
  132. data/lib/onyxcord/internal/websocket.rb +79 -0
  133. data/lib/onyxcord/light/data.rb +1 -1
  134. data/lib/onyxcord/light/integrations.rb +1 -1
  135. data/lib/onyxcord/light/light_bot.rb +7 -7
  136. data/lib/onyxcord/{data → models}/activity.rb +2 -2
  137. data/lib/onyxcord/{data → models}/application.rb +3 -3
  138. data/lib/onyxcord/{data → models}/avatar_decoration.rb +1 -1
  139. data/lib/onyxcord/{data → models}/channel.rb +23 -23
  140. data/lib/onyxcord/{data → models}/collectibles.rb +1 -1
  141. data/lib/onyxcord/{data → models}/emoji.rb +1 -1
  142. data/lib/onyxcord/models/interaction.rb +450 -0
  143. data/lib/onyxcord/{data → models}/invite.rb +1 -1
  144. data/lib/onyxcord/{data → models}/member.rb +11 -11
  145. data/lib/onyxcord/{data → models}/message.rb +18 -14
  146. data/lib/onyxcord/{data → models}/poll.rb +2 -2
  147. data/lib/onyxcord/{data → models}/primary_server.rb +1 -1
  148. data/lib/onyxcord/{data → models}/profile.rb +4 -4
  149. data/lib/onyxcord/{data → models}/role.rb +6 -12
  150. data/lib/onyxcord/{data → models}/scheduled_event.rb +5 -5
  151. data/lib/onyxcord/{data → models}/server.rb +41 -41
  152. data/lib/onyxcord/{data → models}/server_preview.rb +2 -2
  153. data/lib/onyxcord/{data → models}/team.rb +1 -1
  154. data/lib/onyxcord/{data → models}/user.rb +5 -5
  155. data/lib/onyxcord/{data → models}/webhook.rb +10 -10
  156. data/lib/onyxcord/models.rb +57 -0
  157. data/lib/onyxcord/{api.rb → rest/client.rb} +23 -22
  158. data/lib/onyxcord/{api → rest/routes}/application.rb +79 -57
  159. data/lib/onyxcord/rest/routes/channel/base.rb +73 -0
  160. data/lib/onyxcord/rest/routes/channel/groups.rb +78 -0
  161. data/lib/onyxcord/rest/routes/channel/messages.rb +130 -0
  162. data/lib/onyxcord/rest/routes/channel/permissions.rb +73 -0
  163. data/lib/onyxcord/rest/routes/channel/pins.rb +45 -0
  164. data/lib/onyxcord/rest/routes/channel/polls.rb +32 -0
  165. data/lib/onyxcord/rest/routes/channel/reactions.rb +86 -0
  166. data/lib/onyxcord/rest/routes/channel/threads.rb +176 -0
  167. data/lib/onyxcord/rest/routes/channel/webhooks.rb +47 -0
  168. data/lib/onyxcord/rest/routes/channel.rb +12 -0
  169. data/lib/onyxcord/{api/interaction.rb → rest/routes/interaction/base.rb} +7 -25
  170. data/lib/onyxcord/rest/routes/interaction/response.rb +24 -0
  171. data/lib/onyxcord/rest/routes/interaction.rb +4 -0
  172. data/lib/onyxcord/{api → rest/routes}/invite.rb +7 -7
  173. data/lib/onyxcord/rest/routes/server/admin.rb +174 -0
  174. data/lib/onyxcord/rest/routes/server/assets.rb +25 -0
  175. data/lib/onyxcord/rest/routes/server/bans.rb +67 -0
  176. data/lib/onyxcord/rest/routes/server/base.rb +77 -0
  177. data/lib/onyxcord/rest/routes/server/channels.rb +58 -0
  178. data/lib/onyxcord/rest/routes/server/emoji.rb +48 -0
  179. data/lib/onyxcord/rest/routes/server/members.rb +109 -0
  180. data/lib/onyxcord/rest/routes/server/messages.rb +19 -0
  181. data/lib/onyxcord/rest/routes/server/roles.rb +156 -0
  182. data/lib/onyxcord/rest/routes/server/scheduled_events.rb +86 -0
  183. data/lib/onyxcord/rest/routes/server.rb +12 -0
  184. data/lib/onyxcord/{api → rest/routes}/user.rb +23 -23
  185. data/lib/onyxcord/{api → rest/routes}/webhook.rb +22 -22
  186. data/lib/onyxcord/{allowed_mentions.rb → utils/allowed_mentions.rb} +1 -1
  187. data/lib/onyxcord/utils/timestamp.rb +69 -0
  188. data/lib/onyxcord/voice/{voice_bot.rb → client.rb} +4 -4
  189. data/lib/onyxcord/voice/encoder.rb +1 -1
  190. data/lib/onyxcord/voice/network/udp.rb +135 -0
  191. data/lib/onyxcord/voice/network/websocket.rb +225 -0
  192. data/lib/onyxcord/voice/network.rb +5 -357
  193. data/lib/onyxcord/webhooks/builder.rb +1 -1
  194. data/lib/onyxcord/webhooks/client.rb +13 -13
  195. data/lib/onyxcord/webhooks/modal/group_builder.rb +55 -0
  196. data/lib/onyxcord/webhooks/modal/label_builder.rb +183 -0
  197. data/lib/onyxcord/webhooks/modal.rb +2 -239
  198. data/lib/onyxcord/webhooks/version.rb +3 -3
  199. data/lib/onyxcord/webhooks/view/container_builder.rb +80 -0
  200. data/lib/onyxcord/webhooks/view/file_builder.rb +24 -0
  201. data/lib/onyxcord/webhooks/view/media_gallery_builder.rb +50 -0
  202. data/lib/onyxcord/webhooks/view/row_builder.rb +120 -0
  203. data/lib/onyxcord/webhooks/view/section_builder.rb +61 -0
  204. data/lib/onyxcord/webhooks/view/select_menu_builder.rb +77 -0
  205. data/lib/onyxcord/webhooks/view/separator_builder.rb +22 -0
  206. data/lib/onyxcord/webhooks/view/text_display_builder.rb +20 -0
  207. data/lib/onyxcord/webhooks/view.rb +9 -425
  208. data/lib/onyxcord.rb +106 -42
  209. metadata +207 -92
  210. data/.github/CONTRIBUTING.md +0 -13
  211. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  212. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -24
  213. data/.github/pull_request_template.md +0 -37
  214. data/.github/workflows/ci.yml +0 -78
  215. data/.github/workflows/codeql.yml +0 -65
  216. data/.github/workflows/deploy.yml +0 -54
  217. data/.github/workflows/release.yml +0 -51
  218. data/.gitignore +0 -17
  219. data/.markdownlint.json +0 -4
  220. data/.overcommit.yml +0 -7
  221. data/.rspec +0 -2
  222. data/.rubocop.yml +0 -129
  223. data/.yardopts +0 -1
  224. data/CHANGELOG.md +0 -257
  225. data/Gemfile +0 -6
  226. data/LICENSE.txt +0 -21
  227. data/README.md +0 -448
  228. data/Rakefile +0 -13
  229. data/lib/onyxcord/api/channel.rb +0 -703
  230. data/lib/onyxcord/api/server.rb +0 -775
  231. data/lib/onyxcord/async/runtime.rb +0 -30
  232. data/lib/onyxcord/commands/command_bot.rb +0 -505
  233. data/lib/onyxcord/data/interaction.rb +0 -1151
  234. data/lib/onyxcord/data.rb +0 -57
  235. data/lib/onyxcord/event_executor.rb +0 -153
  236. data/lib/onyxcord/gateway.rb +0 -505
  237. data/lib/onyxcord/http.rb +0 -186
  238. data/lib/onyxcord/json.rb +0 -49
  239. data/lib/onyxcord/rate_limiter/async_rest.rb +0 -150
  240. data/lib/onyxcord/rate_limiter/gateway.rb +0 -42
  241. data/lib/onyxcord/rate_limiter/rest.rb +0 -142
  242. data/lib/onyxcord/version.rb +0 -7
  243. data/lib/onyxcord/websocket.rb +0 -77
  244. data/onyxcord.gemspec +0 -63
  245. /data/lib/onyxcord/{configuration.rb → core/configuration.rb} +0 -0
  246. /data/lib/onyxcord/{errors.rb → core/errors.rb} +0 -0
  247. /data/lib/onyxcord/{upload.rb → internal/upload.rb} +0 -0
  248. /data/lib/onyxcord/{data → models}/attachment.rb +0 -0
  249. /data/lib/onyxcord/{data → models}/audit_logs.rb +0 -0
  250. /data/lib/onyxcord/{data → models}/call.rb +0 -0
  251. /data/lib/onyxcord/{data → models}/channel_tag.rb +0 -0
  252. /data/lib/onyxcord/{data → models}/component.rb +0 -0
  253. /data/lib/onyxcord/{data → models}/embed.rb +0 -0
  254. /data/lib/onyxcord/{data → models}/install_params.rb +0 -0
  255. /data/lib/onyxcord/{data → models}/integration.rb +0 -0
  256. /data/lib/onyxcord/{data → models}/message_activity.rb +0 -0
  257. /data/lib/onyxcord/{data → models}/overwrite.rb +0 -0
  258. /data/lib/onyxcord/{data → models}/reaction.rb +0 -0
  259. /data/lib/onyxcord/{data → models}/recipient.rb +0 -0
  260. /data/lib/onyxcord/{data → models}/role_connection_data.rb +0 -0
  261. /data/lib/onyxcord/{data → models}/role_subscription.rb +0 -0
  262. /data/lib/onyxcord/{data → models}/snapshot.rb +0 -0
  263. /data/lib/onyxcord/{data → models}/timestamp.rb +0 -0
  264. /data/lib/onyxcord/{data → models}/voice_region.rb +0 -0
  265. /data/lib/onyxcord/{data → models}/voice_state.rb +0 -0
  266. /data/lib/onyxcord/{colour_rgb.rb → utils/colour_rgb.rb} +0 -0
  267. /data/lib/onyxcord/{id_object.rb → utils/id_object.rb} +0 -0
  268. /data/lib/onyxcord/{message_components.rb → utils/message_components.rb} +0 -0
  269. /data/lib/onyxcord/{paginator.rb → utils/paginator.rb} +0 -0
  270. /data/lib/onyxcord/{permissions.rb → utils/permissions.rb} +0 -0
@@ -1,399 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'onyxcord/events/generic'
4
- require 'onyxcord/data'
5
-
6
- module OnyxCord::Events
7
- # Module to make sending messages easier with the presence of a text channel in an event
8
- module Respondable
9
- # @return [Channel] the channel in which this event occurred
10
- attr_reader :channel
11
-
12
- # Sends a message to the channel this message was sent in, right now. It is usually preferable to use {#<<} instead
13
- # because it avoids rate limiting problems
14
- # @param content [String] The message to send to the channel
15
- # @param tts [true, false] Whether or not this message should be sent using Discord text-to-speech.
16
- # @param embed [Hash, OnyxCord::Webhooks::Embed, nil] The rich embed to append to this message.
17
- # @param attachments [Array<File>] Files that can be referenced in embeds via `attachment://file.png`
18
- # @param allowed_mentions [Hash, OnyxCord::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
19
- # @param message_reference [Message, String, Integer, nil] The message, or message ID, to reply to if any.
20
- # @param components [View, Array<Hash>, nil] A collection of components to attach to the message.
21
- # @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2), SUPPRESS_NOTIFICATIONS (1 << 12), and IS_COMPONENTS_V2 (1 << 15) can be set.
22
- # @return [OnyxCord::Message] the message that was sent
23
- def send_message(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0)
24
- channel.send_message(content, tts, embed, attachments, allowed_mentions, message_reference, components, flags)
25
- end
26
-
27
- # The same as {#send_message}, but yields a {Webhooks::Embed} for easy building of embedded content inside a block.
28
- # @see Channel#send_embed
29
- # @param message [String] The message that should be sent along with the embed. If this is the empty string, only the embed will be shown.
30
- # @param embed [OnyxCord::Webhooks::Embed, nil] The embed to start the building process with, or nil if one should be created anew.
31
- # @param attachments [Array<File>] Files that can be referenced in embeds via `attachment://file.png`
32
- # @param tts [true, false] Whether or not this message should be sent using Discord text-to-speech.
33
- # @param allowed_mentions [Hash, OnyxCord::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
34
- # @param message_reference [Message, String, Integer, nil] The message, or message ID, to reply to if any.
35
- # @param components [View, Array<Hash>, nil] A collection of components to attach to the message.
36
- # @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2), SUPPRESS_NOTIFICATIONS (1 << 12), and IS_COMPONENTS_V2 (1 << 15) can be set.
37
- # @yield [embed] Yields the embed to allow for easy building inside a block.
38
- # @yieldparam embed [OnyxCord::Webhooks::Embed] The embed from the parameters, or a new one.
39
- # @return [Message] The resulting message.
40
- def send_embed(message = '', embed = nil, attachments = nil, tts = false, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0, &block)
41
- channel.send_embed(message, embed, attachments, tts, allowed_mentions, message_reference, components, flags, &block)
42
- end
43
-
44
- # Sends a temporary message to the channel this message was sent in, right now.
45
- # @param content [String] The content to send. Should not be longer than 2000 characters or it will result in an error.
46
- # @param timeout [Float] The amount of time in seconds after which the message sent will be deleted.
47
- # @param tts [true, false] Whether or not this message should be sent using Discord text-to-speech.
48
- # @param embed [Hash, OnyxCord::Webhooks::Embed, nil] The rich embed to append to this message.
49
- # @param attachments [Array<File>] Files that can be referenced in embeds via `attachment://file.png`
50
- # @param allowed_mentions [Hash, OnyxCord::AllowedMentions, false, nil] Mentions that are allowed to ping on this message. `false` disables all pings
51
- # @param components [View, Array<Hash>, nil] A collection of components to attach to the message.
52
- # @param flags [Integer] Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2), SUPPRESS_NOTIFICATIONS (1 << 12), and IS_COMPONENTS_V2 (1 << 15) can be set.
53
- def send_temporary_message(content, timeout, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, components = nil, flags = 0)
54
- channel.send_temporary_message(content, timeout, tts, embed, attachments, allowed_mentions, components, flags)
55
- end
56
-
57
- # Sends a message to the channel this message was sent in, right now.
58
- # @see Channel#send_message!
59
- def send_message!(...)
60
- channel.send_message!(...)
61
- end
62
-
63
- # Adds a string to be sent after the event has finished execution. Avoids problems with rate limiting because only
64
- # one message is ever sent. If it is used multiple times, the strings will bunch up into one message (separated by
65
- # newlines)
66
- # @param message [String] The message to send to the channel
67
- def <<(message)
68
- addition = "#{message}\n"
69
- @saved_message = @saved_message ? @saved_message + addition : addition
70
- nil
71
- end
72
-
73
- # Drains the currently saved message, which clears it out, resulting in everything being saved before being
74
- # thrown away and nothing being sent to the channel (unless there is something saved after this).
75
- # @see #<<
76
- def drain
77
- @saved_message = ''
78
- nil
79
- end
80
-
81
- # Drains the currently saved message into a result string. This prepends it before that string, clears the saved
82
- # message and returns the concatenation.
83
- # @param result [String] The result string to drain into.
84
- # @return [String] a string formed by concatenating the saved message and the argument.
85
- def drain_into(result)
86
- return if result.is_a?(OnyxCord::Message)
87
-
88
- result = (@saved_message.nil? ? '' : @saved_message.to_s) + (result.nil? ? '' : result.to_s)
89
- drain
90
- result
91
- end
92
-
93
- alias_method :send, :send_message
94
- alias_method :respond, :send_message
95
- alias_method :send_temp, :send_temporary_message
96
-
97
- alias_method :send!, :send_message!
98
- alias_method :respond!, :send_message!
99
- end
100
-
101
- # Event raised when a text message is sent to a channel
102
- class MessageEvent < Event
103
- include Respondable
104
-
105
- # @return [Message] the message which triggered this event.
106
- attr_reader :message
107
-
108
- # @return [String] the message that has been saved by calls to {#<<} and will be sent to Discord upon completion.
109
- attr_reader :saved_message
110
-
111
- # @return [File] the file that has been saved by a call to {#attach_file} and will be sent to Discord upon completion.
112
- attr_reader :file
113
-
114
- # @return [String] the filename set in {#attach_file} that will override the original filename when sent.
115
- attr_reader :filename
116
-
117
- # @return [true, false] Whether or not this file should appear as a spoiler. Set by {#attach_file}
118
- attr_reader :file_spoiler
119
-
120
- # @!attribute [r] author
121
- # @return [Member, User] who sent this message.
122
- # @see Message#author
123
- # @!attribute [r] channel
124
- # @return [Channel] the channel in which this message was sent.
125
- # @see Message#channel
126
- # @!attribute [r] content
127
- # @return [String] the message's content.
128
- # @see Message#content
129
- # @!attribute [r] timestamp
130
- # @return [Time] the time at which the message was sent.
131
- # @see Message#timestamp
132
- delegate :author, :channel, :content, :timestamp, to: :message
133
-
134
- # @!attribute [r] server
135
- # @return [Server, nil] the server where this message was sent, or nil if it was sent in PM.
136
- # @see Channel#server
137
- delegate :server, to: :channel
138
-
139
- # @!visibility private
140
- def initialize(message, bot)
141
- @bot = bot
142
- @message = message
143
- @channel = message.channel
144
- @saved_message = ''
145
- @file = nil
146
- @filename = nil
147
- @file_spoiler = nil
148
- end
149
-
150
- # Sends file with a caption to the channel this message was sent in, right now.
151
- # It is usually preferable to use {#<<} and {#attach_file} instead
152
- # because it avoids rate limiting problems
153
- # @param file [File] The file to send to the channel
154
- # @param caption [String] The caption attached to the file
155
- # @param filename [String] Overrides the filename of the uploaded file
156
- # @param spoiler [true, false] Whether or not this file should appear as a spoiler.
157
- # @return [OnyxCord::Message] the message that was sent
158
- # @example Send a file from disk
159
- # event.send_file(File.open('rubytaco.png', 'r'))
160
- def send_file(file, caption: nil, filename: nil, spoiler: nil)
161
- @message.channel.send_file(file, caption: caption, filename: filename, spoiler: spoiler)
162
- end
163
-
164
- # Attaches a file to the message event and converts the message into
165
- # a caption.
166
- # @param file [File] The file to be attached
167
- # @param filename [String] Overrides the filename of the uploaded file
168
- # @param spoiler [true, false] Whether or not this file should appear as a spoiler.
169
- def attach_file(file, filename: nil, spoiler: nil)
170
- raise ArgumentError, 'Argument is not a file!' unless file.is_a?(File)
171
-
172
- @file = file
173
- @filename = filename
174
- @file_spoiler = spoiler
175
- nil
176
- end
177
-
178
- # Detaches a file from the message event.
179
- def detach_file
180
- @file = nil
181
- @filename = nil
182
- @file_spoiler = nil
183
- end
184
-
185
- # @return [true, false] whether or not this message was sent by the bot itself
186
- def from_bot?
187
- @message.user.id == @bot.profile.id
188
- end
189
-
190
- # Utility method to get the voice bot for the current server
191
- # @return [VoiceBot, nil] the voice bot connected to this message's server, or nil if there is none connected
192
- def voice
193
- @bot.voice(@message.channel.server.id)
194
- end
195
-
196
- alias_method :user, :author
197
- alias_method :text, :content
198
- end
199
-
200
- # Event handler for MessageEvent
201
- class MessageEventHandler < EventHandler
202
- def matches?(event)
203
- # Check for the proper event type
204
- return false unless event.is_a? MessageEvent
205
-
206
- [
207
- matches_all(@attributes[:starting_with] || @attributes[:start_with], event.content) do |a, e|
208
- case a
209
- when String
210
- e.start_with? a
211
- when Regexp
212
- (e =~ a)&.zero?
213
- end
214
- end,
215
- matches_all(@attributes[:ending_with] || @attributes[:end_with], event.content) do |a, e|
216
- case a
217
- when String
218
- e.end_with? a
219
- when Regexp
220
- !(e =~ Regexp.new("#{a}$")).nil?
221
- end
222
- end,
223
- matches_all(@attributes[:containing] || @attributes[:contains], event.content) do |a, e|
224
- case a
225
- when String
226
- e.include? a
227
- when Regexp
228
- (e =~ a)
229
- end
230
- end,
231
- matches_all(@attributes[:in], event.channel) do |a, e|
232
- case a
233
- when String
234
- # Make sure to remove the "#" from channel names in case it was specified
235
- a.delete('#') == e.name
236
- when Integer
237
- a == e.id
238
- else
239
- a == e
240
- end
241
- end,
242
- matches_all(@attributes[:from], event.message) do |a, e|
243
- # Resolve the author in the block in order to prevent resolving the author even when the attribute is `nil`
244
- e = e.author
245
- case a
246
- when String
247
- a == e.name
248
- when Integer
249
- a == e.id
250
- when :bot
251
- e.current_bot?
252
- else
253
- a == e
254
- end
255
- end,
256
- matches_all(@attributes[:with_text] || @attributes[:content] || @attributes[:exact_text], event.content) do |a, e|
257
- case a
258
- when String
259
- e == a
260
- when Regexp
261
- match = a.match(e)
262
- match ? (e == match[0]) : false
263
- end
264
- end,
265
- matches_all(@attributes[:type] || @attributes[:message_type], event.message.type) do |a, e|
266
- case a
267
- when String, Symbol
268
- OnyxCord::Message::TYPES[a.to_sym] == e
269
- when Integer
270
- a == e
271
- end
272
- end,
273
- matches_all(@attributes[:after], event.timestamp) { |a, e| a > e },
274
- matches_all(@attributes[:before], event.timestamp) { |a, e| a < e },
275
- matches_all(@attributes[:private], event.channel.private?) { |a, e| !e == !a },
276
- matches_all(@attributes[:server], event.server) { |a, e| a&.resolve_id == e&.resolve_id }
277
- ].reduce(true, &:&)
278
- end
279
-
280
- # @see EventHandler#after_call
281
- def after_call(event)
282
- if event.file.nil?
283
- event.send_message(event.saved_message) unless event.saved_message.empty?
284
- else
285
- event.send_file(event.file, caption: event.saved_message, filename: event.filename, spoiler: event.file_spoiler)
286
- end
287
- end
288
- end
289
-
290
- # Event raised when the current bot is mentioned in a message.
291
- class MentionEvent < MessageEvent
292
- # @return [true, false] whether this mention event was raised
293
- # due to a mention of the bot's auto-generated server role.
294
- attr_reader :role_mention
295
- alias_method :role_mention?, :role_mention
296
-
297
- # @!visibility private
298
- def initialize(message, bot, role_mention)
299
- super(message, bot)
300
-
301
- @role_mention = role_mention
302
- end
303
- end
304
-
305
- # Event handler for {MentionEvent}
306
- class MentionEventHandler < MessageEventHandler
307
- # @!visibility private
308
- def matches?(event)
309
- return false unless super
310
- return false unless event.is_a?(MentionEvent)
311
-
312
- [
313
- matches_all(@attributes[:role_mention], event.role_mention) do |a, e|
314
- case a
315
- when TrueClass
316
- e == true
317
- when FalseClass
318
- e == false
319
- end
320
- end
321
- ].reduce(true, &:&)
322
- end
323
- end
324
-
325
- # @see OnyxCord::EventContainer#pm
326
- class PrivateMessageEvent < MessageEvent; end
327
-
328
- # Event handler for {PrivateMessageEvent}
329
- class PrivateMessageEventHandler < MessageEventHandler; end
330
-
331
- # A subset of MessageEvent that only contains a message ID and a channel
332
- class MessageIDEvent < Event
333
- include Respondable
334
-
335
- # @return [Integer] the ID associated with this event
336
- attr_reader :id
337
-
338
- # @return [Server, nil] the server associated with this event
339
- attr_reader :server
340
-
341
- # @!visibility private
342
- def initialize(data, bot)
343
- @id = data['id'].to_i
344
- @channel = bot.channel(data['channel_id'].to_i)
345
- @server = @channel.server
346
- @saved_message = ''
347
- @bot = bot
348
- end
349
- end
350
-
351
- # Event handler for {MessageIDEvent}
352
- class MessageIDEventHandler < EventHandler
353
- def matches?(event)
354
- # Check for the proper event type
355
- return false unless event.is_a? MessageIDEvent
356
-
357
- [
358
- matches_all(@attributes[:id], event.id) do |a, e|
359
- a.resolve_id == e.resolve_id
360
- end,
361
- matches_all(@attributes[:in], event.channel) do |a, e|
362
- case a
363
- when String
364
- # Make sure to remove the "#" from channel names in case it was specified
365
- a.delete('#') == e.name
366
- when Integer
367
- a == e.id
368
- else
369
- a == e
370
- end
371
- end,
372
- matches_all(@attributes[:server], event.server) do |a, e|
373
- a&.resolve_id == e&.resolve_id
374
- end
375
- ].reduce(true, &:&)
376
- end
377
- end
378
-
379
- # Raised when a message is edited
380
- # @see OnyxCord::EventContainer#message_edit
381
- class MessageEditEvent < MessageEvent; end
382
-
383
- # Event handler for {MessageEditEvent}
384
- class MessageEditEventHandler < MessageEventHandler; end
385
-
386
- # Raised when a message is deleted
387
- # @see OnyxCord::EventContainer#message_delete
388
- class MessageDeleteEvent < MessageIDEvent; end
389
-
390
- # Event handler for {MessageDeleteEvent}
391
- class MessageDeleteEventHandler < MessageIDEventHandler; end
392
-
393
- # Raised whenever a MESSAGE_UPDATE is received
394
- # @see OnyxCord::EventContainer#message_update
395
- class MessageUpdateEvent < MessageEvent; end
396
-
397
- # Event handler for {MessageUpdateEvent}
398
- class MessageUpdateEventHandler < MessageEventHandler; end
399
- end
3
+ require 'onyxcord/events/message/base'
4
+ require 'onyxcord/events/message/mentions'
5
+ require 'onyxcord/events/message/ids'
6
+ require 'onyxcord/events/message/updates'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onyxcord/events/poll/base'
4
+
5
+ module OnyxCord::Events
6
+ # Raised whenever someone votes on a poll.
7
+ class PollVoteAddEvent < PollVoteEvent; end
8
+
9
+ # Event handler for the :MESSAGE_POLL_VOTE_ADD event.
10
+ class PollVoteAddEventHandler < PollVoteEventHandler; end
11
+ end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onyxcord/models'
4
+ require 'onyxcord/events/generic'
5
+
6
+ module OnyxCord::Events
7
+ # Generic superclass for poll events.
8
+ class PollVoteEvent < Event
9
+ # @return [Integer] the ID of the user associated with the event.
10
+ attr_reader :user_id
11
+
12
+ # @return [Integer, nil] the ID of the server associated with the
13
+ # event.
14
+ attr_reader :server_id
15
+
16
+ # @return [Integer] the ID of the answer associated with the event.
17
+ attr_reader :answer_id
18
+
19
+ # @return [Integer] the ID of the channel associated with the event.
20
+ attr_reader :channel_id
21
+
22
+ # @return [Integer] the ID of the message associated with the event.
23
+ attr_reader :message_id
24
+
25
+ # @!visibility private
26
+ def initialize(data, bot)
27
+ @bot = bot
28
+ @user_id = data['user_id']&.to_i
29
+ @server_id = data['guild_id']&.to_i
30
+ @answer_id = data['answer_id']&.to_i
31
+ @channel_id = data['channel_id']&.to_i
32
+ @message_id = data['message_id']&.to_i
33
+ end
34
+
35
+ # Get the poll associated with the event.
36
+ # @return [Poll] The poll associated with the event.
37
+ def poll
38
+ message&.poll
39
+ end
40
+
41
+ # Get the poll answer associated with the event.
42
+ # @return [Poll::Answer] The poll answer associated with the event.
43
+ def answer
44
+ poll&.answer(@answer_id)
45
+ end
46
+
47
+ # Get the channel that the poll originates from.
48
+ # @return [Channel] The channel that the poll originates from.
49
+ def channel
50
+ @bot.channel(@channel_id)
51
+ end
52
+
53
+ # Get the server that the poll originates from.
54
+ # @return [Server, nil] The server that the poll originates from.
55
+ def server
56
+ @bot.server(@server_id) if @server_id
57
+ end
58
+
59
+ # Get the message that the poll originates from.
60
+ # @return [Message] The message that the poll originates from.
61
+ def message
62
+ @message ||= channel.load_message(@message_id)
63
+ end
64
+
65
+ # Get the user who added or removed their poll vote.
66
+ # @return [User, Member] The member who added the poll vote, or
67
+ # a user if the member cannot be reached, or the poll was created
68
+ # in a DM channel.
69
+ def user
70
+ @user ||= (server&.member(@user_id) || @bot.user(@user_id))
71
+ end
72
+
73
+ alias_method :member, :user
74
+ end
75
+
76
+ # Generic event handler for polls.
77
+ class PollVoteEventHandler < EventHandler
78
+ # @!visibility private
79
+ def matches?(event)
80
+ # Check for the proper event type.
81
+ return false unless event.is_a?(PollVoteEvent)
82
+
83
+ [
84
+ matches_all(@attributes[:answer], event.answer_id) do |a, e|
85
+ (a.respond_to?(:id) ? a.id : a&.resolve_id) == e
86
+ end,
87
+
88
+ matches_all(@attributes[:server], event.server_id) do |a, e|
89
+ a&.resolve_id == e
90
+ end,
91
+
92
+ matches_all(@attributes[:message], event.message_id) do |a, e|
93
+ a&.resolve_id == e
94
+ end,
95
+
96
+ matches_all(@attributes[:channel], event.channel_id) do |a, e|
97
+ a&.resolve_id == e
98
+ end,
99
+
100
+ matches_all(@attributes[:user] || @attributes[:member], event.user_id) do |a, e|
101
+ a&.resolve_id == e
102
+ end
103
+ ].reduce(true, &:&)
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onyxcord/events/poll/base'
4
+
5
+ module OnyxCord::Events
6
+ # Raised whenever someone removes a poll vote.
7
+ class PollVoteRemoveEvent < PollVoteEvent; end
8
+
9
+ # Event handler for the :MESSAGE_POLL_VOTE_REMOVE event.
10
+ class PollVoteRemoveEventHandler < PollVoteEventHandler; end
11
+ end
@@ -1,118 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'onyxcord/data'
4
- require 'onyxcord/events/generic'
5
-
6
- module OnyxCord::Events
7
- # Generic superclass for poll events.
8
- class PollVoteEvent < Event
9
- # @return [Integer] the ID of the user associated with the event.
10
- attr_reader :user_id
11
-
12
- # @return [Integer, nil] the ID of the server associated with the
13
- # event.
14
- attr_reader :server_id
15
-
16
- # @return [Integer] the ID of the answer associated with the event.
17
- attr_reader :answer_id
18
-
19
- # @return [Integer] the ID of the channel associated with the event.
20
- attr_reader :channel_id
21
-
22
- # @return [Integer] the ID of the message associated with the event.
23
- attr_reader :message_id
24
-
25
- # @!visibility private
26
- def initialize(data, bot)
27
- @bot = bot
28
- @user_id = data['user_id']&.to_i
29
- @server_id = data['guild_id']&.to_i
30
- @answer_id = data['answer_id']&.to_i
31
- @channel_id = data['channel_id']&.to_i
32
- @message_id = data['message_id']&.to_i
33
- end
34
-
35
- # Get the poll associated with the event.
36
- # @return [Poll] The poll associated with the event.
37
- def poll
38
- message&.poll
39
- end
40
-
41
- # Get the poll answer associated with the event.
42
- # @return [Poll::Answer] The poll answer associated with the event.
43
- def answer
44
- poll&.answer(@answer_id)
45
- end
46
-
47
- # Get the channel that the poll originates from.
48
- # @return [Channel] The channel that the poll originates from.
49
- def channel
50
- @bot.channel(@channel_id)
51
- end
52
-
53
- # Get the server that the poll originates from.
54
- # @return [Server, nil] The server that the poll originates from.
55
- def server
56
- @bot.server(@server_id) if @server_id
57
- end
58
-
59
- # Get the message that the poll originates from.
60
- # @return [Message] The message that the poll originates from.
61
- def message
62
- @message ||= channel.load_message(@message_id)
63
- end
64
-
65
- # Get the user who added or removed their poll vote.
66
- # @return [User, Member] The member who added the poll vote, or
67
- # a user if the member cannot be reached, or the poll was created
68
- # in a DM channel.
69
- def user
70
- @user ||= (server&.member(@user_id) || @bot.user(@user_id))
71
- end
72
-
73
- alias_method :member, :user
74
- end
75
-
76
- # Generic event handler for polls.
77
- class PollVoteEventHandler < EventHandler
78
- # @!visibility private
79
- def matches?(event)
80
- # Check for the proper event type.
81
- return false unless event.is_a?(PollVoteEvent)
82
-
83
- [
84
- matches_all(@attributes[:answer], event.answer_id) do |a, e|
85
- (a.respond_to?(:id) ? a.id : a&.resolve_id) == e
86
- end,
87
-
88
- matches_all(@attributes[:server], event.server_id) do |a, e|
89
- a&.resolve_id == e
90
- end,
91
-
92
- matches_all(@attributes[:message], event.message_id) do |a, e|
93
- a&.resolve_id == e
94
- end,
95
-
96
- matches_all(@attributes[:channel], event.channel_id) do |a, e|
97
- a&.resolve_id == e
98
- end,
99
-
100
- matches_all(@attributes[:user] || @attributes[:member], event.user_id) do |a, e|
101
- a&.resolve_id == e
102
- end
103
- ].reduce(true, &:&)
104
- end
105
- end
106
-
107
- # Raised whenever someone votes on a poll.
108
- class PollVoteAddEvent < PollVoteEvent; end
109
-
110
- # Raised whenever someone removes a poll vote.
111
- class PollVoteRemoveEvent < PollVoteEvent; end
112
-
113
- # Event handler for the :MESSAGE_POLL_VOTE_ADD event.
114
- class PollVoteAddEventHandler < PollVoteEventHandler; end
115
-
116
- # Event handler for the :MESSAGE_POLL_VOTE_REMOVE event.
117
- class PollVoteRemoveEventHandler < PollVoteEventHandler; end
118
- end
3
+ require 'onyxcord/events/poll/base'
4
+ require 'onyxcord/events/poll/add'
5
+ require 'onyxcord/events/poll/remove'