discorb 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +26 -0
- data/discorb.gemspec +1 -1
- data/docs/application_command.md +11 -8
- data/docs/cli/run.md +2 -1
- data/docs/events.md +53 -1
- data/lib/discorb/app_command.rb +5 -0
- data/lib/discorb/application.rb +31 -1
- data/lib/discorb/audit_logs.rb +28 -16
- data/lib/discorb/channel.rb +12 -5
- data/lib/discorb/client.rb +4 -4
- data/lib/discorb/common.rb +26 -1
- data/lib/discorb/components.rb +12 -0
- data/lib/discorb/dictionary.rb +1 -1
- data/lib/discorb/embed.rb +4 -0
- data/lib/discorb/emoji.rb +4 -0
- data/lib/discorb/emoji_table.rb +3891 -3806
- data/lib/discorb/event.rb +265 -24
- data/lib/discorb/event_handler.rb +39 -0
- data/lib/discorb/exe/run.rb +16 -1
- data/lib/discorb/extension.rb +4 -4
- data/lib/discorb/file.rb +4 -0
- data/lib/discorb/flag.rb +4 -0
- data/lib/discorb/gateway.rb +56 -1
- data/lib/discorb/gateway_requests.rb +4 -0
- data/lib/discorb/guild.rb +113 -0
- data/lib/discorb/http.rb +11 -4
- data/lib/discorb/image.rb +7 -5
- data/lib/discorb/integration.rb +1 -1
- data/lib/discorb/intents.rb +8 -3
- data/lib/discorb/interaction/autocomplete.rb +1 -1
- data/lib/discorb/interaction/command.rb +2 -2
- data/lib/discorb/log.rb +4 -0
- data/lib/discorb/member.rb +1 -1
- data/lib/discorb/message.rb +29 -23
- data/lib/discorb/permission.rb +4 -0
- data/lib/discorb/rate_limit.rb +6 -2
- data/lib/discorb/sticker.rb +9 -0
- data/lib/discorb/user.rb +1 -0
- data/lib/discorb.rb +1 -1
- data/po/yard.pot +4 -4
- data/sig/discorb.rbs +7 -7
- data/template-replace/scripts/yard_replace.rb +6 -0
- metadata +4 -3
data/lib/discorb/image.rb
CHANGED
@@ -16,12 +16,10 @@ module Discorb
|
|
16
16
|
#
|
17
17
|
def initialize(source, type = nil)
|
18
18
|
if source.respond_to?(:read)
|
19
|
-
@
|
19
|
+
@io = source
|
20
20
|
@type = type || MIME::Types.type_for(source.path).first.content_type
|
21
21
|
elsif ::File.exist?(source)
|
22
|
-
::File.open(source, "rb")
|
23
|
-
@bytes = file.read
|
24
|
-
end
|
22
|
+
@io = ::File.open(source, "rb")
|
25
23
|
@type = MIME::Types.type_for(source).first.to_s
|
26
24
|
else
|
27
25
|
raise ArgumentError, "Couldn't read file."
|
@@ -34,7 +32,11 @@ module Discorb
|
|
34
32
|
# @return [String] The image as a Discord style.
|
35
33
|
#
|
36
34
|
def to_s
|
37
|
-
"data:#{@type};base64,#{Base64.strict_encode64(@
|
35
|
+
"data:#{@type};base64,#{Base64.strict_encode64(@io.read)}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def inspect
|
39
|
+
"#<#{self.class} #{@type}>"
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
data/lib/discorb/integration.rb
CHANGED
@@ -84,7 +84,7 @@ module Discorb
|
|
84
84
|
@account = Account.new(data[:account])
|
85
85
|
@subscriber_count = data[:subscriber_count]
|
86
86
|
@revoked = data[:revoked]
|
87
|
-
@application = Application.new(@client, data[:application])
|
87
|
+
@application = data[:application] and Application.new(@client, data[:application])
|
88
88
|
end
|
89
89
|
|
90
90
|
class << self
|
data/lib/discorb/intents.rb
CHANGED
@@ -19,6 +19,7 @@ module Discorb
|
|
19
19
|
dm_messages: 1 << 12,
|
20
20
|
dm_reactions: 1 << 13,
|
21
21
|
dm_typing: 1 << 14,
|
22
|
+
scheduled_events: 1 << 16,
|
22
23
|
}.freeze
|
23
24
|
|
24
25
|
#
|
@@ -38,6 +39,7 @@ module Discorb
|
|
38
39
|
# @param dm_messages [Boolean] Whether dm messages related events are enabled.
|
39
40
|
# @param dm_reactions [Boolean] Whether dm reactions related events are enabled.
|
40
41
|
# @param dm_typing [Boolean] Whether dm typing related events are enabled.
|
42
|
+
# @param scheduled_events [Boolean] Whether events related scheduled events are enabled.
|
41
43
|
#
|
42
44
|
# @note You must enable privileged intents to use `members` and/or `presences` intents.
|
43
45
|
#
|
@@ -55,7 +57,8 @@ module Discorb
|
|
55
57
|
typing: true,
|
56
58
|
dm_messages: true,
|
57
59
|
dm_reactions: true,
|
58
|
-
dm_typing: true
|
60
|
+
dm_typing: true,
|
61
|
+
scheduled_events: true)
|
59
62
|
@raw_value = {
|
60
63
|
guilds: guilds,
|
61
64
|
members: members,
|
@@ -72,6 +75,7 @@ module Discorb
|
|
72
75
|
dm_messages: dm_messages,
|
73
76
|
dm_reactions: dm_reactions,
|
74
77
|
dm_typing: dm_typing,
|
78
|
+
scheduled_events: scheduled_events,
|
75
79
|
}
|
76
80
|
end
|
77
81
|
|
@@ -124,13 +128,14 @@ module Discorb
|
|
124
128
|
end
|
125
129
|
|
126
130
|
# Create new intent object with default values.
|
131
|
+
# This will return intents without members and presence.
|
127
132
|
def default
|
128
|
-
from_value(
|
133
|
+
from_value(@intent_bits.values.reduce(:+) - @intent_bits[:members] - @intent_bits[:presences])
|
129
134
|
end
|
130
135
|
|
131
136
|
# Create new intent object with all intents.
|
132
137
|
def all
|
133
|
-
from_value(
|
138
|
+
from_value(@intent_bits.values.reduce(:+))
|
134
139
|
end
|
135
140
|
|
136
141
|
# Create new intent object with no intents.
|
@@ -18,7 +18,7 @@ module Discorb
|
|
18
18
|
end
|
19
19
|
|
20
20
|
option_map = command.options.map { |k, v| [k.to_s, v[:default]] }.to_h
|
21
|
-
Discorb::CommandInteraction::SlashCommand.modify_option_map(option_map, options)
|
21
|
+
Discorb::CommandInteraction::SlashCommand.modify_option_map(option_map, options, guild)
|
22
22
|
focused_index = options.find_index { |o| o[:focused] }
|
23
23
|
val = command.options.values[focused_index][:autocomplete]&.call(self, *command.options.map { |k, v| option_map[k.to_s] })
|
24
24
|
send_complete_result(val)
|
@@ -26,7 +26,7 @@ module Discorb
|
|
26
26
|
end
|
27
27
|
|
28
28
|
option_map = command.options.map { |k, v| [k.to_s, v[:default]] }.to_h
|
29
|
-
SlashCommand.modify_option_map(option_map, options)
|
29
|
+
SlashCommand.modify_option_map(option_map, options, guild)
|
30
30
|
|
31
31
|
command.block.call(self, *command.options.map { |k, v| option_map[k.to_s] })
|
32
32
|
end
|
@@ -59,7 +59,7 @@ module Discorb
|
|
59
59
|
end
|
60
60
|
|
61
61
|
# @private
|
62
|
-
def modify_option_map(option_map, options)
|
62
|
+
def modify_option_map(option_map, options, guild)
|
63
63
|
options ||= []
|
64
64
|
options.each_with_index do |option|
|
65
65
|
val = case option[:type]
|
data/lib/discorb/log.rb
CHANGED
data/lib/discorb/member.rb
CHANGED
@@ -233,7 +233,7 @@ module Discorb
|
|
233
233
|
@joined_at = member_data[:joined_at] && Time.iso8601(member_data[:joined_at])
|
234
234
|
@hoisted_role_id = member_data[:hoisted_role]
|
235
235
|
@deaf = member_data[:deaf]
|
236
|
-
@custom_avatar = member_data[:avatar] && Asset.new(member_data[:avatar])
|
236
|
+
@custom_avatar = member_data[:avatar] && Asset.new(self, member_data[:avatar])
|
237
237
|
super(user_data)
|
238
238
|
@display_avatar = @avatar || @custom_avatar
|
239
239
|
@client.guilds[@guild_id].members[@id] = self unless @guild_id.nil? || @client.guilds[@guild_id].nil?
|
data/lib/discorb/message.rb
CHANGED
@@ -29,6 +29,10 @@ module Discorb
|
|
29
29
|
@replied_user = replied_user
|
30
30
|
end
|
31
31
|
|
32
|
+
def inspect
|
33
|
+
"#<#{self.class} @everyone=#{@everyone} @roles=#{@roles} @users=#{@users} @replied_user=#{@replied_user}>"
|
34
|
+
end
|
35
|
+
|
32
36
|
# @private
|
33
37
|
def to_hash(other = nil)
|
34
38
|
payload = {
|
@@ -109,9 +113,10 @@ module Discorb
|
|
109
113
|
# * `:guild_discovery_grace_period_final_warning`
|
110
114
|
# * `:thread_created`
|
111
115
|
# * `:reply`
|
112
|
-
# * `:
|
116
|
+
# * `:chat_input_command`
|
113
117
|
# * `:thread_starter_message`
|
114
118
|
# * `:guild_invite_reminder`
|
119
|
+
# * `:context_menu_command`
|
115
120
|
attr_reader :type
|
116
121
|
# @return [Discorb::Message::Activity] The activity of the message.
|
117
122
|
attr_reader :activity
|
@@ -143,28 +148,29 @@ module Discorb
|
|
143
148
|
attr_reader :pinned
|
144
149
|
alias pinned? pinned
|
145
150
|
@message_type = {
|
146
|
-
default
|
147
|
-
recipient_add
|
148
|
-
recipient_remove
|
149
|
-
call
|
150
|
-
channel_name_change
|
151
|
-
channel_icon_change
|
152
|
-
channel_pinned_message
|
153
|
-
guild_member_join
|
154
|
-
user_premium_guild_subscription
|
155
|
-
user_premium_guild_subscription_tier_1
|
156
|
-
user_premium_guild_subscription_tier_2
|
157
|
-
user_premium_guild_subscription_tier_3
|
158
|
-
channel_follow_add
|
159
|
-
guild_discovery_disqualified
|
160
|
-
guild_discovery_requalified
|
161
|
-
guild_discovery_grace_period_initial_warning
|
162
|
-
guild_discovery_grace_period_final_warning
|
163
|
-
thread_created
|
164
|
-
reply
|
165
|
-
|
166
|
-
thread_starter_message
|
167
|
-
guild_invite_reminder
|
151
|
+
0 => :default,
|
152
|
+
1 => :recipient_add,
|
153
|
+
2 => :recipient_remove,
|
154
|
+
3 => :call,
|
155
|
+
4 => :channel_name_change,
|
156
|
+
5 => :channel_icon_change,
|
157
|
+
6 => :channel_pinned_message,
|
158
|
+
7 => :guild_member_join,
|
159
|
+
8 => :user_premium_guild_subscription,
|
160
|
+
9 => :user_premium_guild_subscription_tier_1,
|
161
|
+
10 => :user_premium_guild_subscription_tier_2,
|
162
|
+
11 => :user_premium_guild_subscription_tier_3,
|
163
|
+
12 => :channel_follow_add,
|
164
|
+
14 => :guild_discovery_disqualified,
|
165
|
+
15 => :guild_discovery_requalified,
|
166
|
+
16 => :guild_discovery_grace_period_initial_warning,
|
167
|
+
17 => :guild_discovery_grace_period_final_warning,
|
168
|
+
18 => :thread_created,
|
169
|
+
19 => :reply,
|
170
|
+
20 => :chat_input_command,
|
171
|
+
21 => :thread_starter_message,
|
172
|
+
22 => :guild_invite_reminder,
|
173
|
+
23 => :context_menu_command,
|
168
174
|
}.freeze
|
169
175
|
|
170
176
|
# @!attribute [r] channel
|
data/lib/discorb/permission.rb
CHANGED
data/lib/discorb/rate_limit.rb
CHANGED
@@ -14,6 +14,10 @@ module Discorb
|
|
14
14
|
@global = false
|
15
15
|
end
|
16
16
|
|
17
|
+
def inspect
|
18
|
+
"#<#{self.class}>"
|
19
|
+
end
|
20
|
+
|
17
21
|
#
|
18
22
|
# Wait for the rate limit to reset.
|
19
23
|
#
|
@@ -23,8 +27,8 @@ module Discorb
|
|
23
27
|
def wait(method, path)
|
24
28
|
return if path.start_with?("https://")
|
25
29
|
|
26
|
-
if @global
|
27
|
-
time =
|
30
|
+
if @global && @global > Time.now.to_f
|
31
|
+
time = @global - Time.now.to_f
|
28
32
|
@client.log.info("global rate limit reached, waiting #{time} seconds")
|
29
33
|
sleep(time)
|
30
34
|
@global = false
|
data/lib/discorb/sticker.rb
CHANGED
@@ -51,6 +51,15 @@ module Discorb
|
|
51
51
|
# @!attribute [r] guild
|
52
52
|
# @macro client_cache
|
53
53
|
# @return [Discorb::Guild] The guild the sticker is in.
|
54
|
+
@sticker_type = {
|
55
|
+
1 => :official,
|
56
|
+
2 => :guild,
|
57
|
+
}.freeze
|
58
|
+
@sticker_format = {
|
59
|
+
1 => :png,
|
60
|
+
2 => :apng,
|
61
|
+
3 => :lottie,
|
62
|
+
}
|
54
63
|
|
55
64
|
def guild
|
56
65
|
@client.guilds[@guild_id]
|
data/lib/discorb/user.rb
CHANGED
data/lib/discorb.rb
CHANGED
@@ -41,7 +41,7 @@ end
|
|
41
41
|
|
42
42
|
require_order = %w[common flag dictionary error rate_limit http intents emoji_table modules] +
|
43
43
|
%w[user member guild emoji channel embed message] +
|
44
|
-
%w[application audit_logs color components event] +
|
44
|
+
%w[application audit_logs color components event event_handler] +
|
45
45
|
%w[file guild_template image integration interaction invite log permission] +
|
46
46
|
%w[presence reaction role sticker utils voice_state webhook] +
|
47
47
|
%w[gateway_requests gateway app_command] +
|
data/po/yard.pot
CHANGED
@@ -4784,7 +4784,7 @@ msgstr ""
|
|
4784
4784
|
msgid "The block to execute when the event is triggered."
|
4785
4785
|
msgstr ""
|
4786
4786
|
|
4787
|
-
# @return [Discorb::
|
4787
|
+
# @return [Discorb::EventHandler]
|
4788
4788
|
#: ../lib/discorb/client.rb:104
|
4789
4789
|
#: ../lib/discorb/client.rb:118
|
4790
4790
|
#: ../lib/discorb/extension.rb:24
|
@@ -7040,7 +7040,7 @@ msgstr ""
|
|
7040
7040
|
msgid "a new instance of NotSupportedWarning"
|
7041
7041
|
msgstr ""
|
7042
7042
|
|
7043
|
-
# Discorb::
|
7043
|
+
# Discorb::EventHandler
|
7044
7044
|
#: ../lib/discorb/event.rb:5
|
7045
7045
|
msgid "Represents a event.\n"
|
7046
7046
|
"This class shouldn't be instantiated directly.\n"
|
@@ -7073,7 +7073,7 @@ msgstr ""
|
|
7073
7073
|
msgid "a new instance of Event"
|
7074
7074
|
msgstr ""
|
7075
7075
|
|
7076
|
-
# Discorb::
|
7076
|
+
# Discorb::EventHandler#call
|
7077
7077
|
#: ../lib/discorb/event.rb:29
|
7078
7078
|
msgid "Calls the block associated with the event."
|
7079
7079
|
msgstr ""
|
@@ -7135,7 +7135,7 @@ msgstr ""
|
|
7135
7135
|
msgid "Define a new once event."
|
7136
7136
|
msgstr ""
|
7137
7137
|
|
7138
|
-
# @return [Hash{Symbol => Array<Discorb::
|
7138
|
+
# @return [Hash{Symbol => Array<Discorb::EventHandler>}]
|
7139
7139
|
#: ../lib/discorb/extension.rb:48
|
7140
7140
|
msgid "The events of the extension."
|
7141
7141
|
msgstr ""
|
data/sig/discorb.rbs
CHANGED
@@ -2183,12 +2183,12 @@ module Discorb
|
|
2183
2183
|
# _@return_ — The event.
|
2184
2184
|
#
|
2185
2185
|
# _@see_ `file:docs/Events.md`
|
2186
|
-
def on: (Symbol event_name, ?id: Symbol?, **::Hash[untyped, untyped] metadata) -> Discorb::
|
2186
|
+
def on: (Symbol event_name, ?id: Symbol?, **::Hash[untyped, untyped] metadata) -> Discorb::EventHandler
|
2187
2187
|
|
2188
2188
|
# Almost same as {#on}, but only triggers the event once.
|
2189
2189
|
#
|
2190
2190
|
# _@return_ — The event.
|
2191
|
-
def once: (Symbol event_name, ?id: Symbol?, **::Hash[untyped, untyped] metadata) -> Discorb::
|
2191
|
+
def once: (Symbol event_name, ?id: Symbol?, **::Hash[untyped, untyped] metadata) -> Discorb::EventHandler
|
2192
2192
|
|
2193
2193
|
# Remove event by ID.
|
2194
2194
|
#
|
@@ -3981,7 +3981,7 @@ module Discorb
|
|
3981
3981
|
module Command
|
3982
3982
|
#
|
3983
3983
|
# Module to handle commands.
|
3984
|
-
module
|
3984
|
+
module EventHandler
|
3985
3985
|
# Add new top-level command.
|
3986
3986
|
#
|
3987
3987
|
# _@param_ `command_name` — Command name.
|
@@ -4548,7 +4548,7 @@ module Discorb
|
|
4548
4548
|
|
4549
4549
|
#
|
4550
4550
|
# A module to handle gateway events.
|
4551
|
-
module
|
4551
|
+
module EventHandler
|
4552
4552
|
def connect_gateway: (untyped first) -> untyped
|
4553
4553
|
|
4554
4554
|
def send_gateway: (untyped opcode, **untyped value) -> untyped
|
@@ -5798,7 +5798,7 @@ module Discorb
|
|
5798
5798
|
# _@param_ `block` — The block to execute when the event is triggered.
|
5799
5799
|
#
|
5800
5800
|
# _@return_ — The event.
|
5801
|
-
def event: (Symbol event_name, ?id: Symbol?, **::Hash[untyped, untyped] metadata) -> Discorb::
|
5801
|
+
def event: (Symbol event_name, ?id: Symbol?, **::Hash[untyped, untyped] metadata) -> Discorb::EventHandler
|
5802
5802
|
|
5803
5803
|
# Define a new once event.
|
5804
5804
|
#
|
@@ -5811,7 +5811,7 @@ module Discorb
|
|
5811
5811
|
# _@param_ `block` — The block to execute when the event is triggered.
|
5812
5812
|
#
|
5813
5813
|
# _@return_ — The event.
|
5814
|
-
def once_event: (Symbol event_name, ?id: Symbol?, **::Hash[untyped, untyped] metadata) -> Discorb::
|
5814
|
+
def once_event: (Symbol event_name, ?id: Symbol?, **::Hash[untyped, untyped] metadata) -> Discorb::EventHandler
|
5815
5815
|
|
5816
5816
|
def self.extended: (untyped obj) -> untyped
|
5817
5817
|
|
@@ -5886,7 +5886,7 @@ module Discorb
|
|
5886
5886
|
def setup_commands: (?String? token, ?guild_ids: (::Array[untyped] | bool)?) -> untyped
|
5887
5887
|
|
5888
5888
|
# _@return_ — The events of the extension.
|
5889
|
-
attr_reader events: ::Hash[Symbol, ::Array[Discorb::
|
5889
|
+
attr_reader events: ::Hash[Symbol, ::Array[Discorb::EventHandler]]
|
5890
5890
|
|
5891
5891
|
# _@return_ — The commands of the extension.
|
5892
5892
|
attr_reader commands: ::Array[Discorb::ApplicationCommand::Command]
|
@@ -22,6 +22,12 @@ def yard_replace(dir, version)
|
|
22
22
|
<h1 class="noborder title">Documentation by YARD 0.9.26</h1>
|
23
23
|
HTML3
|
24
24
|
HTML4
|
25
|
+
if version == "main"
|
26
|
+
display_version = "(main)"
|
27
|
+
else
|
28
|
+
display_version = "v" + version
|
29
|
+
end
|
30
|
+
contents.gsub!(/Documentation by YARD \d+\.\d+\.\d+/, "discorb #{display_version} documentation")
|
25
31
|
File.write(file, contents)
|
26
32
|
end
|
27
33
|
end
|
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.13.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: 2021-
|
11
|
+
date: 2021-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- lib/discorb/emoji_table.rb
|
145
145
|
- lib/discorb/error.rb
|
146
146
|
- lib/discorb/event.rb
|
147
|
+
- lib/discorb/event_handler.rb
|
147
148
|
- lib/discorb/exe/about.rb
|
148
149
|
- lib/discorb/exe/irb.rb
|
149
150
|
- lib/discorb/exe/new.rb
|
@@ -221,5 +222,5 @@ requirements: []
|
|
221
222
|
rubygems_version: 3.2.22
|
222
223
|
signing_key:
|
223
224
|
specification_version: 4
|
224
|
-
summary:
|
225
|
+
summary: A discord API wrapper written in Ruby
|
225
226
|
test_files: []
|