discorb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +56 -0
  3. data/.yardopts +6 -0
  4. data/Changelog.md +5 -0
  5. data/Gemfile +23 -0
  6. data/Gemfile.lock +70 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +53 -0
  9. data/Rakefile +46 -0
  10. data/bin/console +15 -0
  11. data/bin/setup +8 -0
  12. data/discorb.gemspec +37 -0
  13. data/docs/Examples.md +26 -0
  14. data/docs/events.md +480 -0
  15. data/docs/voice_events.md +283 -0
  16. data/examples/components/authorization_button.rb +43 -0
  17. data/examples/components/select_menu.rb +61 -0
  18. data/examples/extension/main.rb +12 -0
  19. data/examples/extension/message_expander.rb +41 -0
  20. data/examples/simple/eval.rb +32 -0
  21. data/examples/simple/ping_pong.rb +16 -0
  22. data/examples/simple/rolepanel.rb +65 -0
  23. data/examples/simple/wait_for_message.rb +30 -0
  24. data/lib/discorb/application.rb +157 -0
  25. data/lib/discorb/asset.rb +57 -0
  26. data/lib/discorb/audit_logs.rb +323 -0
  27. data/lib/discorb/channel.rb +1101 -0
  28. data/lib/discorb/client.rb +363 -0
  29. data/lib/discorb/color.rb +173 -0
  30. data/lib/discorb/common.rb +123 -0
  31. data/lib/discorb/components.rb +290 -0
  32. data/lib/discorb/dictionary.rb +119 -0
  33. data/lib/discorb/embed.rb +345 -0
  34. data/lib/discorb/emoji.rb +218 -0
  35. data/lib/discorb/emoji_table.rb +3799 -0
  36. data/lib/discorb/error.rb +98 -0
  37. data/lib/discorb/event.rb +35 -0
  38. data/lib/discorb/extend.rb +18 -0
  39. data/lib/discorb/extension.rb +54 -0
  40. data/lib/discorb/file.rb +69 -0
  41. data/lib/discorb/flag.rb +109 -0
  42. data/lib/discorb/gateway.rb +967 -0
  43. data/lib/discorb/gateway_requests.rb +47 -0
  44. data/lib/discorb/guild.rb +1244 -0
  45. data/lib/discorb/guild_template.rb +211 -0
  46. data/lib/discorb/image.rb +43 -0
  47. data/lib/discorb/integration.rb +111 -0
  48. data/lib/discorb/intents.rb +137 -0
  49. data/lib/discorb/interaction.rb +333 -0
  50. data/lib/discorb/internet.rb +285 -0
  51. data/lib/discorb/invite.rb +145 -0
  52. data/lib/discorb/log.rb +70 -0
  53. data/lib/discorb/member.rb +232 -0
  54. data/lib/discorb/message.rb +583 -0
  55. data/lib/discorb/modules.rb +138 -0
  56. data/lib/discorb/permission.rb +270 -0
  57. data/lib/discorb/presence.rb +308 -0
  58. data/lib/discorb/reaction.rb +48 -0
  59. data/lib/discorb/role.rb +189 -0
  60. data/lib/discorb/sticker.rb +157 -0
  61. data/lib/discorb/user.rb +163 -0
  62. data/lib/discorb/utils.rb +16 -0
  63. data/lib/discorb/voice_state.rb +251 -0
  64. data/lib/discorb/webhook.rb +420 -0
  65. data/lib/discorb.rb +51 -0
  66. metadata +120 -0
@@ -0,0 +1,283 @@
1
+ # @title Voice Events
2
+
3
+ # Voice Events
4
+
5
+ ### Voice Channel Events
6
+
7
+ #### `voice_channel_connect(task, state)`
8
+
9
+ Fires when someone joins a voice channel.
10
+
11
+ | Parameter | Type | Description |
12
+ | --- | --- | --- |
13
+ | state | {Discorb::VoiceState} | The voice state of the user that joined. |
14
+
15
+ #### `voice_channel_disconnect(task, state)`
16
+
17
+ Fires when someone leaves a voice channel.
18
+
19
+ | Parameter | Type | Description |
20
+ | --- | --- | --- |
21
+ | state | {Discorb::VoiceState} | The voice state of the user that left. |
22
+
23
+ #### `voice_channel_move(task, before, after)`
24
+
25
+ Fires when someone moves to a different voice channel.
26
+
27
+ | Parameter | Type | Description |
28
+ | --- | --- | --- |
29
+ | before | {Discorb::VoiceState} | The voice state of the user before the move. |
30
+ | after | {Discorb::VoiceState} | The voice state of the user after the move. |
31
+
32
+ #### `voice_channel_update(task, before, after)`
33
+
34
+ Fires when a voice channel is connected, disconnected, or updated.
35
+
36
+ | Parameter | Type | Description |
37
+ | --- | --- | --- |
38
+ | before | {Discorb::VoiceState} | The voice state before the update. |
39
+ | after | {Discorb::VoiceState} | The voice state after the update. |
40
+
41
+ ### Mute Events
42
+
43
+ #### `voice_mute_disable(task, state)`
44
+
45
+ Fires when a user's voice mute is disabled.
46
+
47
+ | Parameter | Type | Description |
48
+ | --- | --- | --- |
49
+ | `state` | {Discorb::VoiceState} | The voice state. |
50
+
51
+ #### `voice_mute_enable(task, state)`
52
+
53
+ Fires when a user's voice mute is enabled.
54
+
55
+ | Parameter | Type | Description |
56
+ | --- | --- | --- |
57
+ | `state` | {Discorb::VoiceState} | The voice state. |
58
+
59
+ #### `voice_mute_update(task, before, after)`
60
+
61
+ Fires when a user's voice mute is enabled or disabled.
62
+
63
+ | Parameter | Type | Description |
64
+ | --- | --- | --- |
65
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
66
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
67
+
68
+ #### `voice_server_mute_enable(task, state)`
69
+
70
+ Fires when a user's server voice mute is enabled.
71
+
72
+ | Parameter | Type | Description |
73
+ | --- | --- | --- |
74
+ | `state` | {Discorb::VoiceState} | The voice state. |
75
+
76
+ #### `voice_server_mute_disable(task, state)`
77
+
78
+ Fires when a user's server voice mute is disabled.
79
+
80
+ | Parameter | Type | Description |
81
+ | --- | --- | --- |
82
+ | `state` | {Discorb::VoiceState} | The voice state. |
83
+
84
+ #### `voice_server_mute_update(task, before, after)`
85
+
86
+ Fires when a user's server voice mute is enabled or disabled.
87
+
88
+ | Parameter | Type | Description |
89
+ | --- | --- | --- |
90
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
91
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
92
+
93
+ #### `voice_self_mute_enable(task, state)`
94
+
95
+ Fires when a user's self voice mute is enabled.
96
+
97
+ | Parameter | Type | Description |
98
+ | --- | --- | --- |
99
+ | `state` | {Discorb::VoiceState} | The voice state. |
100
+
101
+ #### `voice_self_mute_disable(task, state)`
102
+
103
+ Fires when a user's self voice mute is disabled.
104
+
105
+ | Parameter | Type | Description |
106
+ | --- | --- | --- |
107
+ | `state` | {Discorb::VoiceState} | The voice state. |
108
+
109
+ #### `voice_self_mute_update(task, before, after)`
110
+
111
+ Fires when a user's self voice mute is enabled or disabled.
112
+
113
+ | Parameter | Type | Description |
114
+ | --- | --- | --- |
115
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
116
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
117
+
118
+ ### Deaf Events
119
+
120
+ #### `voice_deaf_enable(task, state)`
121
+
122
+ Fires when a user's voice deaf is enabled.
123
+
124
+ | Parameter | Type | Description |
125
+ | --- | --- | --- |
126
+ | `state` | {Discorb::VoiceState} | The voice state. |
127
+
128
+ #### `voice_deaf_disable(task, state)`
129
+
130
+ Fires when a user's voice deaf is disabled.
131
+
132
+ | Parameter | Type | Description |
133
+ | --- | --- | --- |
134
+ | `state` | {Discorb::VoiceState} | The voice state. |
135
+
136
+ #### `voice_deaf_update(task, before, after)`
137
+
138
+ Fires when a user's voice deaf is enabled or disabled.
139
+
140
+ | Parameter | Type | Description |
141
+ | --- | --- | --- |
142
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
143
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
144
+
145
+ #### `voice_server_deaf_enable(task, state)`
146
+
147
+ Fires when a user's server voice deaf is enabled.
148
+
149
+ | Parameter | Type | Description |
150
+ | --- | --- | --- |
151
+ | `state` | {Discorb::VoiceState} | The voice state. |
152
+
153
+ #### `voice_server_deaf_disable(task, state)`
154
+
155
+ Fires when a user's server voice deaf is disabled.
156
+
157
+ | Parameter | Type | Description |
158
+ | --- | --- | --- |
159
+ | `state` | {Discorb::VoiceState} | The voice state. |
160
+
161
+ #### `voice_server_deaf_update(task, before, after)`
162
+
163
+ Fires when a user's server voice deaf is enabled or disabled.
164
+
165
+ | Parameter | Type | Description |
166
+ | --- | --- | --- |
167
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
168
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
169
+
170
+ #### `voice_self_deaf_enable(task, state)`
171
+
172
+ Fires when a user's self voice deaf is enabled.
173
+
174
+ | Parameter | Type | Description |
175
+ | --- | --- | --- |
176
+ | `state` | {Discorb::VoiceState} | The voice state. |
177
+
178
+ #### `voice_self_deaf_disable(task, state)`
179
+
180
+ Fires when a user's self voice deaf is disabled.
181
+
182
+ | Parameter | Type | Description |
183
+ | --- | --- | --- |
184
+ | `state` | {Discorb::VoiceState} | The voice state. |
185
+
186
+ #### `voice_self_deaf_update(task, before, after)`
187
+
188
+ | Parameter | Type | Description |
189
+ | --- | --- | --- |
190
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
191
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
192
+
193
+ ### Stream Events
194
+
195
+ #### `voice_stream_start(task, state)`
196
+
197
+ Fires when a stream is started.
198
+
199
+ | Parameter | Type | Description |
200
+ | --- | --- | --- |
201
+ | `state` | {Discorb::VoiceState} | The voice state. |
202
+
203
+ #### `voice_stream_end(task, state)`
204
+
205
+ Fires when a stream is ended.
206
+
207
+ | Parameter | Type | Description |
208
+ | --- | --- | --- |
209
+ | `state` | {Discorb::VoiceState} | The voice state. |
210
+
211
+ #### `voice_stream_update(task, before, after)`
212
+
213
+ Fires when a stream is started or ended.
214
+
215
+ | Parameter | Type | Description |
216
+ | --- | --- | --- |
217
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
218
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
219
+
220
+ ### Video Events
221
+
222
+ #### `voice_video_start(task, state)`
223
+
224
+ Fires when a video is started.
225
+
226
+ | Parameter | Type | Description |
227
+ | --- | --- | --- |
228
+ | `state` | {Discorb::VoiceState} | The voice state. |
229
+
230
+ #### `voice_video_end(task, state)`
231
+
232
+ Fires when a video is ended.
233
+
234
+ | Parameter | Type | Description |
235
+ | --- | --- | --- |
236
+ | `state` | {Discorb::VoiceState} | The voice state. |
237
+
238
+ #### `voice_video_update(task, before, after)`
239
+
240
+ Fires when a video is started or ended.
241
+
242
+ | Parameter | Type | Description |
243
+ | --- | --- | --- |
244
+ | `before` | {Discorb::VoiceState} | The voice state before the update. |
245
+ | `after` | {Discorb::VoiceState} | The voice state after the update. |
246
+
247
+ ### Stage Instances Events
248
+
249
+ #### `stage_instance_create(task, instance)`
250
+
251
+ Fires when a new stage instance is created.
252
+
253
+ | Parameter | Type | Description |
254
+ | --- | --- | --- |
255
+ | `instance` | {Discorb::StageInstance} | The created instance. |
256
+
257
+ #### `stage_instance_delete(task, instance)`
258
+
259
+ Fires when a stage instance is deleted.
260
+
261
+ | Parameter | Type | Description |
262
+ | --- | --- | --- |
263
+ | `instance` | {Discorb::StageInstance} | The deleted instance. |
264
+
265
+ #### `stage_instance_update(task, before, after)`
266
+
267
+ Fires when a stage instance is updated.
268
+
269
+ | Parameter | Type | Description |
270
+ | --- | --- | --- |
271
+ | `before` | {Discorb::StageInstance} | The instance before the update. |
272
+ | `after` | {Discorb::StageInstance} | The instance after the update. |
273
+
274
+ ### Misc Events
275
+
276
+ #### `voice_state_update(task, before, after)`
277
+
278
+ Fired when a user changes voice state.
279
+
280
+ | Parameter | Type | Description |
281
+ | --- | --- | --- |
282
+ | before | {Discorb::VoiceState} | The voice state before the update. |
283
+ | after | {Discorb::VoiceState} | The voice state after the update. |
@@ -0,0 +1,43 @@
1
+ require "discorb"
2
+
3
+ client = Discorb::Client.new
4
+
5
+ def convert_role(guild, string)
6
+ guild.roles.find do |role|
7
+ role.id == string || role.name == string || role.mention == string
8
+ end
9
+ end
10
+
11
+ client.once :ready do
12
+ puts "Logged in as #{client.user}"
13
+ end
14
+
15
+ client.on :message do |_task, message|
16
+ next if message.author.bot?
17
+ next unless message.content.start_with?("!auth ")
18
+
19
+ role_name = message.content.delete_prefix("!auth ")
20
+ role = convert_role(message.guild, role_name)
21
+ if role.nil?
22
+ message.reply("Unknown role: #{role_name}").wait
23
+ next
24
+ end
25
+ message.channel.post(
26
+ "Click this button if you are human:",
27
+ components: [
28
+ Discorb::Button.new(
29
+ "Get role", custom_id: "auth:#{role.id}",
30
+ ),
31
+ ],
32
+ )
33
+ end
34
+
35
+ client.on :button_click do |_task, response|
36
+ if response.custom_id.start_with?("auth:")
37
+ id = response.custom_id.delete_prefix("auth:")
38
+ response.fired_by.add_role(id).wait
39
+ response.post("You got your role!\nHere's your role: <@&#{id}>", hide: true)
40
+ end
41
+ end
42
+
43
+ client.run(ENV["DISCORD_BOT_TOKEN"])
@@ -0,0 +1,61 @@
1
+ require "discorb"
2
+
3
+ client = Discorb::Client.new
4
+
5
+ SECTIONS = [
6
+ ["About", <<~WIKI],
7
+ Ruby is an interpreted, high-level, general-purpose programming language.
8
+ It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.\n\n
9
+ Ruby is dynamically typed and uses garbage collection and just-in-time compilation.
10
+ It supports multiple programming paradigms, including procedural, object-oriented, and functional programming.
11
+ According to the creator, Ruby was influenced by Perl, Smalltalk, Eiffel, Ada, BASIC, and Lisp.
12
+ WIKI
13
+ ["Early concept", <<~WIKI],
14
+ Matsumoto has said that Ruby was conceived in 1993.
15
+ In a 1999 post to the ruby-talk mailing list, he describes some of his early ideas about the language:
16
+ > I was talking with my colleague about the possibility of an object-oriented scripting language.
17
+ > I knew Perl (Perl4, not Perl5), but I didn't like it really, because it had the smell of a toy language (it still has).
18
+ > The object-oriented language seemed very promising. I knew Python then.
19
+ > But I didn't like it, because I didn't think it was a true object-oriented language - OO features appeared to be add-on to the language.
20
+ > As a language maniac and OO fan for 15 years, I really wanted a genuine object-oriented, easy-to-use scripting language. I looked for but couldn't find one.
21
+ > So I decided to make it.
22
+ Matsumoto describes the design of Ruby as being like a simple Lisp language at its core, with an object system like that of Smalltalk, blocks inspired by higher-order functions, and practical utility like that of Perl.
23
+ WIKI
24
+ ["First publication", <<~WIKI],
25
+ The first public release of Ruby 0.95 was announced on Japanese domestic newsgroups on December 21, 1995.
26
+ Subsequently, three more versions of Ruby were released in two days.
27
+ The release coincided with the launch of the Japanese-language ruby-list mailing list, which was the first mailing list for the new language.
28
+
29
+ Already present at this stage of development were many of the features familiar in later releases of Ruby, including object-oriented design, classes with inheritance, mixins, iterators, closures, exception handling and garbage collection.
30
+ WIKI
31
+ ].freeze
32
+
33
+ WIKIPEDIA_CREDIT = "(From: [Wikipedia](https://en.wikipedia.org/wiki/Ruby_(programming_language)))"
34
+
35
+ client.once :ready do
36
+ puts "Logged in as #{client.user}"
37
+ end
38
+
39
+ client.on :message do |_task, message|
40
+ next if message.author.bot?
41
+ next unless message.content == "!ruby"
42
+
43
+ options = SECTIONS.map.with_index { |section, i| Discorb::SelectMenu::Option.new("Page #{i + 1}", "sections:#{i}", description: section[0]) }
44
+ message.channel.post(
45
+ "Select a section", components: [Discorb::SelectMenu.new("sections", options)],
46
+ )
47
+ end
48
+
49
+ client.on :select_menu_select do |_task, response|
50
+ next unless response.custom_id == "sections"
51
+
52
+ id = response.value.delete_prefix("sections:")
53
+ selected_section = SECTIONS[id.to_i]
54
+ response.post(
55
+ "**#{selected_section[0]}**\n" \
56
+ "#{selected_section[1].strip}\n\n" \
57
+ "#{WIKIPEDIA_CREDIT}", hide: true,
58
+ )
59
+ end
60
+
61
+ client.run(ENV["DISCORD_BOT_TOKEN"])
@@ -0,0 +1,12 @@
1
+ require "discorb"
2
+ require_relative "message_expander"
3
+
4
+ client = Discorb::Client.new
5
+
6
+ client.once :ready do
7
+ puts "Logged in as #{client.user}"
8
+ end
9
+
10
+ client.extend(MessageExpander)
11
+
12
+ client.run(ENV["DISCORD_BOT_TOKEN"])
@@ -0,0 +1,41 @@
1
+ require "discorb"
2
+
3
+ module MessageExpander
4
+ extend Discorb::Extension
5
+
6
+ @message_regex = Regexp.new(
7
+ '(?!<)https://(?:ptb\.|canary\.)?discord(?:app)?\.com/channels/' \
8
+ "(?<guild>[0-9]{18})/(?<channel>[0-9]{18})/(?<message>[0-9]{18})(?!>)"
9
+ )
10
+
11
+ event :message do |_task, message|
12
+ next if message.author.bot?
13
+
14
+ message.content.to_enum(:scan, @message_regex).map { Regexp.last_match }.each do |match|
15
+ ch = @client.channels[match[:channel]]
16
+ next if ch.nil?
17
+
18
+ begin
19
+ url_message = ch.fetch_message(match[:message]).wait
20
+ rescue Discorb::NotFoundError
21
+ url_message.add_reaction(Discorb::UnicodeEmoji["x"])
22
+ else
23
+ embed = Discorb::Embed.new(
24
+ nil, url_message.content,
25
+ color: Discorb::Color[:blurple],
26
+ timestamp: url_message.created_at,
27
+ author: Discorb::Embed::Author.new(
28
+ url_message.author.name,
29
+ url: url_message.jump_url,
30
+ icon: url_message.author.display_avatar.url,
31
+ ),
32
+ footer: Discorb::Embed::Footer.new(
33
+ "#{url_message.guild.name} / #{ch.name}",
34
+ icon: url_message.guild.icon&.url,
35
+ ),
36
+ )
37
+ message.reply embed: embed
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,32 @@
1
+ require "discorb"
2
+
3
+ client = Discorb::Client.new
4
+
5
+ client.once :ready do |_task|
6
+ puts "Logged in as #{client.user}"
7
+ end
8
+
9
+ client.on :message do |_task, message|
10
+ next if message.author.bot?
11
+ next unless message.content.start_with?("eval ")
12
+
13
+ unless message.author.bot_owner?.wait
14
+ message.reply("You don't have permission to use this command.")
15
+ next
16
+ end
17
+
18
+ code = message.content.delete_prefix("eval ").delete_prefix("```rb").delete_suffix("```")
19
+ message.add_reaction(Discorb::UnicodeEmoji["clock3"])
20
+ res = eval("Async { |task| #{code} }.wait", binding, __FILE__, __LINE__) # rubocop:disable Security/Eval
21
+ message.remove_reaction(Discorb::UnicodeEmoji["clock3"])
22
+ message.add_reaction(Discorb::UnicodeEmoji["white_check_mark"])
23
+ unless res.nil?
24
+ res = res.wait if res.is_a? Async::Task
25
+ message.channel.post("```rb\n#{res.inspect[...1990]}\n```")
26
+ end
27
+ rescue Exception => error
28
+ message.reply embed: Discorb::Embed.new("Error!", "```rb\n#{error.full_message(highlight: false)[...1990]}\n```",
29
+ color: Discorb::Color[:red])
30
+ end
31
+
32
+ client.run(ENV["discord_bot_token"])