discorb 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -3
- data/.yardopts +1 -0
- data/Changelog.md +21 -0
- data/README.md +9 -6
- data/assets/banner.svg +125 -0
- data/docs/application_command.md +11 -11
- data/docs/events.md +5 -0
- data/docs/extension.md +5 -5
- data/lib/discorb/app_command.rb +6 -6
- data/lib/discorb/client.rb +12 -10
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/embed.rb +12 -12
- data/lib/discorb/gateway.rb +23 -3
- data/lib/discorb/interaction.rb +1 -0
- data/lib/discorb/log.rb +16 -12
- data/lib/discorb/member.rb +2 -2
- data/lib/discorb/message.rb +3 -3
- metadata +3 -3
- data/Gemfile.lock +0 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13326863238ba4e79e873947fe579da1027bfcfe7f6baed1bd9d0c74806e31a1
|
4
|
+
data.tar.gz: c43a370b95eec06dcfa2ce0f627c8b9e14421464848c7170690ddc9527aff589
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf804c54e218696a9ba5464af5e8c6d4d25132ac573413d0453502872e2dcc55ec49bfb4c571d05df4d489a49cef894ca139091e74fb41fb0d5f36c2786e5cdf
|
7
|
+
data.tar.gz: 8fb94771a4ea9730962f084d40439383b412caa97674aa9d6edb38d01ebd10fb14ecc54a9bac24a067768bbe5866d18ddd6366449ba84355324af70839fce135
|
data/.gitignore
CHANGED
@@ -45,9 +45,9 @@ build-iPhoneSimulator/
|
|
45
45
|
|
46
46
|
# for a library or gem, you might want to ignore these files since the code is
|
47
47
|
# intended to run in multiple environments; otherwise, check them in:
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
Gemfile.lock
|
49
|
+
.ruby-version
|
50
|
+
.ruby-gemset
|
51
51
|
|
52
52
|
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
53
|
.rvmrc
|
data/.yardopts
CHANGED
data/Changelog.md
CHANGED
@@ -150,3 +150,24 @@
|
|
150
150
|
|
151
151
|
- Change: Rename `Event#discriminator` to `Event#metadata`
|
152
152
|
- Add: Add `:override` to `Client#on`
|
153
|
+
|
154
|
+
## 0.7.0
|
155
|
+
|
156
|
+
- Add: Add `error` event
|
157
|
+
- Fix: Fix some issues with client without guild intent
|
158
|
+
- Add: Add alias for `#fired_by`
|
159
|
+
- Change!: Change block usage of `ApplicationCommand::Handler#group`
|
160
|
+
```ruby
|
161
|
+
# before
|
162
|
+
client.slash_group do
|
163
|
+
slash "help", "Help" do |interaction|
|
164
|
+
# ...
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# after
|
169
|
+
client.slash_group do |group|
|
170
|
+
group.slash "help", "Help" do |interaction|
|
171
|
+
# ...
|
172
|
+
end
|
173
|
+
end
|
data/README.md
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
![discorb](./assets/banner.svg)
|
2
|
+
|
3
|
+
<div align="center"><a href="https://discorb-lib.github.io/"><img src="https://img.shields.io/badge/Document-discorb--lib.github.io-blue.svg" alt="Document"></a>
|
4
|
+
<a href="https://rubygems.org/gems/discorb"><img src="https://img.shields.io/gem/dt/discorb?logo=rubygems&logoColor=fff" alt="Gem"></a>
|
5
|
+
<a href="https://rubygems.org/gems/discorb"><img src="https://img.shields.io/gem/v/discorb?logo=rubygems&logoColor=fff" alt="Gem"></a>
|
6
|
+
<a href="https://discord.gg/hCP6zq8Vpj"><img src="https://img.shields.io/discord/863581274916913193?logo=discord&logoColor=fff&color=5865f2&label=Discord" alt="Discord"></a>
|
7
|
+
<a href="https://github.com/discorb-lib/discorb"><img src="https://img.shields.io/github/stars/discorb-lib/discorb?color=24292e&label=Stars&logo=GitHub&logoColor=fff" alt="GitHub"></a></div>
|
8
|
+
|
9
|
+
----
|
7
10
|
|
8
11
|
discorb is a Discord API wrapper for Ruby.
|
9
12
|
|
data/assets/banner.svg
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
3
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
4
|
+
<svg version="1.1" id="レイヤー_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px"
|
5
|
+
y="0px" width="1080px" height="150px" viewBox="0 0 1080 150" enable-background="new 0 0 1080 150" xml:space="preserve">
|
6
|
+
<g>
|
7
|
+
<defs>
|
8
|
+
<rect id="SVGID_1_" x="283.667" y="-12.667" width="343.333" height="201.333"/>
|
9
|
+
</defs>
|
10
|
+
<clipPath id="SVGID_2_">
|
11
|
+
<use xlink:href="#SVGID_1_" overflow="visible"/>
|
12
|
+
</clipPath>
|
13
|
+
<g clip-path="url(#SVGID_2_)">
|
14
|
+
<g>
|
15
|
+
<g>
|
16
|
+
<path fill="#2E3338" d="M370.533,119.061c-13.503,0-21.565-10.312-21.565-27.582c0-18.543,9.872-30.525,25.149-30.525
|
17
|
+
c5.186,0,10.446,0.915,14.432,2.509l3.429,1.372V31.79l6.393-1.006v86.997h-4.456l-1.936-12.146l-3.522,4.208
|
18
|
+
C383.265,116.045,377.402,119.061,370.533,119.061z M374.501,65.554c-9.191,0-19.013,6.676-19.013,25.413
|
19
|
+
c0,13.96,6.559,22.98,16.708,22.98c7.18,0,13.308-3.736,19.286-11.758l0.495-0.665V69.983l-1.358-0.697
|
20
|
+
C385.253,66.53,381.035,65.554,374.501,65.554z"/>
|
21
|
+
</g>
|
22
|
+
<g>
|
23
|
+
<path fill="#2E3338" d="M419.624,117.78V61.721h6.393v56.059H419.624z M422.884,44.433c-2.645,0-4.796-2.094-4.796-4.668
|
24
|
+
c0-2.6,2.196-4.796,4.796-4.796c2.574,0,4.668,2.152,4.668,4.796C427.552,42.338,425.458,44.433,422.884,44.433z"/>
|
25
|
+
</g>
|
26
|
+
<g>
|
27
|
+
<path fill="#2E3338" d="M463.332,119.061c-7.015,0-14.662-2.282-19.529-4.647l0.809-5.23c4.905,2.794,11.627,5.405,19.616,5.405
|
28
|
+
c9.34,0,14.917-3.949,14.917-10.564c0-8.187-6.482-10.382-16.372-12.797c-13.937-3.485-18.19-7.314-18.19-16.388
|
29
|
+
c0-8.611,7.638-14.397,19.005-14.397c6.173,0,11.985,1.055,17.305,3.139l-0.902,5.412c-5.417-2.532-11.33-3.95-16.659-3.95
|
30
|
+
c-12.06,0-12.997,7.302-12.997,9.54c0,6.302,5.57,8.979,14.559,11.256c15.329,3.897,20.003,7.967,20.003,17.418
|
31
|
+
C484.897,113.3,477.037,119.061,463.332,119.061z"/>
|
32
|
+
</g>
|
33
|
+
<g>
|
34
|
+
<path fill="#2E3338" d="M523.746,119.061c-15.986,0-25.917-11.206-25.917-29.246c0-17.843,10.273-29.373,26.173-29.373
|
35
|
+
c6.897,0,12.696,1.453,17.263,4.322l-0.821,5.493c-5.086-3.282-10.441-4.83-16.57-4.83c-12.043,0-19.525,9.296-19.525,24.262
|
36
|
+
c0,15.271,7.777,24.389,20.805,24.389c6.137,0,11.114-1.451,15.996-4.757l0.746,4.59
|
37
|
+
C536.669,117.509,531.15,119.061,523.746,119.061z"/>
|
38
|
+
</g>
|
39
|
+
<g>
|
40
|
+
<path fill="#2E3338" d="M580.834,119.061c-15.511,0-25.533-11.479-25.533-29.246c0-17.843,10.022-29.373,25.533-29.373
|
41
|
+
c15.744,0,25.917,11.53,25.917,29.373C606.751,107.581,596.578,119.061,580.834,119.061z M580.834,65.042
|
42
|
+
c-11.729,0-19.014,9.492-19.014,24.772c0,15.049,7.463,24.773,19.014,24.773c11.964,0,19.396-9.492,19.396-24.773
|
43
|
+
C600.23,74.766,592.617,65.042,580.834,65.042z"/>
|
44
|
+
</g>
|
45
|
+
<g>
|
46
|
+
<path d="M623.652,117.78V61.721h4.444l2.615,16.91l3.563-5.661c3.16-5.019,8.634-11.016,17.176-12.309l0.981,5.953
|
47
|
+
c-9.186,1.447-17.664,7.67-22.117,16.437l-0.271,0.533v34.196H623.652z"/>
|
48
|
+
</g>
|
49
|
+
<g>
|
50
|
+
<path d="M688.224,118.549c-8.27,0-14.267-1.167-21.31-3.208V31.79l6.393-1.006V72.56l4.295-4.43
|
51
|
+
c5.017-5.173,10.417-7.688,16.51-7.688c13.302,0,21.565,10.569,21.565,27.582C715.677,107.423,705.671,118.549,688.224,118.549z
|
52
|
+
M692.447,65.554c-6.539,0-12.794,3.675-18.593,10.923l-0.548,0.685v33.856l1.64,0.601c3.981,1.461,7.108,2.202,13.148,2.202
|
53
|
+
c9.608,0,21.062-4.387,21.062-25.285C709.156,74.575,702.598,65.554,692.447,65.554z"/>
|
54
|
+
</g>
|
55
|
+
</g>
|
56
|
+
</g>
|
57
|
+
</g>
|
58
|
+
<g>
|
59
|
+
<defs>
|
60
|
+
<rect id="SVGID_3_" x="610.334" y="8" width="268" height="246"/>
|
61
|
+
</defs>
|
62
|
+
<clipPath id="SVGID_4_">
|
63
|
+
<use xlink:href="#SVGID_3_" overflow="visible"/>
|
64
|
+
</clipPath>
|
65
|
+
<g clip-path="url(#SVGID_4_)">
|
66
|
+
<g>
|
67
|
+
<path fill="#2E3338" d="M391.782,120.28l-1.408-8.833c-4.608,5.505-10.88,10.113-19.841,10.113
|
68
|
+
c-13.185,0-24.065-9.601-24.065-30.082c0-22.272,12.8-33.025,27.649-33.025c6.017,0,11.521,1.152,15.361,2.688v-31.49
|
69
|
+
l11.393-1.792v92.42H391.782z M389.478,71.51c-4.736-2.432-8.448-3.456-14.977-3.456c-9.601,0-16.513,7.809-16.513,22.913
|
70
|
+
c0,13.441,6.016,20.48,14.208,20.48c7.041,0,12.417-4.224,17.281-10.752V71.51z"/>
|
71
|
+
<path fill="#2E3338" d="M422.884,46.933c-3.968,0-7.296-3.2-7.296-7.168s3.328-7.296,7.296-7.296s7.168,3.328,7.168,7.296
|
72
|
+
S426.852,46.933,422.884,46.933z M417.124,120.28V59.221h11.393v61.059H417.124z"/>
|
73
|
+
<path fill="#2E3338" d="M463.332,121.561c-8.064,0-17.025-2.816-22.273-5.76l1.664-10.754c5.76,3.969,13.185,7.041,21.505,7.041
|
74
|
+
c7.808,0,12.417-2.944,12.417-8.064c0-5.633-3.456-7.68-14.465-10.368c-14.336-3.585-20.097-7.937-20.097-18.817
|
75
|
+
c0-9.729,8.192-16.897,21.505-16.897c7.552,0,14.336,1.536,20.097,4.096l-1.792,10.752c-5.376-3.072-12.161-5.248-18.561-5.248
|
76
|
+
c-6.913,0-10.497,2.688-10.497,7.04c0,4.096,3.072,6.4,12.672,8.832c15.105,3.841,21.889,8.193,21.889,19.842
|
77
|
+
C487.397,114.393,479.077,121.561,463.332,121.561z"/>
|
78
|
+
<path fill="#2E3338" d="M523.746,121.561c-16.385,0-28.417-11.393-28.417-31.746c0-20.865,12.8-31.873,28.673-31.873
|
79
|
+
c8.96,0,15.36,2.304,19.968,5.632l-1.664,11.136c-5.632-4.608-11.392-6.784-18.432-6.784c-9.985,0-17.025,7.552-17.025,21.762
|
80
|
+
c0,14.848,7.552,21.889,18.305,21.889c6.145,0,11.521-1.408,17.793-6.785l1.664,10.241
|
81
|
+
C538.339,119.768,531.938,121.561,523.746,121.561z"/>
|
82
|
+
<path fill="#2E3338" d="M580.834,121.561c-16.258,0-28.033-11.648-28.033-31.746c0-20.097,11.775-31.873,28.033-31.873
|
83
|
+
c16.385,0,28.417,11.776,28.417,31.873C609.251,109.912,597.219,121.561,580.834,121.561z M580.834,67.542
|
84
|
+
c-11.009,0-16.514,9.472-16.514,22.272c0,12.545,5.761,22.273,16.514,22.273c11.264,0,16.896-9.473,16.896-22.273
|
85
|
+
C597.73,77.271,591.842,67.542,580.834,67.542z"/>
|
86
|
+
<path fill="#CC342D" d="M632.545,84.183v36.098h-11.393V59.221h9.088l1.92,12.417c4.353-6.913,11.393-13.185,21.377-13.697
|
87
|
+
l1.793,10.88C645.217,69.334,636.641,76.118,632.545,84.183z"/>
|
88
|
+
<path fill="#CC342D" d="M688.224,121.049c-9.217,0-15.745-1.408-23.81-3.841V29.652l11.393-1.792v38.53
|
89
|
+
c4.096-4.224,9.984-8.448,18.305-8.448c13.185,0,24.065,9.729,24.065,30.082C718.177,110.296,705.888,121.049,688.224,121.049z
|
90
|
+
M692.447,68.054c-6.4,0-12.032,4.224-16.641,9.984v31.233c3.84,1.408,6.656,2.049,12.288,2.049
|
91
|
+
c11.905,0,18.562-7.041,18.562-22.785C706.656,75.222,700.64,68.054,692.447,68.054z"/>
|
92
|
+
</g>
|
93
|
+
</g>
|
94
|
+
</g>
|
95
|
+
<g>
|
96
|
+
</g>
|
97
|
+
<g>
|
98
|
+
</g>
|
99
|
+
<g>
|
100
|
+
</g>
|
101
|
+
<g>
|
102
|
+
</g>
|
103
|
+
<g>
|
104
|
+
</g>
|
105
|
+
<g>
|
106
|
+
</g>
|
107
|
+
<g>
|
108
|
+
</g>
|
109
|
+
<g>
|
110
|
+
</g>
|
111
|
+
<g>
|
112
|
+
</g>
|
113
|
+
<g>
|
114
|
+
</g>
|
115
|
+
<g>
|
116
|
+
</g>
|
117
|
+
<g>
|
118
|
+
</g>
|
119
|
+
<g>
|
120
|
+
</g>
|
121
|
+
<g>
|
122
|
+
</g>
|
123
|
+
<g>
|
124
|
+
</g>
|
125
|
+
</svg>
|
data/docs/application_command.md
CHANGED
@@ -136,8 +136,8 @@ Since v0.5.1, You can use block for register commands.
|
|
136
136
|
|
137
137
|
```ruby
|
138
138
|
|
139
|
-
client.slash_group("settings", "Set settings of bot.") do
|
140
|
-
slash("message_expand", "Whether bot should expand message.", {
|
139
|
+
client.slash_group("settings", "Set settings of bot.") do |group|
|
140
|
+
group.slash("message_expand", "Whether bot should expand message.", {
|
141
141
|
"enabled" => {
|
142
142
|
type: :boolean,
|
143
143
|
description: "Whether bot should expand message."
|
@@ -145,7 +145,7 @@ client.slash_group("settings", "Set settings of bot.") do
|
|
145
145
|
}) do |interaction|
|
146
146
|
# ...
|
147
147
|
end
|
148
|
-
slash("bump_alert", "Whether bot should notify DISBOARD bump.", {
|
148
|
+
group.slash("bump_alert", "Whether bot should notify DISBOARD bump.", {
|
149
149
|
"enabled" => {
|
150
150
|
type: :boolean,
|
151
151
|
description: "Whether bot should notify DISBOARD bump."
|
@@ -164,14 +164,14 @@ group = client.slash_group("permission", "Set/Get command permissions.")
|
|
164
164
|
group_user = group.group("user", "Set/Get user's command permissions.")
|
165
165
|
|
166
166
|
group_user.slash("set", "Set user's command permissions.", {
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
167
|
+
"user_id" => {
|
168
|
+
type: :user,
|
169
|
+
description: "The user."
|
170
|
+
},
|
171
|
+
"value" => {
|
172
|
+
type: :boolean,
|
173
|
+
description: "Whether the user can use the command."
|
174
|
+
}
|
175
175
|
}) do |interaction, user|
|
176
176
|
# ...
|
177
177
|
end
|
data/docs/events.md
CHANGED
@@ -79,6 +79,11 @@ Fires when the client is ready.
|
|
79
79
|
|
80
80
|
Fires when the client is resumed connection.
|
81
81
|
|
82
|
+
#### `error(event_name, args, error)`
|
83
|
+
|
84
|
+
Fires when an error occurs during an event.
|
85
|
+
Defaults to printing the error to stderr, override to handle it yourself.
|
86
|
+
|
82
87
|
### Guild events
|
83
88
|
|
84
89
|
#### `guild_join(guild)`
|
data/docs/extension.md
CHANGED
@@ -46,13 +46,13 @@ module MyExtension
|
|
46
46
|
# ...
|
47
47
|
end
|
48
48
|
|
49
|
-
slash_group("group", "Group") do
|
50
|
-
slash("subcommand", "Subcommand") do |interaction|
|
49
|
+
slash_group("group", "Group") do |group|
|
50
|
+
group.slash("subcommand", "Subcommand") do |interaction|
|
51
51
|
# ...
|
52
52
|
end
|
53
53
|
|
54
|
-
group("subgroup", "Subcommand group") do
|
55
|
-
slash("group_subcommand", "Command in Subcommand group") do |interaction|
|
54
|
+
group.group("subgroup", "Subcommand group") do |group|
|
55
|
+
group.slash("group_subcommand", "Command in Subcommand group") do |interaction|
|
56
56
|
# ...
|
57
57
|
end
|
58
58
|
end
|
@@ -86,7 +86,7 @@ module MyExtension
|
|
86
86
|
extend Discorb::Extension
|
87
87
|
|
88
88
|
event :ready do |message|
|
89
|
-
puts "Logged in as #{client.user}"
|
89
|
+
puts "Logged in as #{@client.user}"
|
90
90
|
end
|
91
91
|
end
|
92
92
|
```
|
data/lib/discorb/app_command.rb
CHANGED
@@ -46,8 +46,8 @@ module Discorb
|
|
46
46
|
# @param [String] description Command description.
|
47
47
|
# @param [Array<#to_s>, false, nil] guild_ids Guild IDs to set the command to. `false` to global command, `nil` to use default.
|
48
48
|
#
|
49
|
-
# @yield Block to
|
50
|
-
# @
|
49
|
+
# @yield Block to yield with the command.
|
50
|
+
# @yieldparam [Discorb::ApplicationCommand::Command::GroupCommand] group Group command.
|
51
51
|
#
|
52
52
|
# @return [Discorb::ApplicationCommand::Command::GroupCommand] Command object.
|
53
53
|
#
|
@@ -56,7 +56,7 @@ module Discorb
|
|
56
56
|
#
|
57
57
|
def slash_group(command_name, description, guild_ids: nil, &block)
|
58
58
|
command = Discorb::ApplicationCommand::Command::GroupCommand.new(command_name, description, guild_ids, nil, self)
|
59
|
-
command.
|
59
|
+
command.yield_self(&block) if block_given?
|
60
60
|
@commands << command
|
61
61
|
command
|
62
62
|
end
|
@@ -284,8 +284,8 @@ module Discorb
|
|
284
284
|
# @param [String] command_name Group name.
|
285
285
|
# @param [String] description Group description.
|
286
286
|
#
|
287
|
-
# @yield Block to
|
288
|
-
# @
|
287
|
+
# @yield Block to yield with the command.
|
288
|
+
# @yieldparam [Discorb::ApplicationCommand::Command::SubcommandGroup] group Group command.
|
289
289
|
#
|
290
290
|
# @return [Discorb::ApplicationCommand::Command::SubcommandGroup] Command object.
|
291
291
|
#
|
@@ -293,7 +293,7 @@ module Discorb
|
|
293
293
|
#
|
294
294
|
def group(command_name, description, &block)
|
295
295
|
command = Discorb::ApplicationCommand::Command::SubcommandGroup.new(command_name, description, @name, @client)
|
296
|
-
command.
|
296
|
+
command.yield_self(&block) if block_given?
|
297
297
|
@commands << command
|
298
298
|
command
|
299
299
|
end
|
data/lib/discorb/client.rb
CHANGED
@@ -91,6 +91,7 @@ module Discorb
|
|
91
91
|
@commands = []
|
92
92
|
@bottom_commands = []
|
93
93
|
@status = :initialized
|
94
|
+
set_default_events
|
94
95
|
end
|
95
96
|
|
96
97
|
#
|
@@ -172,23 +173,17 @@ module Discorb
|
|
172
173
|
end
|
173
174
|
@log.debug "Dispatching event #{event_name}"
|
174
175
|
events.each do |block|
|
175
|
-
|
176
|
+
Async do
|
176
177
|
Async(annotation: "Discorb event: #{event_name}") do |task|
|
177
178
|
if block.is_a?(Discorb::Event)
|
178
179
|
@events[event_name].delete(block) if block.metadata[:once]
|
179
180
|
end
|
180
|
-
block.call(*
|
181
|
+
block.call(*args)
|
181
182
|
@log.debug "Dispatched proc with ID #{block.id.inspect}"
|
182
183
|
rescue StandardError, ScriptError => e
|
183
|
-
|
184
|
-
dispatch(:error, event_name, event_args, e)
|
185
|
-
if @log.out
|
186
|
-
@log.error message
|
187
|
-
else
|
188
|
-
warn message
|
189
|
-
end
|
184
|
+
dispatch(:error, event_name, args, e)
|
190
185
|
end
|
191
|
-
|
186
|
+
end
|
192
187
|
end
|
193
188
|
end
|
194
189
|
end
|
@@ -482,5 +477,12 @@ module Discorb
|
|
482
477
|
@main_task.stop
|
483
478
|
end
|
484
479
|
end
|
480
|
+
|
481
|
+
def set_default_events
|
482
|
+
on :error, override: true do |event_name, _args, e|
|
483
|
+
message = "An error occurred while dispatching #{event_name}:\n#{e.full_message}"
|
484
|
+
@log.error message, fallback: $stderr
|
485
|
+
end
|
486
|
+
end
|
485
487
|
end
|
486
488
|
end
|
data/lib/discorb/common.rb
CHANGED
@@ -4,7 +4,7 @@ module Discorb
|
|
4
4
|
# @return [String] The API base URL.
|
5
5
|
API_BASE_URL = "https://discord.com/api/v9"
|
6
6
|
# @return [String] The version of discorb.
|
7
|
-
VERSION = "0.
|
7
|
+
VERSION = "0.7.0"
|
8
8
|
# @return [String] The user agent for the bot.
|
9
9
|
USER_AGENT = "DiscordBot (https://github.com/discorb-lib/discorb #{VERSION}) Ruby/#{RUBY_VERSION}"
|
10
10
|
|
data/lib/discorb/embed.rb
CHANGED
@@ -93,18 +93,18 @@ module Discorb
|
|
93
93
|
# @return [Hash] Converted embed.
|
94
94
|
#
|
95
95
|
def to_hash
|
96
|
-
{
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
96
|
+
ret = { type: "rich" }
|
97
|
+
ret[:title] = @title if @title
|
98
|
+
ret[:description] = @description if @description
|
99
|
+
ret[:url] = @url if @url
|
100
|
+
ret[:timestamp] = @timestamp&.iso8601 if @timestamp
|
101
|
+
ret[:color] = @color&.to_i if @color
|
102
|
+
ret[:footer] = @footer&.to_hash if @footer
|
103
|
+
ret[:image] = @image&.to_hash if @image
|
104
|
+
ret[:thumbnail] = @thumbnail&.to_hash if @thumbnail
|
105
|
+
ret[:author] = @author&.to_hash if @author
|
106
|
+
ret[:fields] = @fields&.map { |f| f.to_hash } if @fields.any?
|
107
|
+
ret
|
108
108
|
end
|
109
109
|
|
110
110
|
#
|
data/lib/discorb/gateway.rb
CHANGED
@@ -53,6 +53,12 @@ module Discorb
|
|
53
53
|
attr_reader :member
|
54
54
|
# @return [Discorb::UnicodeEmoji, Discorb::PartialEmoji] The emoji that was reacted with.
|
55
55
|
attr_reader :emoji
|
56
|
+
# @macro client_cache
|
57
|
+
# @return [Discorb::Member, Discorb::User] The user or member who reacted.
|
58
|
+
attr_reader :fired_by
|
59
|
+
|
60
|
+
alias reactor fired_by
|
61
|
+
alias from fired_by
|
56
62
|
|
57
63
|
# @!visibility private
|
58
64
|
def initialize(client, data)
|
@@ -79,6 +85,8 @@ module Discorb
|
|
79
85
|
end
|
80
86
|
end
|
81
87
|
|
88
|
+
@fired_by = @member || @user || @client.users[data[:user_id]]
|
89
|
+
|
82
90
|
@message = client.messages[data[:message_id]]
|
83
91
|
@emoji = data[:emoji][:id].nil? ? UnicodeEmoji.new(data[:emoji][:name]) : PartialEmoji.new(data[:emoji])
|
84
92
|
end
|
@@ -355,6 +363,9 @@ module Discorb
|
|
355
363
|
class TypingStartEvent < GatewayEvent
|
356
364
|
# @return [Discorb::Snowflake] The ID of the channel the user is typing in.
|
357
365
|
attr_reader :user_id
|
366
|
+
# @macro client_cache
|
367
|
+
# @return [Discorb::Member] The member that is typing.
|
368
|
+
attr_reader :member
|
358
369
|
|
359
370
|
# @!attribute [r] channel
|
360
371
|
# @macro client_cache
|
@@ -365,6 +376,9 @@ module Discorb
|
|
365
376
|
# @!attribute [r] user
|
366
377
|
# @macro client_cache
|
367
378
|
# @return [Discorb::User] The user that is typing.
|
379
|
+
# @!attribute [r] fired_by
|
380
|
+
# @macro client_cache
|
381
|
+
# @return [Discorb::Member, Discorb::User] The member or user that started typing.
|
368
382
|
|
369
383
|
# @!visibility private
|
370
384
|
def initialize(client, data)
|
@@ -388,6 +402,12 @@ module Discorb
|
|
388
402
|
def guild
|
389
403
|
@client.guilds[@guild_id]
|
390
404
|
end
|
405
|
+
|
406
|
+
def fired_by
|
407
|
+
@member || user
|
408
|
+
end
|
409
|
+
|
410
|
+
alias from fired_by
|
391
411
|
end
|
392
412
|
|
393
413
|
#
|
@@ -584,10 +604,10 @@ module Discorb
|
|
584
604
|
@session_id = data[:session_id]
|
585
605
|
@user = ClientUser.new(self, data[:user])
|
586
606
|
@uncached_guilds = data[:guilds].map { |g| g[:id] }
|
587
|
-
if @uncached_guilds == []
|
607
|
+
if @uncached_guilds == [] or !@intents.guilds
|
588
608
|
@ready = true
|
589
609
|
dispatch(:ready)
|
590
|
-
@log.info("
|
610
|
+
@log.info("Successfully connected to Discord.")
|
591
611
|
end
|
592
612
|
@tasks << handle_heartbeat(@heartbeat_interval)
|
593
613
|
when "GUILD_CREATE"
|
@@ -597,7 +617,7 @@ module Discorb
|
|
597
617
|
if @uncached_guilds == []
|
598
618
|
@ready = true
|
599
619
|
dispatch(:ready)
|
600
|
-
@log.info("
|
620
|
+
@log.info("Successfully connected to Discord, and cached all guilds.")
|
601
621
|
end
|
602
622
|
elsif @guilds.has?(data[:id])
|
603
623
|
@guilds[data[:id]].send(:_set_data, data)
|
data/lib/discorb/interaction.rb
CHANGED
data/lib/discorb/log.rb
CHANGED
@@ -22,34 +22,34 @@ module Discorb
|
|
22
22
|
raise ArgumentError, "Invalid log level: #{level}" unless @level
|
23
23
|
end
|
24
24
|
|
25
|
-
def debug(message)
|
25
|
+
def debug(message, fallback: nil)
|
26
26
|
return unless @level <= 0
|
27
27
|
|
28
|
-
write_output("DEBUG", "\e[90m", message)
|
28
|
+
write_output("DEBUG", "\e[90m", message, fallback)
|
29
29
|
end
|
30
30
|
|
31
|
-
def info(message)
|
31
|
+
def info(message, fallback: nil)
|
32
32
|
return unless @level <= 1
|
33
33
|
|
34
|
-
write_output("INFO", "\e[94m", message)
|
34
|
+
write_output("INFO", "\e[94m", message, fallback)
|
35
35
|
end
|
36
36
|
|
37
|
-
def warn(message)
|
37
|
+
def warn(message, fallback: nil)
|
38
38
|
return unless @level <= 2
|
39
39
|
|
40
|
-
write_output("WARN", "\e[93m", message)
|
40
|
+
write_output("WARN", "\e[93m", message, fallback)
|
41
41
|
end
|
42
42
|
|
43
|
-
def error(message)
|
43
|
+
def error(message, fallback: nil)
|
44
44
|
return unless @level <= 3
|
45
45
|
|
46
|
-
write_output("ERROR", "\e[31m", message)
|
46
|
+
write_output("ERROR", "\e[31m", message, fallback)
|
47
47
|
end
|
48
48
|
|
49
|
-
def fatal(message)
|
49
|
+
def fatal(message, fallback: nil)
|
50
50
|
return unless @level <= 4
|
51
51
|
|
52
|
-
write_output("FATAL", "\e[91m", message)
|
52
|
+
write_output("FATAL", "\e[91m", message, fallback)
|
53
53
|
end
|
54
54
|
|
55
55
|
class << self
|
@@ -58,8 +58,12 @@ module Discorb
|
|
58
58
|
|
59
59
|
private
|
60
60
|
|
61
|
-
def write_output(name, color, message)
|
62
|
-
|
61
|
+
def write_output(name, color, message, fallback)
|
62
|
+
unless @out
|
63
|
+
fallback.puts(message) if fallback
|
64
|
+
|
65
|
+
return
|
66
|
+
end
|
63
67
|
|
64
68
|
if @colorize_log
|
65
69
|
@out.puts("\e[2;90m[#{Time.now.iso8601}] #{color}#{name}\e[m -- #{message}")
|
data/lib/discorb/member.rb
CHANGED
@@ -104,7 +104,7 @@ module Discorb
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def roles
|
107
|
-
@role_ids.map { |r| guild.roles[r] }
|
107
|
+
@role_ids.map { |r| guild.roles[r] }.sort_by(&:position)
|
108
108
|
end
|
109
109
|
|
110
110
|
def permissions
|
@@ -234,7 +234,7 @@ module Discorb
|
|
234
234
|
@custom_avatar = member_data[:avatar] && Asset.new(member_data[:avatar])
|
235
235
|
super(user_data)
|
236
236
|
@display_avatar = @avatar || @custom_avatar
|
237
|
-
@client.guilds[@guild_id].members[@id] = self unless @guild_id.nil?
|
237
|
+
@client.guilds[@guild_id].members[@id] = self unless @guild_id.nil? || @client.guilds[@guild_id].nil?
|
238
238
|
@_member_data.update(member_data)
|
239
239
|
end
|
240
240
|
end
|
data/lib/discorb/message.rb
CHANGED
@@ -522,11 +522,11 @@ module Discorb
|
|
522
522
|
if data[:member].nil? && data[:webhook_id]
|
523
523
|
@webhook_id = Snowflake.new(data[:webhook_id])
|
524
524
|
@author = Webhook::Message::Author.new(data[:author])
|
525
|
-
elsif data[:guild_id].nil? || data[:guild_id].empty?
|
525
|
+
elsif data[:guild_id].nil? || data[:guild_id].empty? || data[:member].nil?
|
526
526
|
@author = @client.users[data[:author][:id]] || User.new(@client, data[:author])
|
527
527
|
else
|
528
|
-
@author = guild
|
529
|
-
|
528
|
+
@author = guild&.members&.get(data[:author][:id]) || Member.new(@client,
|
529
|
+
@guild_id, data[:author], data[:member])
|
530
530
|
end
|
531
531
|
@content = data[:content]
|
532
532
|
@created_at = Time.iso8601(data[:timestamp])
|
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.7.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-09-
|
11
|
+
date: 2021-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -82,10 +82,10 @@ files:
|
|
82
82
|
- ".yardopts"
|
83
83
|
- Changelog.md
|
84
84
|
- Gemfile
|
85
|
-
- Gemfile.lock
|
86
85
|
- LICENSE.txt
|
87
86
|
- README.md
|
88
87
|
- Rakefile
|
88
|
+
- assets/banner.svg
|
89
89
|
- bin/console
|
90
90
|
- bin/setup
|
91
91
|
- crowdin.yml
|
data/Gemfile.lock
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
discorb (0.6.1)
|
5
|
-
async (~> 1.30.1)
|
6
|
-
async-http (~> 0.56.5)
|
7
|
-
async-websocket (~> 0.19.0)
|
8
|
-
mime-types (~> 3.3)
|
9
|
-
|
10
|
-
GEM
|
11
|
-
remote: https://rubygems.org/
|
12
|
-
specs:
|
13
|
-
async (1.30.1)
|
14
|
-
console (~> 1.10)
|
15
|
-
nio4r (~> 2.3)
|
16
|
-
timers (~> 4.1)
|
17
|
-
async-http (0.56.5)
|
18
|
-
async (>= 1.25)
|
19
|
-
async-io (>= 1.28)
|
20
|
-
async-pool (>= 0.2)
|
21
|
-
protocol-http (~> 0.22.0)
|
22
|
-
protocol-http1 (~> 0.14.0)
|
23
|
-
protocol-http2 (~> 0.14.0)
|
24
|
-
async-io (1.32.2)
|
25
|
-
async
|
26
|
-
async-pool (0.3.8)
|
27
|
-
async (>= 1.25)
|
28
|
-
async-websocket (0.19.0)
|
29
|
-
async-http (~> 0.54)
|
30
|
-
async-io (~> 1.23)
|
31
|
-
protocol-websocket (~> 0.7.0)
|
32
|
-
console (1.13.1)
|
33
|
-
fiber-local
|
34
|
-
fiber-local (1.0.0)
|
35
|
-
mime-types (3.3.1)
|
36
|
-
mime-types-data (~> 3.2015)
|
37
|
-
mime-types-data (3.2021.0901)
|
38
|
-
nio4r (2.5.8)
|
39
|
-
protocol-hpack (1.4.2)
|
40
|
-
protocol-http (0.22.5)
|
41
|
-
protocol-http1 (0.14.2)
|
42
|
-
protocol-http (~> 0.22)
|
43
|
-
protocol-http2 (0.14.2)
|
44
|
-
protocol-hpack (~> 1.4)
|
45
|
-
protocol-http (~> 0.18)
|
46
|
-
protocol-websocket (0.7.5)
|
47
|
-
protocol-http (~> 0.2)
|
48
|
-
protocol-http1 (~> 0.2)
|
49
|
-
rake (13.0.6)
|
50
|
-
redcarpet (3.5.1)
|
51
|
-
rufo (0.13.0)
|
52
|
-
timers (4.3.3)
|
53
|
-
yard (0.9.26)
|
54
|
-
|
55
|
-
PLATFORMS
|
56
|
-
x86-mingw32
|
57
|
-
x86_64-linux
|
58
|
-
|
59
|
-
DEPENDENCIES
|
60
|
-
discorb!
|
61
|
-
rake (~> 13.0)
|
62
|
-
redcarpet
|
63
|
-
rufo (~> 0.13.0)
|
64
|
-
yard (~> 0.9.26)
|
65
|
-
|
66
|
-
BUNDLED WITH
|
67
|
-
2.2.22
|