discorb 0.16.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +1 -0
  3. data/.github/workflows/build_main.yml +2 -2
  4. data/.github/workflows/build_version.yml +1 -1
  5. data/.github/workflows/codeql-analysis.yml +1 -1
  6. data/.github/workflows/lint-push.yml +3 -5
  7. data/.github/workflows/lint.yml +2 -4
  8. data/.github/workflows/spec.yml +33 -0
  9. data/.github/workflows/validate.yml +21 -0
  10. data/.gitignore +2 -0
  11. data/.lefthook/commit-msg/validator.rb +5 -0
  12. data/.rspec +2 -0
  13. data/.rspec_parallel +2 -0
  14. data/.rubocop.yml +43 -6
  15. data/Changelog.md +30 -1
  16. data/Gemfile +20 -8
  17. data/Rakefile +226 -98
  18. data/Steepfile +28 -0
  19. data/bin/console +3 -3
  20. data/docs/Examples.md +1 -1
  21. data/docs/application_command.md +156 -47
  22. data/docs/cli/irb.md +2 -2
  23. data/docs/cli/new.md +14 -9
  24. data/docs/cli/run.md +7 -11
  25. data/docs/cli.md +17 -10
  26. data/docs/events.md +247 -213
  27. data/docs/extension.md +1 -2
  28. data/docs/faq.md +0 -1
  29. data/docs/tutorial.md +18 -18
  30. data/docs/voice_events.md +106 -106
  31. data/examples/commands/message.rb +68 -0
  32. data/examples/commands/permission.rb +19 -0
  33. data/examples/commands/slash.rb +48 -0
  34. data/examples/commands/user.rb +54 -0
  35. data/examples/components/authorization_button.rb +4 -3
  36. data/examples/components/select_menu.rb +6 -3
  37. data/examples/extension/main.rb +2 -1
  38. data/examples/extension/message_expander.rb +6 -2
  39. data/examples/sig/commands/message.rbs +5 -0
  40. data/examples/simple/eval.rb +3 -2
  41. data/examples/simple/ping_pong.rb +2 -1
  42. data/examples/simple/rolepanel.rb +17 -6
  43. data/examples/simple/shard.rb +3 -2
  44. data/examples/simple/wait_for_message.rb +4 -1
  45. data/exe/discorb +33 -18
  46. data/lefthook.yml +45 -0
  47. data/lib/discorb/allowed_mentions.rb +2 -1
  48. data/lib/discorb/app_command/command.rb +130 -72
  49. data/lib/discorb/app_command/common.rb +25 -0
  50. data/lib/discorb/app_command/handler.rb +130 -33
  51. data/lib/discorb/app_command.rb +2 -1
  52. data/lib/discorb/application.rb +1 -0
  53. data/lib/discorb/asset.rb +1 -2
  54. data/lib/discorb/attachment.rb +1 -1
  55. data/lib/discorb/audit_logs.rb +19 -10
  56. data/lib/discorb/automod.rb +269 -0
  57. data/lib/discorb/channel/base.rb +108 -0
  58. data/lib/discorb/channel/category.rb +32 -0
  59. data/lib/discorb/channel/container.rb +44 -0
  60. data/lib/discorb/channel/dm.rb +28 -0
  61. data/lib/discorb/channel/guild.rb +246 -0
  62. data/lib/discorb/channel/stage.rb +140 -0
  63. data/lib/discorb/channel/text.rb +336 -0
  64. data/lib/discorb/channel/thread.rb +325 -0
  65. data/lib/discorb/channel/voice.rb +79 -0
  66. data/lib/discorb/channel.rb +2 -1165
  67. data/lib/discorb/client.rb +50 -36
  68. data/lib/discorb/color.rb +37 -60
  69. data/lib/discorb/common.rb +2 -1
  70. data/lib/discorb/components/button.rb +2 -1
  71. data/lib/discorb/components/select_menu.rb +4 -2
  72. data/lib/discorb/components/text_input.rb +12 -2
  73. data/lib/discorb/components.rb +1 -1
  74. data/lib/discorb/dictionary.rb +1 -1
  75. data/lib/discorb/embed.rb +26 -10
  76. data/lib/discorb/emoji.rb +31 -4
  77. data/lib/discorb/emoji_table.rb +4969 -3
  78. data/lib/discorb/event.rb +29 -4
  79. data/lib/discorb/exe/about.rb +2 -1
  80. data/lib/discorb/exe/irb.rb +2 -4
  81. data/lib/discorb/exe/new.rb +89 -26
  82. data/lib/discorb/exe/run.rb +8 -22
  83. data/lib/discorb/exe/setup.rb +25 -12
  84. data/lib/discorb/exe/show.rb +4 -3
  85. data/lib/discorb/extend.rb +1 -0
  86. data/lib/discorb/extension.rb +6 -7
  87. data/lib/discorb/flag.rb +13 -2
  88. data/lib/discorb/gateway.rb +79 -589
  89. data/lib/discorb/gateway_events.rb +638 -0
  90. data/lib/discorb/guild.rb +318 -67
  91. data/lib/discorb/guild_template.rb +11 -5
  92. data/lib/discorb/http.rb +53 -24
  93. data/lib/discorb/integration.rb +4 -1
  94. data/lib/discorb/intents.rb +28 -19
  95. data/lib/discorb/interaction/autocomplete.rb +28 -16
  96. data/lib/discorb/interaction/command.rb +42 -14
  97. data/lib/discorb/interaction/components.rb +5 -2
  98. data/lib/discorb/interaction/modal.rb +0 -1
  99. data/lib/discorb/interaction/response.rb +125 -26
  100. data/lib/discorb/interaction/root.rb +13 -13
  101. data/lib/discorb/interaction.rb +1 -0
  102. data/lib/discorb/invite.rb +5 -2
  103. data/lib/discorb/member.rb +28 -8
  104. data/lib/discorb/message.rb +60 -25
  105. data/lib/discorb/message_meta.rb +3 -3
  106. data/lib/discorb/modules.rb +59 -16
  107. data/lib/discorb/presence.rb +2 -0
  108. data/lib/discorb/rate_limit.rb +7 -2
  109. data/lib/discorb/reaction.rb +2 -2
  110. data/lib/discorb/role.rb +20 -5
  111. data/lib/discorb/shard.rb +1 -1
  112. data/lib/discorb/sticker.rb +9 -8
  113. data/lib/discorb/user.rb +4 -3
  114. data/lib/discorb/utils/colored_puts.rb +1 -0
  115. data/lib/discorb/voice_state.rb +6 -2
  116. data/lib/discorb/webhook.rb +64 -31
  117. data/lib/discorb.rb +7 -5
  118. data/po/yard.pot +20 -20
  119. data/rbs_collection.lock.yaml +88 -0
  120. data/rbs_collection.yaml +21 -0
  121. data/sig/async.rbs +11 -0
  122. data/sig/discorb/activity.rbs +23 -0
  123. data/sig/discorb/allowed_mentions.rbs +44 -0
  124. data/sig/discorb/app_command/base.rbs +282 -0
  125. data/sig/discorb/app_command/handler.rbs +171 -0
  126. data/sig/discorb/application.rbs +142 -0
  127. data/sig/discorb/asset.rbs +32 -0
  128. data/sig/discorb/attachment.rbs +91 -0
  129. data/sig/discorb/audit_log.rbs +231 -0
  130. data/sig/discorb/automod.rbs +128 -0
  131. data/sig/discorb/avatar.rbs +26 -0
  132. data/sig/discorb/channel/base.rbs +179 -0
  133. data/sig/discorb/channel/category.rbs +56 -0
  134. data/sig/discorb/channel/container.rbs +29 -0
  135. data/sig/discorb/channel/dm.rbs +14 -0
  136. data/sig/discorb/channel/news.rbs +20 -0
  137. data/sig/discorb/channel/stage.rbs +77 -0
  138. data/sig/discorb/channel/text.rbs +158 -0
  139. data/sig/discorb/channel/thread.rbs +185 -0
  140. data/sig/discorb/channel/voice.rbs +41 -0
  141. data/sig/discorb/client.rbs +2495 -0
  142. data/sig/discorb/color.rbs +142 -0
  143. data/sig/discorb/component/base.rbs +28 -0
  144. data/sig/discorb/component/button.rbs +65 -0
  145. data/sig/discorb/component/select_menu.rbs +107 -0
  146. data/sig/discorb/component/text_input.rbs +69 -0
  147. data/sig/discorb/connectable.rbs +8 -0
  148. data/sig/discorb/custom_emoji.rbs +90 -0
  149. data/sig/discorb/dictionary.rbs +85 -0
  150. data/sig/discorb/discord_model.rbs +15 -0
  151. data/sig/discorb/embed.rbs +279 -0
  152. data/sig/discorb/emoji.rbs +13 -0
  153. data/sig/discorb/error.rbs +73 -0
  154. data/sig/discorb/event_handler.rbs +27 -0
  155. data/sig/discorb/extension.rbs +1734 -0
  156. data/sig/discorb/flag.rbs +72 -0
  157. data/sig/discorb/gateway.rbs +481 -0
  158. data/sig/discorb/guild.rbs +870 -0
  159. data/sig/discorb/guild_template.rbs +174 -0
  160. data/sig/discorb/http.rbs +147 -0
  161. data/sig/discorb/image.rbs +20 -0
  162. data/sig/discorb/integration.rbs +118 -0
  163. data/sig/discorb/intents.rbs +97 -0
  164. data/sig/discorb/interaction/autocomplete.rbs +9 -0
  165. data/sig/discorb/interaction/base.rbs +66 -0
  166. data/sig/discorb/interaction/command.rbs +66 -0
  167. data/sig/discorb/interaction/message_component.rbs +140 -0
  168. data/sig/discorb/interaction/modal.rbs +50 -0
  169. data/sig/discorb/interaction/responder.rbs +157 -0
  170. data/sig/discorb/invite.rbs +86 -0
  171. data/sig/discorb/member.rbs +187 -0
  172. data/sig/discorb/message.rbs +469 -0
  173. data/sig/discorb/messageable.rbs +153 -0
  174. data/sig/discorb/partial_emoji.rbs +35 -0
  175. data/sig/discorb/permissions.rbs +149 -0
  176. data/sig/discorb/presence.rbs +237 -0
  177. data/sig/discorb/reaction.rbs +33 -0
  178. data/sig/discorb/role.rbs +145 -0
  179. data/sig/discorb/scheduled_event.rbs +148 -0
  180. data/sig/discorb/shard.rbs +62 -0
  181. data/sig/discorb/snowflake.rbs +56 -0
  182. data/sig/discorb/stage_instance.rbs +63 -0
  183. data/sig/discorb/sticker.rbs +116 -0
  184. data/sig/discorb/system_channel_flag.rbs +17 -0
  185. data/sig/discorb/unicode_emoji.rbs +49 -0
  186. data/sig/discorb/user.rbs +93 -0
  187. data/sig/discorb/utils.rbs +8 -0
  188. data/sig/discorb/voice_region.rbs +30 -0
  189. data/sig/discorb/voice_state.rbs +71 -0
  190. data/sig/discorb/webhook.rbs +327 -0
  191. data/sig/discorb/welcome_screen.rbs +78 -0
  192. data/sig/discorb.rbs +6 -7230
  193. data/sig/manifest.yaml +3 -0
  194. data/sig/override.rbs +19 -0
  195. data/template-replace/files/css/common.css +4 -0
  196. metadata +102 -6
  197. data/examples/commands/bookmarker.rb +0 -42
  198. data/examples/commands/hello.rb +0 -10
  199. data/examples/commands/inspect.rb +0 -25
data/docs/extension.md CHANGED
@@ -64,7 +64,6 @@ class MyExtension
64
64
  end
65
65
  ```
66
66
 
67
-
68
67
  ## Load extension
69
68
 
70
69
  Use {Discorb::Client#load_extension} to load extension.
@@ -127,4 +126,4 @@ class MyExtension
127
126
  puts "This extension is loaded to #{client}"
128
127
  end
129
128
  end
130
- ```
129
+ ```
data/docs/faq.md CHANGED
@@ -36,7 +36,6 @@ message = channel.post("Hello world!").wait # => Message
36
36
  message.pin
37
37
  ```
38
38
 
39
-
40
39
  ### How can I send DM to a user?
41
40
 
42
41
  Use {Discorb::User#post} method, {Discorb::User} includes {Discorb::Messageable}.
data/docs/tutorial.md CHANGED
@@ -11,21 +11,21 @@ Let's get started!
11
11
 
12
12
  - Ruby 3.0.0+
13
13
  - Basic knowledge of ruby
14
- These documents will help you:
15
- - [Ruby in Twenty Minutes](https://www.ruby-lang.org/en/documentation/quickstart/)
16
- - [Ruby from other languages](https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/)
17
- - [Try ruby!](https://try.ruby-lang.org/)
14
+ These documents will help you:
15
+ - [Ruby in Twenty Minutes](https://www.ruby-lang.org/en/documentation/quickstart/)
16
+ - [Ruby from other languages](https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/)
17
+ - [Try ruby!](https://try.ruby-lang.org/)
18
18
 
19
19
  ### Recommended
20
20
 
21
21
  - Good editor
22
- They are recommended:
23
- - [VSCode](https://code.visualstudio.com/)
24
- - [Atom](https://atom.io/)
25
- - [Sublime Text](https://www.sublimetext.com/)
26
- - [Brackets](https://brackets.io/)
27
- - [Notepad++](https://notepad-plus-plus.org/)
28
- - [Vim](https://www.vim.org/)
22
+ They are recommended:
23
+ - [VSCode](https://code.visualstudio.com/)
24
+ - [RubyMine](https://www.jetbrains.com/ruby/)
25
+ - [Sublime Text](https://www.sublimetext.com/)
26
+ - [Brackets](https://brackets.io/)
27
+ - [Notepad++](https://notepad-plus-plus.org/)
28
+ - [Vim](https://www.vim.org/)
29
29
  - Git
30
30
  - Bundler
31
31
 
@@ -98,10 +98,10 @@ You will get other files if you specify `--git`.
98
98
  Open `main.rb`, you will see the following code:
99
99
 
100
100
  ```ruby
101
- require "discorb"
102
- require "dotenv"
101
+ # frozen_string_literal: true
103
102
 
104
- Dotenv.load # Loads .env file
103
+ require "discorb"
104
+ require "dotenv/load" # Load environment variables from .env file.
105
105
 
106
106
  client = Discorb::Client.new # Create client for connecting to Discord
107
107
 
@@ -115,10 +115,10 @@ client.run ENV["TOKEN"] # Starts client
115
115
  Open `.env`, you will see:
116
116
 
117
117
  ```
118
- TOKEN=Y0urB0tT0k3nHer3.Th1sT0ken.W0ntWorkB3c4useItH4sM34n1ng
118
+ TOKEN=
119
119
  ```
120
120
 
121
- Replace `Y0urB0tT0k3nHer3.Th1sT0ken.W0ntWorkB3c4useItH4sM34n1ng` with your bot token.
121
+ Put your token after `TOKEN=`.
122
122
  Remember to keep this file secret!
123
123
 
124
124
  Open terminal and type:
@@ -160,7 +160,7 @@ end
160
160
 
161
161
  Save your bot and restart it.
162
162
 
163
- You can see your bot's response by typing `hello` in your server...
163
+ You can see your bot's response by typing `hello` in your server...
164
164
 
165
165
  ![](./assets/07_hello_infinite.png)
166
166
 
@@ -194,4 +194,4 @@ You did it! Your bot won't respond to bot's messages anymore.
194
194
  This is the end of tutorial.
195
195
 
196
196
  To learn more, check out the [documentation](https://discorb-lib.github.io/).
197
- You can also check out [Examples](docs/examples).
197
+ You can also check out [Examples](https://github.com/discorb-lib/discorb/tree/main/examples).
data/docs/voice_events.md CHANGED
@@ -10,35 +10,35 @@
10
10
 
11
11
  Fires when someone joins a voice channel.
12
12
 
13
- | Parameter | Type | Description |
14
- | --- | --- | --- |
15
- | state | {Discorb::VoiceState} | The voice state of the user that joined. |
13
+ | Parameter | Type | Description |
14
+ | --------- | --------------------- | ---------------------------------------- |
15
+ | state | {Discorb::VoiceState} | The voice state of the user that joined. |
16
16
 
17
17
  #### `voice_channel_disconnect(state)`
18
18
 
19
19
  Fires when someone leaves a voice channel.
20
20
 
21
- | Parameter | Type | Description |
22
- | --- | --- | --- |
23
- | state | {Discorb::VoiceState} | The voice state of the user that left. |
21
+ | Parameter | Type | Description |
22
+ | --------- | --------------------- | -------------------------------------- |
23
+ | state | {Discorb::VoiceState} | The voice state of the user that left. |
24
24
 
25
25
  #### `voice_channel_move(before, after)`
26
26
 
27
27
  Fires when someone moves to a different voice channel.
28
28
 
29
- | Parameter | Type | Description |
30
- | --- | --- | --- |
31
- | before | {Discorb::VoiceState} | The voice state of the user before the move. |
32
- | after | {Discorb::VoiceState} | The voice state of the user after the move. |
29
+ | Parameter | Type | Description |
30
+ | --------- | --------------------- | -------------------------------------------- |
31
+ | before | {Discorb::VoiceState} | The voice state of the user before the move. |
32
+ | after | {Discorb::VoiceState} | The voice state of the user after the move. |
33
33
 
34
34
  #### `voice_channel_update(before, after)`
35
35
 
36
36
  Fires when a voice channel is connected, disconnected, or updated.
37
37
 
38
- | Parameter | Type | Description |
39
- | --- | --- | --- |
40
- | before | {Discorb::VoiceState} | The voice state before the update. |
41
- | after | {Discorb::VoiceState} | The voice state after the update. |
38
+ | Parameter | Type | Description |
39
+ | --------- | --------------------- | ---------------------------------- |
40
+ | before | {Discorb::VoiceState} | The voice state before the update. |
41
+ | after | {Discorb::VoiceState} | The voice state after the update. |
42
42
 
43
43
  ### Mute Events
44
44
 
@@ -46,76 +46,76 @@ Fires when a voice channel is connected, disconnected, or updated.
46
46
 
47
47
  Fires when a user's voice mute is disabled.
48
48
 
49
- | Parameter | Type | Description |
50
- | --- | --- | --- |
51
- | `state` | {Discorb::VoiceState} | The voice state. |
49
+ | Parameter | Type | Description |
50
+ | --------- | --------------------- | ---------------- |
51
+ | `state` | {Discorb::VoiceState} | The voice state. |
52
52
 
53
53
  #### `voice_mute_enable(state)`
54
54
 
55
55
  Fires when a user's voice mute is enabled.
56
56
 
57
- | Parameter | Type | Description |
58
- | --- | --- | --- |
59
- | `state` | {Discorb::VoiceState} | The voice state. |
57
+ | Parameter | Type | Description |
58
+ | --------- | --------------------- | ---------------- |
59
+ | `state` | {Discorb::VoiceState} | The voice state. |
60
60
 
61
61
  #### `voice_mute_update(before, after)`
62
62
 
63
63
  Fires when a user's voice mute is enabled or disabled.
64
64
 
65
- | Parameter | Type | Description |
66
- | --- | --- | --- |
67
- | `before` | {Discorb::VoiceState} | The voice state before the update. |
68
- | `after` | {Discorb::VoiceState} | The voice state after the update. |
65
+ | Parameter | Type | Description |
66
+ | --------- | --------------------- | ---------------------------------- |
67
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
68
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
69
69
 
70
70
  #### `voice_server_mute_enable(state)`
71
71
 
72
72
  Fires when a user's server voice mute is enabled.
73
73
 
74
- | Parameter | Type | Description |
75
- | --- | --- | --- |
76
- | `state` | {Discorb::VoiceState} | The voice state. |
74
+ | Parameter | Type | Description |
75
+ | --------- | --------------------- | ---------------- |
76
+ | `state` | {Discorb::VoiceState} | The voice state. |
77
77
 
78
78
  #### `voice_server_mute_disable(state)`
79
79
 
80
80
  Fires when a user's server voice mute is disabled.
81
81
 
82
- | Parameter | Type | Description |
83
- | --- | --- | --- |
84
- | `state` | {Discorb::VoiceState} | The voice state. |
82
+ | Parameter | Type | Description |
83
+ | --------- | --------------------- | ---------------- |
84
+ | `state` | {Discorb::VoiceState} | The voice state. |
85
85
 
86
86
  #### `voice_server_mute_update(before, after)`
87
87
 
88
88
  Fires when a user's server voice mute is enabled or disabled.
89
89
 
90
- | Parameter | Type | Description |
91
- | --- | --- | --- |
92
- | `before` | {Discorb::VoiceState} | The voice state before the update. |
93
- | `after` | {Discorb::VoiceState} | The voice state after the update. |
90
+ | Parameter | Type | Description |
91
+ | --------- | --------------------- | ---------------------------------- |
92
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
93
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
94
94
 
95
95
  #### `voice_self_mute_enable(state)`
96
96
 
97
97
  Fires when a user's self voice mute is enabled.
98
98
 
99
- | Parameter | Type | Description |
100
- | --- | --- | --- |
101
- | `state` | {Discorb::VoiceState} | The voice state. |
99
+ | Parameter | Type | Description |
100
+ | --------- | --------------------- | ---------------- |
101
+ | `state` | {Discorb::VoiceState} | The voice state. |
102
102
 
103
103
  #### `voice_self_mute_disable(state)`
104
104
 
105
105
  Fires when a user's self voice mute is disabled.
106
106
 
107
- | Parameter | Type | Description |
108
- | --- | --- | --- |
109
- | `state` | {Discorb::VoiceState} | The voice state. |
107
+ | Parameter | Type | Description |
108
+ | --------- | --------------------- | ---------------- |
109
+ | `state` | {Discorb::VoiceState} | The voice state. |
110
110
 
111
111
  #### `voice_self_mute_update(before, after)`
112
112
 
113
113
  Fires when a user's self voice mute is enabled or disabled.
114
114
 
115
- | Parameter | Type | Description |
116
- | --- | --- | --- |
117
- | `before` | {Discorb::VoiceState} | The voice state before the update. |
118
- | `after` | {Discorb::VoiceState} | The voice state after the update. |
115
+ | Parameter | Type | Description |
116
+ | --------- | --------------------- | ---------------------------------- |
117
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
118
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
119
119
 
120
120
  ### Deaf Events
121
121
 
@@ -123,74 +123,74 @@ Fires when a user's self voice mute is enabled or disabled.
123
123
 
124
124
  Fires when a user's voice deaf is enabled.
125
125
 
126
- | Parameter | Type | Description |
127
- | --- | --- | --- |
128
- | `state` | {Discorb::VoiceState} | The voice state. |
126
+ | Parameter | Type | Description |
127
+ | --------- | --------------------- | ---------------- |
128
+ | `state` | {Discorb::VoiceState} | The voice state. |
129
129
 
130
130
  #### `voice_deaf_disable(state)`
131
131
 
132
132
  Fires when a user's voice deaf is disabled.
133
133
 
134
- | Parameter | Type | Description |
135
- | --- | --- | --- |
136
- | `state` | {Discorb::VoiceState} | The voice state. |
134
+ | Parameter | Type | Description |
135
+ | --------- | --------------------- | ---------------- |
136
+ | `state` | {Discorb::VoiceState} | The voice state. |
137
137
 
138
138
  #### `voice_deaf_update(before, after)`
139
139
 
140
140
  Fires when a user's voice deaf is enabled or disabled.
141
141
 
142
- | Parameter | Type | Description |
143
- | --- | --- | --- |
144
- | `before` | {Discorb::VoiceState} | The voice state before the update. |
145
- | `after` | {Discorb::VoiceState} | The voice state after the update. |
142
+ | Parameter | Type | Description |
143
+ | --------- | --------------------- | ---------------------------------- |
144
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
145
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
146
146
 
147
147
  #### `voice_server_deaf_enable(state)`
148
148
 
149
149
  Fires when a user's server voice deaf is enabled.
150
150
 
151
- | Parameter | Type | Description |
152
- | --- | --- | --- |
153
- | `state` | {Discorb::VoiceState} | The voice state. |
151
+ | Parameter | Type | Description |
152
+ | --------- | --------------------- | ---------------- |
153
+ | `state` | {Discorb::VoiceState} | The voice state. |
154
154
 
155
155
  #### `voice_server_deaf_disable(state)`
156
156
 
157
157
  Fires when a user's server voice deaf is disabled.
158
158
 
159
- | Parameter | Type | Description |
160
- | --- | --- | --- |
161
- | `state` | {Discorb::VoiceState} | The voice state. |
159
+ | Parameter | Type | Description |
160
+ | --------- | --------------------- | ---------------- |
161
+ | `state` | {Discorb::VoiceState} | The voice state. |
162
162
 
163
163
  #### `voice_server_deaf_update(before, after)`
164
164
 
165
165
  Fires when a user's server voice deaf is enabled or disabled.
166
166
 
167
- | Parameter | Type | Description |
168
- | --- | --- | --- |
169
- | `before` | {Discorb::VoiceState} | The voice state before the update. |
170
- | `after` | {Discorb::VoiceState} | The voice state after the update. |
167
+ | Parameter | Type | Description |
168
+ | --------- | --------------------- | ---------------------------------- |
169
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
170
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
171
171
 
172
172
  #### `voice_self_deaf_enable(state)`
173
173
 
174
174
  Fires when a user's self voice deaf is enabled.
175
175
 
176
- | Parameter | Type | Description |
177
- | --- | --- | --- |
178
- | `state` | {Discorb::VoiceState} | The voice state. |
176
+ | Parameter | Type | Description |
177
+ | --------- | --------------------- | ---------------- |
178
+ | `state` | {Discorb::VoiceState} | The voice state. |
179
179
 
180
180
  #### `voice_self_deaf_disable(state)`
181
181
 
182
182
  Fires when a user's self voice deaf is disabled.
183
183
 
184
- | Parameter | Type | Description |
185
- | --- | --- | --- |
186
- | `state` | {Discorb::VoiceState} | The voice state. |
184
+ | Parameter | Type | Description |
185
+ | --------- | --------------------- | ---------------- |
186
+ | `state` | {Discorb::VoiceState} | The voice state. |
187
187
 
188
188
  #### `voice_self_deaf_update(before, after)`
189
189
 
190
- | Parameter | Type | Description |
191
- | --- | --- | --- |
192
- | `before` | {Discorb::VoiceState} | The voice state before the update. |
193
- | `after` | {Discorb::VoiceState} | The voice state after the update. |
190
+ | Parameter | Type | Description |
191
+ | --------- | --------------------- | ---------------------------------- |
192
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
193
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
194
194
 
195
195
  ### Stream Events
196
196
 
@@ -198,26 +198,26 @@ Fires when a user's self voice deaf is disabled.
198
198
 
199
199
  Fires when a stream is started.
200
200
 
201
- | Parameter | Type | Description |
202
- | --- | --- | --- |
203
- | `state` | {Discorb::VoiceState} | The voice state. |
201
+ | Parameter | Type | Description |
202
+ | --------- | --------------------- | ---------------- |
203
+ | `state` | {Discorb::VoiceState} | The voice state. |
204
204
 
205
205
  #### `voice_stream_end(state)`
206
206
 
207
207
  Fires when a stream is ended.
208
208
 
209
- | Parameter | Type | Description |
210
- | --- | --- | --- |
211
- | `state` | {Discorb::VoiceState} | The voice state. |
209
+ | Parameter | Type | Description |
210
+ | --------- | --------------------- | ---------------- |
211
+ | `state` | {Discorb::VoiceState} | The voice state. |
212
212
 
213
213
  #### `voice_stream_update(before, after)`
214
214
 
215
215
  Fires when a stream is started or ended.
216
216
 
217
- | Parameter | Type | Description |
218
- | --- | --- | --- |
219
- | `before` | {Discorb::VoiceState} | The voice state before the update. |
220
- | `after` | {Discorb::VoiceState} | The voice state after the update. |
217
+ | Parameter | Type | Description |
218
+ | --------- | --------------------- | ---------------------------------- |
219
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
220
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
221
221
 
222
222
  ### Video Events
223
223
 
@@ -225,26 +225,26 @@ Fires when a stream is started or ended.
225
225
 
226
226
  Fires when a video is started.
227
227
 
228
- | Parameter | Type | Description |
229
- | --- | --- | --- |
230
- | `state` | {Discorb::VoiceState} | The voice state. |
228
+ | Parameter | Type | Description |
229
+ | --------- | --------------------- | ---------------- |
230
+ | `state` | {Discorb::VoiceState} | The voice state. |
231
231
 
232
232
  #### `voice_video_end(state)`
233
233
 
234
234
  Fires when a video is ended.
235
235
 
236
- | Parameter | Type | Description |
237
- | --- | --- | --- |
238
- | `state` | {Discorb::VoiceState} | The voice state. |
236
+ | Parameter | Type | Description |
237
+ | --------- | --------------------- | ---------------- |
238
+ | `state` | {Discorb::VoiceState} | The voice state. |
239
239
 
240
240
  #### `voice_video_update(before, after)`
241
241
 
242
242
  Fires when a video is started or ended.
243
243
 
244
- | Parameter | Type | Description |
245
- | --- | --- | --- |
246
- | `before` | {Discorb::VoiceState} | The voice state before the update. |
247
- | `after` | {Discorb::VoiceState} | The voice state after the update. |
244
+ | Parameter | Type | Description |
245
+ | --------- | --------------------- | ---------------------------------- |
246
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
247
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
248
248
 
249
249
  ### Stage Instances Events
250
250
 
@@ -252,26 +252,26 @@ Fires when a video is started or ended.
252
252
 
253
253
  Fires when a new stage instance is created.
254
254
 
255
- | Parameter | Type | Description |
256
- | --- | --- | --- |
255
+ | Parameter | Type | Description |
256
+ | ---------- | ------------------------ | --------------------- |
257
257
  | `instance` | {Discorb::StageInstance} | The created instance. |
258
258
 
259
259
  #### `stage_instance_delete(instance)`
260
260
 
261
261
  Fires when a stage instance is deleted.
262
262
 
263
- | Parameter | Type | Description |
264
- | --- | --- | --- |
263
+ | Parameter | Type | Description |
264
+ | ---------- | ------------------------ | --------------------- |
265
265
  | `instance` | {Discorb::StageInstance} | The deleted instance. |
266
266
 
267
267
  #### `stage_instance_update(before, after)`
268
268
 
269
269
  Fires when a stage instance is updated.
270
270
 
271
- | Parameter | Type | Description |
272
- | --- | --- | --- |
273
- | `before` | {Discorb::StageInstance} | The instance before the update. |
274
- | `after` | {Discorb::StageInstance} | The instance after the update. |
271
+ | Parameter | Type | Description |
272
+ | --------- | ------------------------ | ------------------------------- |
273
+ | `before` | {Discorb::StageInstance} | The instance before the update. |
274
+ | `after` | {Discorb::StageInstance} | The instance after the update. |
275
275
 
276
276
  ### Misc Events
277
277
 
@@ -279,7 +279,7 @@ Fires when a stage instance is updated.
279
279
 
280
280
  Fired when a user changes voice state.
281
281
 
282
- | Parameter | Type | Description |
283
- | --- | --- | --- |
284
- | before | {Discorb::VoiceState} | The voice state before the update. |
285
- | after | {Discorb::VoiceState} | The voice state after the update. |
282
+ | Parameter | Type | Description |
283
+ | --------- | --------------------- | ---------------------------------- |
284
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
285
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "discorb"
4
+ require "json"
5
+
6
+ localizations = {
7
+ context_command: {
8
+ not_found: {
9
+ en: "Bookmark channel not found. Please create one called `bookmarks`.",
10
+ ja: "ブックマークチャンネルが見付かりませんでした。`bookmarks`という名前のチャンネルを作成してください。",
11
+ },
12
+ done: {
13
+ en: "Bookmark added.",
14
+ ja: "ブックマークを追加しました。",
15
+ },
16
+ },
17
+ }
18
+
19
+ client = Discorb::Client.new
20
+
21
+ client.once :standby do
22
+ puts "Logged in as #{client.user}"
23
+ end
24
+
25
+ def bookmark_channel(guild)
26
+ guild.text_channels.find { |c| c.name == "bookmarks" }
27
+ end
28
+
29
+ def build_embed_from_message(message)
30
+ embed = Discorb::Embed.new
31
+ embed.description = message.content
32
+ embed.author = Discorb::Embed::Author.new(message.author.to_s, icon: message.author.avatar.url)
33
+ embed.timestamp = message.timestamp
34
+ embed.footer = Discorb::Embed::Footer.new("ID: #{message.id}")
35
+ embed
36
+ end
37
+
38
+ client.message_command({
39
+ default: "Bookmark",
40
+ ja: "ブックマーク",
41
+ }) do |interaction, message|
42
+ next unless interaction.guild
43
+
44
+ unless channel = bookmark_channel(interaction.guild)
45
+ interaction.post(
46
+ localizations[:context_command][:not_found][interaction.locale] ||
47
+ localizations[:context_command][:not_found][:en],
48
+ ephemeral: true,
49
+ )
50
+ next
51
+ end
52
+ channel.post(
53
+ message.jump_url,
54
+ embed: build_embed_from_message(message),
55
+ ).wait
56
+ interaction.post(
57
+ localizations[:context_command][:done][interaction.locale] || localizations[:context_command][:done][:en],
58
+ ephemeral: true,
59
+ )
60
+ end
61
+
62
+ client.change_presence(
63
+ Discorb::Activity.new(
64
+ "Open message context menu to bookmark"
65
+ )
66
+ )
67
+
68
+ client.run(ENV.fetch("DISCORD_BOT_TOKEN", nil))
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "discorb"
4
+
5
+ client = Discorb::Client.new
6
+
7
+ client.once :standby do
8
+ puts "Logged in as #{client.user}"
9
+ end
10
+
11
+ client.slash(
12
+ "admin", "You can run this command if you have Administrator permission",
13
+ dm_permission: false,
14
+ default_permission: Discorb::Permission.from_keys(:administrator),
15
+ ) do |interaction, _name|
16
+ interaction.post("Hello, admin!")
17
+ end
18
+
19
+ client.run(ENV.fetch("DISCORD_BOT_TOKEN", nil))
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "discorb"
4
+
5
+ client = Discorb::Client.new
6
+
7
+ localizations = {
8
+ localized: {
9
+ text: {
10
+ en: "Hello, %s!",
11
+ ja: "%sさん、こんにちは!",
12
+ },
13
+ },
14
+ }
15
+
16
+ client.once :standby do
17
+ puts "Logged in as #{client.user}"
18
+ end
19
+
20
+ client.slash(
21
+ {
22
+ default: "greet",
23
+ ja: "挨拶",
24
+ }, {
25
+ default: "Bot greets. Cute OwO",
26
+ ja: "Botが挨拶します。かわいいね",
27
+ }, {
28
+ "name" => {
29
+ name_localizations: {
30
+ ja: "名前",
31
+ },
32
+ description: {
33
+ default: "The name to greet.",
34
+ ja: "挨拶する人の名前。",
35
+ },
36
+ type: :string,
37
+ optional: true,
38
+ },
39
+ }
40
+ ) do |interaction, name|
41
+ interaction.post(
42
+ format((localizations[:localized][:text][interaction.locale] || localizations[:localized][:text][:en]),
43
+ name || interaction.user.to_s),
44
+ ephemeral: true,
45
+ )
46
+ end
47
+
48
+ client.run(ENV.fetch("DISCORD_BOT_TOKEN", nil))
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "discorb"
4
+
5
+ localizations = {
6
+ info: {
7
+ title: {
8
+ en: "%s's info",
9
+ ja: "%sの詳細",
10
+ },
11
+ fields: {
12
+ en: ["Name", "ID", "Bot", "Joined at", "Account created at"],
13
+ ja: %w[名前 ID ボット 参加日時 アカウント作成日時],
14
+ },
15
+ yn: {
16
+ en: %w[Yes No],
17
+ ja: %w[はい いいえ],
18
+ },
19
+ },
20
+ }
21
+
22
+ client = Discorb::Client.new
23
+
24
+ client.once :standby do
25
+ puts "Logged in as #{client.user}"
26
+ end
27
+
28
+ client.user_command(
29
+ {
30
+ default: "info",
31
+ ja: "詳細",
32
+ }
33
+ ) do |interaction, user|
34
+ field_name = localizations[:info][:fields][interaction.locale] || localizations[:info][:fields][:en]
35
+ interaction.post(
36
+ embed: Discorb::Embed.new(
37
+ format((localizations[:info][:title][interaction.locale] || localizations[:info][:title][:en]),
38
+ user.to_s),
39
+ fields: [
40
+ Discorb::Embed::Field.new(field_name[0], user.to_s),
41
+ Discorb::Embed::Field.new(field_name[1], user.id),
42
+ Discorb::Embed::Field.new(
43
+ field_name[2],
44
+ (localizations[:info][:yn][locale] || localizations[:info][:yn][:en])[user.bot? ? 0 : 1]
45
+ ),
46
+ Discorb::Embed::Field.new(field_name[3], user.joined_at.to_df("F")),
47
+ Discorb::Embed::Field.new(field_name[4], user.created_at.to_df("F")),
48
+ ],
49
+ thumbnail: user.avatar&.url,
50
+ ), ephemeral: true,
51
+ )
52
+ end
53
+
54
+ client.run(ENV.fetch("DISCORD_BOT_TOKEN", nil))