discorb 0.15.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +1 -0
- data/.github/workflows/build_main.yml +2 -2
- data/.github/workflows/build_version.yml +1 -1
- data/.github/workflows/codeql-analysis.yml +1 -1
- data/.github/workflows/lint-push.yml +3 -5
- data/.github/workflows/lint.yml +1 -1
- data/.github/workflows/spec.yml +30 -0
- data/.lefthook/commit-msg/validator.rb +5 -0
- data/.rspec +2 -0
- data/.rspec_parallel +2 -0
- data/.rubocop.yml +49 -8
- data/Changelog.md +32 -1
- data/Gemfile +14 -8
- data/Rakefile +46 -25
- data/bin/console +3 -3
- data/docs/Examples.md +1 -1
- data/docs/application_command.md +138 -46
- data/docs/cli/irb.md +2 -2
- data/docs/cli/new.md +14 -9
- data/docs/cli/run.md +7 -11
- data/docs/cli.md +17 -10
- data/docs/events.md +257 -193
- data/docs/extension.md +1 -2
- data/docs/faq.md +0 -1
- data/docs/tutorial.md +12 -12
- data/docs/voice_events.md +106 -106
- data/examples/commands/message.rb +63 -0
- data/examples/commands/permission.rb +18 -0
- data/examples/commands/slash.rb +44 -0
- data/examples/commands/user.rb +51 -0
- data/examples/components/authorization_button.rb +2 -2
- data/examples/components/select_menu.rb +2 -2
- data/examples/extension/main.rb +1 -1
- data/examples/extension/message_expander.rb +5 -2
- data/examples/simple/eval.rb +2 -2
- data/examples/simple/ping_pong.rb +1 -1
- data/examples/simple/rolepanel.rb +2 -2
- data/examples/simple/shard.rb +17 -0
- data/examples/simple/wait_for_message.rb +1 -1
- data/exe/discorb +31 -16
- data/lefthook.yml +45 -0
- data/lib/discorb/allowed_mentions.rb +8 -0
- data/lib/discorb/app_command/command.rb +184 -60
- data/lib/discorb/app_command/common.rb +25 -0
- data/lib/discorb/app_command/handler.rb +116 -34
- data/lib/discorb/app_command.rb +2 -1
- data/lib/discorb/application.rb +17 -7
- data/lib/discorb/asset.rb +10 -2
- data/lib/discorb/attachment.rb +17 -2
- data/lib/discorb/audit_logs.rb +53 -12
- data/lib/discorb/channel/base.rb +108 -0
- data/lib/discorb/channel/category.rb +32 -0
- data/lib/discorb/channel/container.rb +44 -0
- data/lib/discorb/channel/dm.rb +28 -0
- data/lib/discorb/channel/guild.rb +245 -0
- data/lib/discorb/channel/stage.rb +140 -0
- data/lib/discorb/channel/text.rb +345 -0
- data/lib/discorb/channel/thread.rb +321 -0
- data/lib/discorb/channel/voice.rb +79 -0
- data/lib/discorb/channel.rb +2 -1126
- data/lib/discorb/client.rb +160 -64
- data/lib/discorb/common.rb +18 -3
- data/lib/discorb/components/button.rb +7 -7
- data/lib/discorb/components/select_menu.rb +6 -18
- data/lib/discorb/components/text_input.rb +12 -2
- data/lib/discorb/components.rb +1 -1
- data/lib/discorb/dictionary.rb +2 -0
- data/lib/discorb/embed.rb +55 -14
- data/lib/discorb/emoji.rb +59 -5
- data/lib/discorb/emoji_table.rb +4970 -4
- data/lib/discorb/error.rb +7 -1
- data/lib/discorb/event.rb +56 -21
- data/lib/discorb/exe/about.rb +1 -0
- data/lib/discorb/exe/irb.rb +2 -4
- data/lib/discorb/exe/new.rb +95 -28
- data/lib/discorb/exe/run.rb +9 -37
- data/lib/discorb/exe/setup.rb +25 -12
- data/lib/discorb/exe/show.rb +4 -3
- data/lib/discorb/extend.rb +1 -0
- data/lib/discorb/extension.rb +6 -3
- data/lib/discorb/flag.rb +11 -0
- data/lib/discorb/gateway.rb +312 -169
- data/lib/discorb/gateway_requests.rb +4 -7
- data/lib/discorb/guild.rb +255 -89
- data/lib/discorb/guild_template.rb +34 -7
- data/lib/discorb/http.rb +23 -11
- data/lib/discorb/integration.rb +27 -9
- data/lib/discorb/intents.rb +8 -8
- data/lib/discorb/interaction/autocomplete.rb +31 -19
- data/lib/discorb/interaction/command.rb +70 -17
- data/lib/discorb/interaction/components.rb +20 -4
- data/lib/discorb/interaction/modal.rb +0 -1
- data/lib/discorb/interaction/response.rb +73 -22
- data/lib/discorb/interaction/root.rb +29 -14
- data/lib/discorb/interaction.rb +1 -0
- data/lib/discorb/invite.rb +16 -9
- data/lib/discorb/member.rb +46 -5
- data/lib/discorb/message.rb +56 -15
- data/lib/discorb/message_meta.rb +39 -9
- data/lib/discorb/modules.rb +56 -14
- data/lib/discorb/permission.rb +14 -5
- data/lib/discorb/presence.rb +43 -10
- data/lib/discorb/rate_limit.rb +13 -3
- data/lib/discorb/reaction.rb +10 -4
- data/lib/discorb/role.rb +31 -4
- data/lib/discorb/shard.rb +74 -0
- data/lib/discorb/sticker.rb +30 -21
- data/lib/discorb/user.rb +13 -1
- data/lib/discorb/utils/colored_puts.rb +1 -0
- data/lib/discorb/voice_state.rb +30 -8
- data/lib/discorb/webhook.rb +88 -25
- data/lib/discorb.rb +10 -6
- data/po/yard.pot +9 -9
- data/sig/discorb.rbs +7232 -5837
- metadata +23 -6
- data/examples/commands/bookmarker.rb +0 -42
- data/examples/commands/hello.rb +0 -10
- data/examples/commands/inspect.rb +0 -25
- data/lib/discorb/log.rb +0 -81
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discorb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sevenc-nanashi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -95,7 +95,11 @@ files:
|
|
95
95
|
- ".github/workflows/lint-push.yml"
|
96
96
|
- ".github/workflows/lint.yml"
|
97
97
|
- ".github/workflows/package_register.yml"
|
98
|
+
- ".github/workflows/spec.yml"
|
98
99
|
- ".gitignore"
|
100
|
+
- ".lefthook/commit-msg/validator.rb"
|
101
|
+
- ".rspec"
|
102
|
+
- ".rspec_parallel"
|
99
103
|
- ".rubocop.yml"
|
100
104
|
- ".yardopts"
|
101
105
|
- CODE_OF_CONDUCT.md
|
@@ -132,9 +136,10 @@ files:
|
|
132
136
|
- docs/license.md
|
133
137
|
- docs/tutorial.md
|
134
138
|
- docs/voice_events.md
|
135
|
-
- examples/commands/
|
136
|
-
- examples/commands/
|
137
|
-
- examples/commands/
|
139
|
+
- examples/commands/message.rb
|
140
|
+
- examples/commands/permission.rb
|
141
|
+
- examples/commands/slash.rb
|
142
|
+
- examples/commands/user.rb
|
138
143
|
- examples/components/authorization_button.rb
|
139
144
|
- examples/components/select_menu.rb
|
140
145
|
- examples/extension/main.rb
|
@@ -142,18 +147,30 @@ files:
|
|
142
147
|
- examples/simple/eval.rb
|
143
148
|
- examples/simple/ping_pong.rb
|
144
149
|
- examples/simple/rolepanel.rb
|
150
|
+
- examples/simple/shard.rb
|
145
151
|
- examples/simple/wait_for_message.rb
|
146
152
|
- exe/discorb
|
153
|
+
- lefthook.yml
|
147
154
|
- lib/discorb.rb
|
148
155
|
- lib/discorb/allowed_mentions.rb
|
149
156
|
- lib/discorb/app_command.rb
|
150
157
|
- lib/discorb/app_command/command.rb
|
158
|
+
- lib/discorb/app_command/common.rb
|
151
159
|
- lib/discorb/app_command/handler.rb
|
152
160
|
- lib/discorb/application.rb
|
153
161
|
- lib/discorb/asset.rb
|
154
162
|
- lib/discorb/attachment.rb
|
155
163
|
- lib/discorb/audit_logs.rb
|
156
164
|
- lib/discorb/channel.rb
|
165
|
+
- lib/discorb/channel/base.rb
|
166
|
+
- lib/discorb/channel/category.rb
|
167
|
+
- lib/discorb/channel/container.rb
|
168
|
+
- lib/discorb/channel/dm.rb
|
169
|
+
- lib/discorb/channel/guild.rb
|
170
|
+
- lib/discorb/channel/stage.rb
|
171
|
+
- lib/discorb/channel/text.rb
|
172
|
+
- lib/discorb/channel/thread.rb
|
173
|
+
- lib/discorb/channel/voice.rb
|
157
174
|
- lib/discorb/client.rb
|
158
175
|
- lib/discorb/color.rb
|
159
176
|
- lib/discorb/common.rb
|
@@ -193,7 +210,6 @@ files:
|
|
193
210
|
- lib/discorb/interaction/response.rb
|
194
211
|
- lib/discorb/interaction/root.rb
|
195
212
|
- lib/discorb/invite.rb
|
196
|
-
- lib/discorb/log.rb
|
197
213
|
- lib/discorb/member.rb
|
198
214
|
- lib/discorb/message.rb
|
199
215
|
- lib/discorb/message_meta.rb
|
@@ -203,6 +219,7 @@ files:
|
|
203
219
|
- lib/discorb/rate_limit.rb
|
204
220
|
- lib/discorb/reaction.rb
|
205
221
|
- lib/discorb/role.rb
|
222
|
+
- lib/discorb/shard.rb
|
206
223
|
- lib/discorb/sticker.rb
|
207
224
|
- lib/discorb/user.rb
|
208
225
|
- lib/discorb/utils.rb
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "discorb"
|
3
|
-
require "json"
|
4
|
-
|
5
|
-
client = Discorb::Client.new
|
6
|
-
|
7
|
-
client.once :standby do
|
8
|
-
puts "Logged in as #{client.user}"
|
9
|
-
end
|
10
|
-
|
11
|
-
def bookmark_channel(guild)
|
12
|
-
guild.channels.find { |c| c.is_a?(Discorb::TextChannel) && c.name == "bookmarks" }
|
13
|
-
end
|
14
|
-
|
15
|
-
def build_embed_from_message(message)
|
16
|
-
embed = Discorb::Embed.new
|
17
|
-
embed.description = message.content
|
18
|
-
embed.author = Discorb::Embed::Author.new(message.author.to_s_user, icon: message.author.avatar.url)
|
19
|
-
embed.timestamp = message.timestamp
|
20
|
-
embed.footer = Discorb::Embed::Footer.new("Message ID: #{message.id}")
|
21
|
-
embed
|
22
|
-
end
|
23
|
-
|
24
|
-
client.message_command("Bookmark", guild_ids: [857_373_681_096_327_180]) do |interaction, message|
|
25
|
-
unless channel = bookmark_channel(interaction.guild)
|
26
|
-
interaction.post("Bookmark channel not found. Please create one called `bookmarks`.", ephemeral: true)
|
27
|
-
next
|
28
|
-
end
|
29
|
-
channel.post(
|
30
|
-
message.jump_url,
|
31
|
-
embed: build_embed_from_message(message),
|
32
|
-
).wait
|
33
|
-
interaction.post("Bookmarked!", ephemeral: true)
|
34
|
-
end
|
35
|
-
|
36
|
-
client.change_presence(
|
37
|
-
Discorb::Activity.new(
|
38
|
-
"Open message context menu to bookmark"
|
39
|
-
)
|
40
|
-
)
|
41
|
-
|
42
|
-
client.run(ENV["DISCORD_BOT_TOKEN"])
|
data/examples/commands/hello.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "discorb"
|
3
|
-
|
4
|
-
client = Discorb::Client.new
|
5
|
-
|
6
|
-
client.once :standby do
|
7
|
-
puts "Logged in as #{client.user}"
|
8
|
-
end
|
9
|
-
|
10
|
-
client.user_command("Info", guild_ids: [857_373_681_096_327_180]) do |interaction|
|
11
|
-
interaction.post(embed: Discorb::Embed.new(
|
12
|
-
"Information of #{interaction.target.to_s_user}",
|
13
|
-
fields: [
|
14
|
-
Discorb::Embed::Field.new("User", interaction.target.to_s_user),
|
15
|
-
Discorb::Embed::Field.new("ID", interaction.target.id),
|
16
|
-
Discorb::Embed::Field.new("Bot", interaction.target.bot? ? "Yes" : "No"),
|
17
|
-
Discorb::Embed::Field.new("Joined at", interaction.target.joined_at.to_df("F")),
|
18
|
-
Discorb::Embed::Field.new("Created at", interaction.target.created_at.to_df("F"))
|
19
|
-
],
|
20
|
-
thumbnail: interaction.target.avatar&.url,
|
21
|
-
|
22
|
-
), ephemeral: true)
|
23
|
-
end
|
24
|
-
|
25
|
-
client.run(ENV["DISCORD_BOT_TOKEN"])
|
data/lib/discorb/log.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
# @private
|
5
|
-
class Logger
|
6
|
-
attr_accessor :out, :colorize_log
|
7
|
-
|
8
|
-
@levels = %i[debug info warn error fatal].freeze
|
9
|
-
|
10
|
-
def initialize(out, colorize_log, level)
|
11
|
-
@out = out
|
12
|
-
@level = self.class.levels.index(level)
|
13
|
-
@colorize_log = colorize_log
|
14
|
-
end
|
15
|
-
|
16
|
-
def inspect
|
17
|
-
"#<#{self.class} level=#{level}>"
|
18
|
-
end
|
19
|
-
|
20
|
-
def level
|
21
|
-
self.class.levels[@level]
|
22
|
-
end
|
23
|
-
|
24
|
-
def level=(level)
|
25
|
-
@level = self.class.levels.index(level)
|
26
|
-
raise ArgumentError, "Invalid log level: #{level}" unless @level
|
27
|
-
end
|
28
|
-
|
29
|
-
def debug(message, fallback: nil)
|
30
|
-
return unless @level <= 0
|
31
|
-
|
32
|
-
write_output("DEBUG", "\e[90m", message, fallback)
|
33
|
-
end
|
34
|
-
|
35
|
-
def info(message, fallback: nil)
|
36
|
-
return unless @level <= 1
|
37
|
-
|
38
|
-
write_output("INFO", "\e[94m", message, fallback)
|
39
|
-
end
|
40
|
-
|
41
|
-
def warn(message, fallback: nil)
|
42
|
-
return unless @level <= 2
|
43
|
-
|
44
|
-
write_output("WARN", "\e[93m", message, fallback)
|
45
|
-
end
|
46
|
-
|
47
|
-
def error(message, fallback: nil)
|
48
|
-
return unless @level <= 3
|
49
|
-
|
50
|
-
write_output("ERROR", "\e[31m", message, fallback)
|
51
|
-
end
|
52
|
-
|
53
|
-
def fatal(message, fallback: nil)
|
54
|
-
return unless @level <= 4
|
55
|
-
|
56
|
-
write_output("FATAL", "\e[91m", message, fallback)
|
57
|
-
end
|
58
|
-
|
59
|
-
class << self
|
60
|
-
attr_reader :levels
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def write_output(name, color, message, fallback)
|
66
|
-
unless @out
|
67
|
-
fallback&.puts(message)
|
68
|
-
|
69
|
-
return
|
70
|
-
end
|
71
|
-
|
72
|
-
time = Time.now.iso8601
|
73
|
-
if @colorize_log
|
74
|
-
@out.write("\e[90m#{time}\e[0m #{color}#{name.ljust(5)}\e[0m #{message}\n")
|
75
|
-
else
|
76
|
-
@out.write("#{time} #{name.ljust(5)} #{message}\n")
|
77
|
-
end
|
78
|
-
@out.flush
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|