onyxcord 2.1.0 → 3.2.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 (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
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onyxcord/events/generic'
4
+ require 'onyxcord/models'
5
+
6
+ module OnyxCord::Events
7
+ # Event raised when a user starts or stops playing a game
8
+ class PlayingEvent < Event
9
+ # @return [Server] the server on which the presence update happened.
10
+ attr_reader :server
11
+
12
+ # @return [User] the user whose status got updated.
13
+ attr_reader :user
14
+
15
+ # @return [OnyxCord::Activity] The new activity
16
+ attr_reader :activity
17
+
18
+ # @!attribute [r] url
19
+ # @return [String] the URL to the stream
20
+
21
+ # @!attribute [r] details
22
+ # @return [String] what the player is currently doing (ex. game being streamed)
23
+
24
+ # @!attribute [r] type
25
+ # @return [Integer] the type of play. See {OnyxCord::Activity}
26
+ delegate :url, :details, :type, to: :activity
27
+
28
+ # @return [Hash<Symbol, Symbol>] the current online status (`:online`, `:idle` or `:dnd`) of the user
29
+ # on various device types (`:desktop`, `:mobile`, or `:web`). The value will be `nil` if the user is offline or invisible.
30
+ attr_reader :client_status
31
+
32
+ # @!visibility private
33
+ def initialize(data, activity, bot)
34
+ @bot = bot
35
+ @activity = activity
36
+
37
+ @server = bot.server(data['guild_id'].to_i)
38
+ @user = bot.user(data['user']['id'].to_i)
39
+ @client_status = @user.client_status
40
+ end
41
+
42
+ # @return [String] the name of the new game the user is playing.
43
+ def game
44
+ @activity.name
45
+ end
46
+ end
47
+
48
+ # Event handler for PlayingEvent
49
+ class PlayingEventHandler < EventHandler
50
+ def matches?(event)
51
+ # Check for the proper event type
52
+ return false unless event.is_a? PlayingEvent
53
+
54
+ [
55
+ matches_all(@attributes[:from], event.user) do |a, e|
56
+ a == case a
57
+ when String
58
+ e.name
59
+ when Integer
60
+ e.id
61
+ else
62
+ e
63
+ end
64
+ end,
65
+ matches_all(@attributes[:game], event.game) do |a, e|
66
+ a == e
67
+ end,
68
+ matches_all(@attributes[:type], event.type) do |a, e|
69
+ a == e
70
+ end,
71
+ matches_all(@attributes[:client_status], event.client_status) do |a, e|
72
+ e.slice(a.keys) == a
73
+ end
74
+ ].reduce(true, &:&)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onyxcord/events/generic'
4
+ require 'onyxcord/models'
5
+
6
+ module OnyxCord::Events
7
+ # Event raised when a user's presence state updates (idle or online)
8
+ class PresenceEvent < Event
9
+ # @return [Server] the server on which the presence update happened.
10
+ attr_reader :server
11
+
12
+ # @return [User] the user whose status got updated.
13
+ attr_reader :user
14
+
15
+ # @return [Symbol] the new status.
16
+ attr_reader :status
17
+
18
+ # @return [Hash<Symbol, Symbol>] the current online status (`:online`, `:idle` or `:dnd`) of the user
19
+ # on various device types (`:desktop`, `:mobile`, or `:web`). The value will be `nil` if the user is offline or invisible.
20
+ attr_reader :client_status
21
+
22
+ # @!visibility private
23
+ def initialize(data, bot)
24
+ @bot = bot
25
+
26
+ @user = bot.user(data['user']['id'].to_i)
27
+ @status = data['status'].to_sym
28
+ @client_status = user.client_status
29
+ @server = bot.server(data['guild_id'].to_i)
30
+ end
31
+ end
32
+
33
+ # Event handler for PresenceEvent
34
+ class PresenceEventHandler < EventHandler
35
+ def matches?(event)
36
+ # Check for the proper event type
37
+ return false unless event.is_a? PresenceEvent
38
+
39
+ [
40
+ matches_all(@attributes[:from], event.user) do |a, e|
41
+ a == case a
42
+ when String
43
+ e.name
44
+ when Integer
45
+ e.id
46
+ else
47
+ e
48
+ end
49
+ end,
50
+ matches_all(@attributes[:status], event.status) do |a, e|
51
+ a == if a.is_a? String
52
+ e.to_s
53
+ else
54
+ e
55
+ end
56
+ end
57
+ ].reduce(true, &:&)
58
+ end
59
+ end
60
+ end
@@ -1,131 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'onyxcord/events/generic'
4
- require 'onyxcord/data'
5
-
6
- module OnyxCord::Events
7
- # Event raised when a user's presence state updates (idle or online)
8
- class PresenceEvent < Event
9
- # @return [Server] the server on which the presence update happened.
10
- attr_reader :server
11
-
12
- # @return [User] the user whose status got updated.
13
- attr_reader :user
14
-
15
- # @return [Symbol] the new status.
16
- attr_reader :status
17
-
18
- # @return [Hash<Symbol, Symbol>] the current online status (`:online`, `:idle` or `:dnd`) of the user
19
- # on various device types (`:desktop`, `:mobile`, or `:web`). The value will be `nil` if the user is offline or invisible.
20
- attr_reader :client_status
21
-
22
- # @!visibility private
23
- def initialize(data, bot)
24
- @bot = bot
25
-
26
- @user = bot.user(data['user']['id'].to_i)
27
- @status = data['status'].to_sym
28
- @client_status = user.client_status
29
- @server = bot.server(data['guild_id'].to_i)
30
- end
31
- end
32
-
33
- # Event handler for PresenceEvent
34
- class PresenceEventHandler < EventHandler
35
- def matches?(event)
36
- # Check for the proper event type
37
- return false unless event.is_a? PresenceEvent
38
-
39
- [
40
- matches_all(@attributes[:from], event.user) do |a, e|
41
- a == case a
42
- when String
43
- e.name
44
- when Integer
45
- e.id
46
- else
47
- e
48
- end
49
- end,
50
- matches_all(@attributes[:status], event.status) do |a, e|
51
- a == if a.is_a? String
52
- e.to_s
53
- else
54
- e
55
- end
56
- end
57
- ].reduce(true, &:&)
58
- end
59
- end
60
-
61
- # Event raised when a user starts or stops playing a game
62
- class PlayingEvent < Event
63
- # @return [Server] the server on which the presence update happened.
64
- attr_reader :server
65
-
66
- # @return [User] the user whose status got updated.
67
- attr_reader :user
68
-
69
- # @return [OnyxCord::Activity] The new activity
70
- attr_reader :activity
71
-
72
- # @!attribute [r] url
73
- # @return [String] the URL to the stream
74
-
75
- # @!attribute [r] details
76
- # @return [String] what the player is currently doing (ex. game being streamed)
77
-
78
- # @!attribute [r] type
79
- # @return [Integer] the type of play. See {OnyxCord::Activity}
80
- delegate :url, :details, :type, to: :activity
81
-
82
- # @return [Hash<Symbol, Symbol>] the current online status (`:online`, `:idle` or `:dnd`) of the user
83
- # on various device types (`:desktop`, `:mobile`, or `:web`). The value will be `nil` if the user is offline or invisible.
84
- attr_reader :client_status
85
-
86
- # @!visibility private
87
- def initialize(data, activity, bot)
88
- @bot = bot
89
- @activity = activity
90
-
91
- @server = bot.server(data['guild_id'].to_i)
92
- @user = bot.user(data['user']['id'].to_i)
93
- @client_status = @user.client_status
94
- end
95
-
96
- # @return [String] the name of the new game the user is playing.
97
- def game
98
- @activity.name
99
- end
100
- end
101
-
102
- # Event handler for PlayingEvent
103
- class PlayingEventHandler < EventHandler
104
- def matches?(event)
105
- # Check for the proper event type
106
- return false unless event.is_a? PlayingEvent
107
-
108
- [
109
- matches_all(@attributes[:from], event.user) do |a, e|
110
- a == case a
111
- when String
112
- e.name
113
- when Integer
114
- e.id
115
- else
116
- e
117
- end
118
- end,
119
- matches_all(@attributes[:game], event.game) do |a, e|
120
- a == e
121
- end,
122
- matches_all(@attributes[:type], event.type) do |a, e|
123
- a == e
124
- end,
125
- matches_all(@attributes[:client_status], event.client_status) do |a, e|
126
- e.slice(a.keys) == a
127
- end
128
- ].reduce(true, &:&)
129
- end
130
- end
131
- end
3
+ require 'onyxcord/events/presence/status'
4
+ require 'onyxcord/events/presence/playing'
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onyxcord/events/generic'
4
+
5
+ # Event classes and handlers
6
+ module OnyxCord::Events
7
+ # Event raised when any dispatch is received
8
+ class RawEvent < Event
9
+ # @return [Symbol] the type of this dispatch.
10
+ attr_reader :type
11
+ alias_method :t, :type
12
+
13
+ # @return [Hash] the data of this dispatch.
14
+ attr_reader :data
15
+ alias_method :d, :data
16
+
17
+ # @!visibility private
18
+ def initialize(type, data, bot)
19
+ @type = type
20
+ @data = data
21
+ @bot = bot
22
+ end
23
+ end
24
+
25
+ # Event handler for {RawEvent}
26
+ class RawEventHandler < EventHandler
27
+ def matches?(event)
28
+ # Check for the proper event type
29
+ return false unless event.is_a? RawEvent
30
+
31
+ [
32
+ matches_all(@attributes[:type] || @attributes[:t], event.type) do |a, e|
33
+ if a.is_a? Regexp
34
+ a.match?(e)
35
+ else
36
+ e.to_s.casecmp(a.to_s).zero?
37
+ end
38
+ end
39
+ ].reduce(true, &:&)
40
+ end
41
+ end
42
+
43
+ # Event raised when an unknown dispatch is received
44
+ class UnknownEvent < RawEvent; end
45
+
46
+ # Event handler for {UnknownEvent}
47
+ class UnknownEventHandler < RawEventHandler; end
48
+
49
+ # Handler for raw Gateway payloads. This bypasses Event object allocation and
50
+ # receives the original parsed Gateway packet.
51
+ class RawDispatchHandler
52
+ def initialize(filter, block)
53
+ @filter = filter
54
+ @block = block
55
+ end
56
+
57
+ def matches?(packet)
58
+ return true unless @filter
59
+
60
+ type = packet['t'] || packet[:t]
61
+ return false unless type
62
+
63
+ if @filter.is_a?(Regexp)
64
+ @filter.match?(type)
65
+ else
66
+ type.to_s.casecmp(@filter.to_s).zero?
67
+ end
68
+ end
69
+
70
+ def call(packet)
71
+ @block.call(packet)
72
+ end
73
+ end
74
+ end
@@ -1,74 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'onyxcord/events/generic'
4
-
5
- # Event classes and handlers
6
- module OnyxCord::Events
7
- # Event raised when any dispatch is received
8
- class RawEvent < Event
9
- # @return [Symbol] the type of this dispatch.
10
- attr_reader :type
11
- alias_method :t, :type
12
-
13
- # @return [Hash] the data of this dispatch.
14
- attr_reader :data
15
- alias_method :d, :data
16
-
17
- # @!visibility private
18
- def initialize(type, data, bot)
19
- @type = type
20
- @data = data
21
- @bot = bot
22
- end
23
- end
24
-
25
- # Event handler for {RawEvent}
26
- class RawEventHandler < EventHandler
27
- def matches?(event)
28
- # Check for the proper event type
29
- return false unless event.is_a? RawEvent
30
-
31
- [
32
- matches_all(@attributes[:type] || @attributes[:t], event.type) do |a, e|
33
- if a.is_a? Regexp
34
- a.match?(e)
35
- else
36
- e.to_s.casecmp(a.to_s).zero?
37
- end
38
- end
39
- ].reduce(true, &:&)
40
- end
41
- end
42
-
43
- # Event raised when an unknown dispatch is received
44
- class UnknownEvent < RawEvent; end
45
-
46
- # Event handler for {UnknownEvent}
47
- class UnknownEventHandler < RawEventHandler; end
48
-
49
- # Handler for raw Gateway payloads. This bypasses Event object allocation and
50
- # receives the original parsed Gateway packet.
51
- class RawDispatchHandler
52
- def initialize(filter, block)
53
- @filter = filter
54
- @block = block
55
- end
56
-
57
- def matches?(packet)
58
- return true unless @filter
59
-
60
- type = packet['t'] || packet[:t]
61
- return false unless type
62
-
63
- if @filter.is_a?(Regexp)
64
- @filter.match?(type)
65
- else
66
- type.to_s.casecmp(@filter.to_s).zero?
67
- end
68
- end
69
-
70
- def call(packet)
71
- @block.call(packet)
72
- end
73
- end
74
- end
3
+ require 'onyxcord/events/raw/base'
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onyxcord/events/generic'
4
+ require 'onyxcord/models'
5
+
6
+ module OnyxCord::Events
7
+ # Generic superclass for events about adding and removing reactions
8
+ class ReactionEvent < Event
9
+ include Respondable
10
+
11
+ # @return [Emoji] the emoji that was reacted with.
12
+ attr_reader :emoji
13
+
14
+ # @!visibility private
15
+ attr_reader :message_id
16
+
17
+ # @return [true, false] whether the reaction is a burst reaction.
18
+ attr_reader :burst
19
+ alias_method :burst?, :burst
20
+
21
+ # @return [Integer] the type of the reaction. 0 for normal, 1 for burst.
22
+ attr_reader :type
23
+
24
+ # @return [Array<ColourRGB>] an array of colors used for animations in burst reactions.
25
+ attr_reader :burst_colours
26
+ alias_method :burst_colors, :burst_colours
27
+
28
+ # @!visibility private
29
+ def initialize(data, bot)
30
+ @bot = bot
31
+
32
+ @emoji = OnyxCord::Emoji.new(data['emoji'], bot, nil)
33
+ @user_id = data['user_id'].to_i
34
+ @message_id = data['message_id'].to_i
35
+ @channel_id = data['channel_id'].to_i
36
+ @burst = data['burst']
37
+ @type = data['type']
38
+ @burst_colours = data['burst_colors']&.map { |b| OnyxCord::ColourRGB.new(b.delete('#')) } || []
39
+ end
40
+
41
+ # @return [User, Member] the user that reacted to this message, or member if a server exists.
42
+ def user
43
+ # Cache the user so we don't do requests all the time
44
+ @user ||= if server
45
+ @server.member(@user_id)
46
+ else
47
+ @bot.user(@user_id)
48
+ end
49
+ end
50
+
51
+ # @return [Message] the message that was reacted to.
52
+ def message
53
+ @message ||= channel.load_message(@message_id)
54
+ end
55
+
56
+ # @return [Channel] the channel that was reacted in.
57
+ def channel
58
+ @channel ||= @bot.channel(@channel_id)
59
+ end
60
+
61
+ # @return [Server, nil] the server that was reacted in. If reacted in a PM channel, it will be nil.
62
+ def server
63
+ @server ||= channel.server
64
+ end
65
+ end
66
+
67
+ # Generic superclass for event handlers pertaining to adding and removing reactions
68
+
69
+ # Generic superclass for event handlers pertaining to adding and removing reactions
70
+ class ReactionEventHandler < EventHandler
71
+ def matches?(event)
72
+ # Check for the proper event type
73
+ return false unless event.is_a? ReactionEvent
74
+
75
+ [
76
+ matches_all(@attributes[:emoji], event.emoji) do |a, e|
77
+ case a
78
+ when Integer
79
+ e.id == a
80
+ when String
81
+ e.name == a || e.name == a.delete(':') || e.id == a.resolve_id
82
+ else
83
+ e == a
84
+ end
85
+ end,
86
+ matches_all(@attributes[:message], event.message_id) do |a, e|
87
+ a == e
88
+ end,
89
+ matches_all(@attributes[:in], event.channel) do |a, e|
90
+ case a
91
+ when String
92
+ # Make sure to remove the "#" from channel names in case it was specified
93
+ a.delete('#') == e.name
94
+ when Integer
95
+ a == e.id
96
+ else
97
+ a == e
98
+ end
99
+ end,
100
+ matches_all(@attributes[:from], event.user) do |a, e|
101
+ case a
102
+ when String
103
+ a == e.name
104
+ when :bot
105
+ e.current_bot?
106
+ else
107
+ a == e
108
+ end
109
+ end,
110
+ matches_all(@attributes[:type], event.type) do |a, e|
111
+ case a
112
+ when Integer
113
+ a == e
114
+ when Symbol, String
115
+ OnyxCord::Reaction::TYPES[a.to_sym] == e
116
+ end
117
+ end
118
+ ].reduce(true, &:&)
119
+ end
120
+ end
121
+
122
+ # Event raised when somebody reacts to a message
123
+
124
+ # Event raised when somebody reacts to a message
125
+ class ReactionAddEvent < ReactionEvent; end
126
+
127
+ # Event handler for {ReactionAddEvent}
128
+
129
+ # Event handler for {ReactionAddEvent}
130
+ class ReactionAddEventHandler < ReactionEventHandler; end
131
+
132
+ # Event raised when somebody removes a reaction to a message
133
+
134
+ # Event raised when somebody removes a reaction to a message
135
+ class ReactionRemoveEvent < ReactionEvent; end
136
+
137
+ # Event handler for {ReactionRemoveEvent}
138
+
139
+ # Event handler for {ReactionRemoveEvent}
140
+ class ReactionRemoveEventHandler < ReactionEventHandler; end
141
+
142
+ # Event raised when somebody removes all reactions from a message
143
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'onyxcord/events/generic'
4
+ require 'onyxcord/models'
5
+
6
+ module OnyxCord::Events
7
+ # Event raised when somebody removes all reactions from a message
8
+ class ReactionRemoveAllEvent < Event
9
+ include Respondable
10
+
11
+ # @!visibility private
12
+ attr_reader :message_id
13
+
14
+ # @!visibility private
15
+ def initialize(data, bot)
16
+ @bot = bot
17
+
18
+ @message_id = data['message_id'].to_i
19
+ @channel_id = data['channel_id'].to_i
20
+ end
21
+
22
+ # @return [Channel] the channel where the removal occurred.
23
+ def channel
24
+ @channel ||= @bot.channel(@channel_id)
25
+ end
26
+
27
+ # @return [Message] the message all reactions were removed from.
28
+ def message
29
+ @message ||= channel.load_message(@message_id)
30
+ end
31
+ end
32
+
33
+ # Event handler for {ReactionRemoveAllEvent}
34
+
35
+ # Event handler for {ReactionRemoveAllEvent}
36
+ class ReactionRemoveAllEventHandler < EventHandler
37
+ def matches?(event)
38
+ # Check for the proper event type
39
+ return false unless event.is_a? ReactionRemoveAllEvent
40
+
41
+ [
42
+ matches_all(@attributes[:message], event.message_id) do |a, e|
43
+ a == e
44
+ end,
45
+ matches_all(@attributes[:in], event.channel) do |a, e|
46
+ case a
47
+ when String
48
+ # Make sure to remove the "#" from channel names in case it was specified
49
+ a.delete('#') == e.name
50
+ when Integer
51
+ a == e.id
52
+ else
53
+ a == e
54
+ end
55
+ end
56
+ ].reduce(true, &:&)
57
+ end
58
+ end
59
+
60
+ # Event raised when all instances of a single reaction are removed from a message.
61
+
62
+ # Event raised when all instances of a single reaction are removed from a message.
63
+ class ReactionRemoveEmojiEvent < ReactionRemoveAllEvent
64
+ # @return [Emoji] the emoji that was removed.
65
+ attr_reader :emoji
66
+
67
+ # @!visibility private
68
+ def initialize(data, bot)
69
+ super
70
+
71
+ @emoji = OnyxCord::Emoji.new(data['emoji'], bot)
72
+ end
73
+ end
74
+
75
+ # Event handler for {ReactionRemoveEmojiEvent}.
76
+
77
+ # Event handler for {ReactionRemoveEmojiEvent}.
78
+ class ReactionRemoveEmojiEventHandler < ReactionRemoveAllEventHandler
79
+ # @!visibility private
80
+ def matches?(event)
81
+ # Check for the proper event type.
82
+ return false unless super
83
+ return false unless event.is_a?(ReactionRemoveEmojiEvent)
84
+
85
+ [
86
+ matches_all(@attributes[:emoji], event.emoji) do |a, e|
87
+ case a
88
+ when Integer
89
+ e.id == a
90
+ when String
91
+ e.name == a || e.name == a.delete(':') || e.id == a.resolve_id
92
+ else
93
+ e == a
94
+ end
95
+ end
96
+ ].reduce(true, &:&)
97
+ end
98
+ end
99
+ end