discorb 0.8.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +24 -1
- data/README.md +54 -3
- data/assets/banner.svg +101 -125
- data/docs/faq.md +77 -0
- data/docs/license.md +7 -0
- data/lib/discorb/client.rb +25 -8
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/exe/about.rb +1 -1
- data/lib/discorb/exe/run.rb +5 -3
- data/lib/discorb/file.rb +7 -1
- data/lib/discorb/gateway.rb +13 -5
- data/lib/discorb/http.rb +1 -1
- data/lib/discorb/message.rb +49 -0
- data/lib/discorb/modules.rb +2 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b1edef0884cfed1af49f9e0fac34b69330a1b00a23820287ea621b429773c09
|
4
|
+
data.tar.gz: 87e7244d44d9ad963a0579db577b066047643ca16dbc6e2fcb7860bcba8fad28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f54c1eb6a5167e00b2670caf80e04bfa0d5f664e6efff8e731bb6a3c01048961a81c7cfa08a2f2dce5a380defcccd2ccedef0009e8f4d70d7778c811babca7a
|
7
|
+
data.tar.gz: 64d3cce130262a18bb59fdb76715c99e8e7a8574af84b8ebf00e39bb3582cf0e0f9ef4a3c65e1c0af457bbed82568af9f259db0351718ed6e12f83cb5bb95bab
|
data/Changelog.md
CHANGED
@@ -211,4 +211,27 @@ end
|
|
211
211
|
- Add: Add `Intents#to_h`
|
212
212
|
- Add: Add `fetch_member` parameter to `Client#initialize`; Note you should set `false` if your bot doesn't have `GUILD_MEMBERS` intent
|
213
213
|
- Change: Change `ready` to `standby` event
|
214
|
-
- Change: `ready` will be fired when client receives `READY` event
|
214
|
+
- Change: `ready` will be fired when client receives `READY` event
|
215
|
+
|
216
|
+
## 0.8.1
|
217
|
+
|
218
|
+
- Add: Add FAQ
|
219
|
+
- Fix: Fix sending files
|
220
|
+
- Add: Add `File.from_string`
|
221
|
+
- Fix: Fix `Client#update_presence`
|
222
|
+
- Add: Add information in `discorb run -d`
|
223
|
+
|
224
|
+
## 0.8.2
|
225
|
+
|
226
|
+
- Fix: Fix `Client#initialize`
|
227
|
+
|
228
|
+
## 0.9.0
|
229
|
+
|
230
|
+
- Delete: Delete `-d` parameter from `discorb run`; This is caused by segement fault error.
|
231
|
+
- Change: Rename `-t`, `--token` to `-e`, `--env` parameter
|
232
|
+
- Add: Add `-t`, `--title` parameter to `discorb run`
|
233
|
+
- Add: Add `title` parameter to `Client#initialize`
|
234
|
+
|
235
|
+
## 0.9.1
|
236
|
+
|
237
|
+
- Fix: Fix member fetching
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
![discorb](./assets/banner.svg)
|
2
2
|
|
3
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>
|
4
|
+
<a href="https://rubygems.org/gems/discorb"><img src="https://img.shields.io/gem/dt/discorb?logo=rubygems&logoColor=fff&label=Downloads" alt="Gem"></a>
|
5
|
+
<a href="https://rubygems.org/gems/discorb"><img src="https://img.shields.io/gem/v/discorb?logo=rubygems&logoColor=fff&label=Version" alt="Gem"></a>
|
6
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
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
8
|
|
@@ -28,7 +28,7 @@ Or install it yourself as:
|
|
28
28
|
|
29
29
|
## Usage
|
30
30
|
|
31
|
-
###
|
31
|
+
### Ping & Pong
|
32
32
|
|
33
33
|
```ruby
|
34
34
|
require "discorb"
|
@@ -49,6 +49,57 @@ end
|
|
49
49
|
client.run(ENV["DISCORD_BOT_TOKEN"])
|
50
50
|
```
|
51
51
|
|
52
|
+
### Quiz Game
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
require "discorb"
|
56
|
+
|
57
|
+
client = Discorb::Client.new
|
58
|
+
|
59
|
+
client.once :standby do
|
60
|
+
puts "Logged in as #{client.user}"
|
61
|
+
end
|
62
|
+
|
63
|
+
client.on :message do |message|
|
64
|
+
next if message.author.bot?
|
65
|
+
next unless message.content == "!quiz"
|
66
|
+
|
67
|
+
operator = [:+, :-, :*].sample
|
68
|
+
num1 = rand(1..10)
|
69
|
+
num2 = rand(1..10)
|
70
|
+
|
71
|
+
val = num1.send(operator, num2)
|
72
|
+
message.channel.post("Quiz: `#{num1} #{operator} #{num2}`")
|
73
|
+
begin
|
74
|
+
msg = client.event_lock(:message, 30) { |m|
|
75
|
+
m.content == val.to_s && m.channel == message.channel
|
76
|
+
}.wait
|
77
|
+
rescue Discorb::TimeoutError
|
78
|
+
message.channel.post("No one answered...")
|
79
|
+
else
|
80
|
+
msg.reply("Correct!")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
client.run(ENV["DISCORD_BOT_TOKEN"])
|
85
|
+
```
|
86
|
+
|
87
|
+
### Slash Commands
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
require "discorb"
|
91
|
+
|
92
|
+
client = Discorb::Client.new
|
93
|
+
|
94
|
+
client.slash("hello", "Greet for you") do |interaction|
|
95
|
+
interaction.post("Hello!", ephemeral: true)
|
96
|
+
end
|
97
|
+
|
98
|
+
client.run(ENV["DISCORD_BOT_TOKEN"])
|
99
|
+
```
|
100
|
+
|
101
|
+
Note: You must run `discorb setup` before using slash commands.
|
102
|
+
|
52
103
|
## Contributing
|
53
104
|
|
54
105
|
Bug reports and pull requests are welcome on GitHub at https://github.com/discorb-lib/discorb.
|
data/assets/banner.svg
CHANGED
@@ -1,125 +1,101 @@
|
|
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
|
-
<
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
</g>
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
<
|
63
|
-
<
|
64
|
-
|
65
|
-
|
66
|
-
<
|
67
|
-
<
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
</g>
|
99
|
-
|
100
|
-
</g>
|
101
|
-
|
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>
|
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
|
+
<rect x="0" fill="#FFFFFF" width="1080" height="150"/>
|
7
|
+
<g>
|
8
|
+
<g>
|
9
|
+
<defs>
|
10
|
+
<rect id="SVGID_1_" x="283.667" y="-12.667" width="343.333" height="201.333"/>
|
11
|
+
</defs>
|
12
|
+
<clipPath id="SVGID_2_">
|
13
|
+
<use xlink:href="#SVGID_1_" overflow="visible"/>
|
14
|
+
</clipPath>
|
15
|
+
<g clip-path="url(#SVGID_2_)">
|
16
|
+
<g>
|
17
|
+
<g>
|
18
|
+
<path fill="#2E3338" d="M370.532,119.061c-13.503,0-21.564-10.312-21.564-27.582c0-18.542,9.872-30.524,25.148-30.524
|
19
|
+
c5.187,0,10.446,0.915,14.433,2.509l3.429,1.372V31.79l6.393-1.006v86.997h-4.456l-1.936-12.146l-3.522,4.209
|
20
|
+
C383.265,116.045,377.402,119.061,370.532,119.061z M374.501,65.554c-9.191,0-19.014,6.676-19.014,25.413
|
21
|
+
c0,13.961,6.56,22.98,16.708,22.98c7.181,0,13.309-3.736,19.286-11.758l0.495-0.666V69.983l-1.358-0.697
|
22
|
+
C385.253,66.53,381.034,65.554,374.501,65.554z"/>
|
23
|
+
</g>
|
24
|
+
<g>
|
25
|
+
<path fill="#2E3338" d="M419.623,117.779V61.721h6.394v56.058H419.623z M422.884,44.433c-2.646,0-4.796-2.094-4.796-4.668
|
26
|
+
c0-2.6,2.195-4.796,4.796-4.796c2.573,0,4.668,2.152,4.668,4.796C427.552,42.338,425.457,44.433,422.884,44.433z"/>
|
27
|
+
</g>
|
28
|
+
<g>
|
29
|
+
<path fill="#2E3338" d="M463.332,119.061c-7.016,0-14.662-2.281-19.529-4.646l0.809-5.23
|
30
|
+
c4.905,2.795,11.627,5.405,19.616,5.405c9.34,0,14.917-3.948,14.917-10.563c0-8.188-6.482-10.383-16.372-12.797
|
31
|
+
c-13.937-3.485-18.19-7.314-18.19-16.389c0-8.611,7.639-14.397,19.006-14.397c6.173,0,11.984,1.055,17.305,3.139l-0.902,5.412
|
32
|
+
c-5.417-2.532-11.33-3.95-16.659-3.95c-12.06,0-12.997,7.302-12.997,9.54c0,6.303,5.57,8.979,14.56,11.256
|
33
|
+
c15.329,3.896,20.003,7.967,20.003,17.418C484.897,113.3,477.036,119.061,463.332,119.061z"/>
|
34
|
+
</g>
|
35
|
+
<g>
|
36
|
+
<path fill="#2E3338" d="M523.745,119.061c-15.985,0-25.917-11.205-25.917-29.246c0-17.842,10.273-29.373,26.174-29.373
|
37
|
+
c6.896,0,12.695,1.453,17.263,4.322l-0.821,5.493c-5.086-3.282-10.44-4.83-16.57-4.83c-12.043,0-19.524,9.296-19.524,24.262
|
38
|
+
c0,15.271,7.776,24.389,20.805,24.389c6.138,0,11.114-1.451,15.996-4.758l0.746,4.591
|
39
|
+
C536.669,117.51,531.15,119.061,523.745,119.061z"/>
|
40
|
+
</g>
|
41
|
+
<g>
|
42
|
+
<path fill="#2E3338" d="M580.834,119.061c-15.512,0-25.533-11.479-25.533-29.246c0-17.842,10.021-29.373,25.533-29.373
|
43
|
+
c15.743,0,25.916,11.53,25.916,29.373C606.75,107.581,596.577,119.061,580.834,119.061z M580.834,65.042
|
44
|
+
c-11.729,0-19.015,9.492-19.015,24.772c0,15.049,7.463,24.772,19.015,24.772c11.964,0,19.396-9.491,19.396-24.772
|
45
|
+
C600.23,74.766,592.616,65.042,580.834,65.042z"/>
|
46
|
+
</g>
|
47
|
+
<g>
|
48
|
+
<path d="M623.652,117.779V61.721h4.444l2.615,16.91l3.563-5.661c3.16-5.019,8.634-11.016,17.176-12.309l0.981,5.953
|
49
|
+
c-9.187,1.447-17.664,7.67-22.117,16.437l-0.271,0.533v34.195H623.652L623.652,117.779z"/>
|
50
|
+
</g>
|
51
|
+
<g>
|
52
|
+
<path d="M688.224,118.549c-8.271,0-14.268-1.167-21.311-3.208V31.79l6.394-1.006V72.56l4.295-4.43
|
53
|
+
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.549
|
54
|
+
z M692.447,65.554c-6.539,0-12.794,3.675-18.593,10.922l-0.548,0.686v33.855l1.64,0.602c3.981,1.461,7.108,2.201,13.148,2.201
|
55
|
+
c9.607,0,21.062-4.387,21.062-25.284C709.156,74.575,702.598,65.554,692.447,65.554z"/>
|
56
|
+
</g>
|
57
|
+
</g>
|
58
|
+
</g>
|
59
|
+
</g>
|
60
|
+
</g>
|
61
|
+
<g>
|
62
|
+
<g>
|
63
|
+
<defs>
|
64
|
+
<rect id="SVGID_3_" x="610.334" y="8" width="268" height="246"/>
|
65
|
+
</defs>
|
66
|
+
<clipPath id="SVGID_4_">
|
67
|
+
<use xlink:href="#SVGID_3_" overflow="visible"/>
|
68
|
+
</clipPath>
|
69
|
+
<g clip-path="url(#SVGID_4_)">
|
70
|
+
<g>
|
71
|
+
<path fill="#2E3338" d="M391.781,120.279l-1.408-8.832c-4.607,5.505-10.88,10.113-19.841,10.113
|
72
|
+
c-13.185,0-24.064-9.602-24.064-30.082c0-22.272,12.8-33.025,27.648-33.025c6.018,0,11.521,1.152,15.361,2.688v-31.49
|
73
|
+
l11.393-1.792v92.42H391.781L391.781,120.279z M389.478,71.51c-4.736-2.432-8.448-3.456-14.977-3.456
|
74
|
+
c-9.602,0-16.514,7.809-16.514,22.913c0,13.441,6.017,20.48,14.208,20.48c7.041,0,12.417-4.225,17.281-10.752L389.478,71.51
|
75
|
+
L389.478,71.51z"/>
|
76
|
+
<path fill="#2E3338" d="M422.884,46.933c-3.968,0-7.296-3.2-7.296-7.168c0-3.968,3.328-7.296,7.296-7.296
|
77
|
+
s7.168,3.328,7.168,7.296C430.052,43.733,426.852,46.933,422.884,46.933z M417.123,120.279V59.221h11.394v61.058H417.123z"/>
|
78
|
+
<path fill="#2E3338" d="M463.332,121.561c-8.064,0-17.025-2.815-22.273-5.76l1.664-10.754c5.76,3.969,13.185,7.041,21.505,7.041
|
79
|
+
c7.808,0,12.417-2.943,12.417-8.064c0-5.633-3.456-7.68-14.465-10.367c-14.336-3.586-20.098-7.938-20.098-18.817
|
80
|
+
c0-9.729,8.192-16.897,21.506-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
|
81
|
+
c-6.913,0-10.498,2.688-10.498,7.04c0,4.096,3.072,6.4,12.673,8.832c15.104,3.841,21.889,8.193,21.889,19.842
|
82
|
+
C487.397,114.393,479.076,121.561,463.332,121.561z"/>
|
83
|
+
<path fill="#2E3338" d="M523.745,121.561c-16.385,0-28.417-11.393-28.417-31.746c0-20.864,12.801-31.873,28.674-31.873
|
84
|
+
c8.96,0,15.359,2.304,19.968,5.632l-1.664,11.136c-5.632-4.608-11.393-6.784-18.433-6.784c-9.984,0-17.024,7.552-17.024,21.761
|
85
|
+
c0,14.849,7.552,21.89,18.305,21.89c6.146,0,11.521-1.408,17.793-6.785l1.664,10.241
|
86
|
+
C538.339,119.768,531.938,121.561,523.745,121.561z"/>
|
87
|
+
<path fill="#2E3338" d="M580.834,121.561c-16.259,0-28.033-11.647-28.033-31.746c0-20.096,11.774-31.873,28.033-31.873
|
88
|
+
c16.385,0,28.416,11.776,28.416,31.873C609.25,109.912,597.219,121.561,580.834,121.561z M580.834,67.542
|
89
|
+
c-11.01,0-16.515,9.472-16.515,22.272c0,12.545,5.761,22.272,16.515,22.272c11.264,0,16.896-9.474,16.896-22.272
|
90
|
+
C597.73,77.271,591.842,67.542,580.834,67.542z"/>
|
91
|
+
<path fill="#CC342D" d="M632.545,84.184v36.098h-11.394v-61.06h9.088l1.92,12.417c4.354-6.913,11.394-13.185,21.377-13.697
|
92
|
+
l1.793,10.88C645.217,69.334,636.641,76.118,632.545,84.184z"/>
|
93
|
+
<path fill="#CC342D" d="M688.224,121.049c-9.217,0-15.745-1.408-23.811-3.841V29.652l11.394-1.792v38.53
|
94
|
+
c4.096-4.224,9.984-8.448,18.305-8.448c13.186,0,24.065,9.729,24.065,30.082C718.177,110.296,705.888,121.049,688.224,121.049z
|
95
|
+
M692.447,68.054c-6.399,0-12.032,4.224-16.641,9.984v31.233c3.84,1.408,6.656,2.049,12.288,2.049
|
96
|
+
c11.905,0,18.562-7.041,18.562-22.785C706.656,75.222,700.64,68.054,692.447,68.054z"/>
|
97
|
+
</g>
|
98
|
+
</g>
|
99
|
+
</g>
|
100
|
+
</g>
|
101
|
+
</svg>
|
data/docs/faq.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# @title FAQ
|
2
|
+
|
3
|
+
# Fequently asked questions
|
4
|
+
|
5
|
+
## What is `Async::Task`?
|
6
|
+
|
7
|
+
Async::Task is a object for asynchronous tasks.
|
8
|
+
|
9
|
+
https://socketry.github.io/async/ for more information.
|
10
|
+
|
11
|
+
## How do I do something with sent messages?
|
12
|
+
|
13
|
+
Use `Async::Task#wait` method.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
# NG
|
17
|
+
message = channel.post("Hello world!") # => Async::Task
|
18
|
+
message.pin # => NoMethodError
|
19
|
+
|
20
|
+
# OK
|
21
|
+
message = channel.post("Hello world!").wait # => Message
|
22
|
+
message.pin
|
23
|
+
```
|
24
|
+
|
25
|
+
## How can I send DM to a user?
|
26
|
+
|
27
|
+
Use {Discorb::User#post} method, {Discorb::User} includes {Discorb::Messageable}.
|
28
|
+
|
29
|
+
## How can I edit status?
|
30
|
+
|
31
|
+
Use {Discorb::Client#update_presence} method.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
%i[standby guild_join guild_leave].each do |event|
|
35
|
+
client.on event do
|
36
|
+
client.update_presence(
|
37
|
+
Discorb::Activity.new(
|
38
|
+
name: "#{client.guilds.length} Servers"
|
39
|
+
),
|
40
|
+
status: :online
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
client.on :ready do
|
46
|
+
client.update_presence(status: :dnd)
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
## How can I send files?
|
51
|
+
|
52
|
+
Use {Discorb::File} class.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
# Send a file
|
56
|
+
message.channel.post file: Discorb::File.new(File.open("./README.md"))
|
57
|
+
|
58
|
+
# Send some files with text
|
59
|
+
message.channel.post "File!", files: [Discorb::File.new(File.open("./README.md")), Discorb::File.new(File.open("./License.txt"))]
|
60
|
+
|
61
|
+
# Send a string as a file
|
62
|
+
message.channel.post file: Discorb::File.from_string("Hello world!", "hello.txt")
|
63
|
+
```
|
64
|
+
|
65
|
+
# Not fequently asked questions
|
66
|
+
|
67
|
+
## How can I pronounce `discorb`?
|
68
|
+
|
69
|
+
Discorb is pronounced `disco-R-B`.
|
70
|
+
|
71
|
+
## Why did you make `discorb`?
|
72
|
+
|
73
|
+
There are many reasons -- One is I didn't like `discordrb`'s `bot.message` -- but the main reason is, "Just for Fun".
|
74
|
+
|
75
|
+
## How was `discorb` named?
|
76
|
+
|
77
|
+
`discord` and `.rb`.
|
data/docs/license.md
ADDED
data/lib/discorb/client.rb
CHANGED
@@ -5,6 +5,7 @@ require "logger"
|
|
5
5
|
|
6
6
|
require "async"
|
7
7
|
require "async/websocket/client"
|
8
|
+
require_relative "./utils/colored_puts"
|
8
9
|
|
9
10
|
module Discorb
|
10
11
|
#
|
@@ -64,13 +65,14 @@ module Discorb
|
|
64
65
|
# @param [Boolean] colorize_log Whether to colorize the log.
|
65
66
|
# @param [:debug, :info, :warn, :error, :critical] log_level The log level.
|
66
67
|
# @param [Boolean] wait_until_ready Whether to delay event dispatch until ready.
|
67
|
-
# @param [Boolean] fetch_member Whether to fetch member on ready. This may slow down the client.
|
68
|
-
#
|
68
|
+
# @param [Boolean] fetch_member Whether to fetch member on ready. This may slow down the client. Default to `false`.
|
69
|
+
# @param [String] title The title of the process. `false` to default, `nil` to `discorb: User#0000`. Default to `nil`.
|
69
70
|
#
|
70
71
|
def initialize(
|
71
72
|
allowed_mentions: nil, intents: nil, message_caches: 1000,
|
72
73
|
log: nil, colorize_log: false, log_level: :info,
|
73
|
-
wait_until_ready: true, fetch_member:
|
74
|
+
wait_until_ready: true, fetch_member: false,
|
75
|
+
title: nil
|
74
76
|
)
|
75
77
|
@allowed_mentions = allowed_mentions || AllowedMentions.new(everyone: true, roles: true, users: true)
|
76
78
|
@intents = (intents or Intents.default)
|
@@ -93,7 +95,8 @@ module Discorb
|
|
93
95
|
@commands = []
|
94
96
|
@bottom_commands = []
|
95
97
|
@status = :initialized
|
96
|
-
@fetch_member = fetch_member
|
98
|
+
@fetch_member = fetch_member
|
99
|
+
@title = title
|
97
100
|
set_default_events
|
98
101
|
end
|
99
102
|
|
@@ -302,9 +305,15 @@ module Discorb
|
|
302
305
|
#
|
303
306
|
# @param [Discorb::Activity] activity The activity to update.
|
304
307
|
# @param [:online, :idle, :dnd, :invisible] status The status to update.
|
305
|
-
#
|
306
|
-
|
307
|
-
|
308
|
+
# @param [String] afk Whether to set the client as AFK.
|
309
|
+
#
|
310
|
+
def update_presence(activity = nil, status: nil, afk: false)
|
311
|
+
payload = {
|
312
|
+
activities: [],
|
313
|
+
status: status,
|
314
|
+
afk: nil,
|
315
|
+
since: nil,
|
316
|
+
}
|
308
317
|
if !activity.nil?
|
309
318
|
payload[:activities] = [activity.to_hash]
|
310
319
|
end
|
@@ -408,7 +417,8 @@ module Discorb
|
|
408
417
|
when "run"
|
409
418
|
require "json"
|
410
419
|
options = JSON.parse(ENV["DISCORB_CLI_OPTIONS"], symbolize_names: true)
|
411
|
-
|
420
|
+
@daemon = options[:daemon]
|
421
|
+
|
412
422
|
setup_commands(token) if options[:setup]
|
413
423
|
if options[:log_level]
|
414
424
|
if options[:log_level] == "none"
|
@@ -486,6 +496,13 @@ module Discorb
|
|
486
496
|
message = "An error occurred while dispatching #{event_name}:\n#{e.full_message}"
|
487
497
|
@log.error message, fallback: $stderr
|
488
498
|
end
|
499
|
+
|
500
|
+
once :standby do
|
501
|
+
next if @title == false
|
502
|
+
|
503
|
+
title = @title || ENV["DISCORB_CLI_TITLE"] || "discorb: #{@user}"
|
504
|
+
Process.setproctitle title
|
505
|
+
end
|
489
506
|
end
|
490
507
|
end
|
491
508
|
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.9.1"
|
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/exe/about.rb
CHANGED
data/lib/discorb/exe/run.rb
CHANGED
@@ -16,14 +16,13 @@ opt = OptionParser.new <<~BANNER
|
|
16
16
|
script The script to run. Defaults to 'main.rb'.
|
17
17
|
BANNER
|
18
18
|
options = {
|
19
|
-
|
19
|
+
title: nil,
|
20
20
|
log_level: nil,
|
21
21
|
log_file: nil,
|
22
22
|
log_color: nil,
|
23
23
|
setup: nil,
|
24
24
|
token: false,
|
25
25
|
}
|
26
|
-
opt.on("-d", "--deamon", "Run as a daemon.") { |v| options[:daemon] = v }
|
27
26
|
opt.on("-l", "--log-level LEVEL", "Log level.") do |v|
|
28
27
|
unless LOG_LEVELS.include? v.downcase
|
29
28
|
eputs "Invalid log level: \e[31m#{v}\e[91m"
|
@@ -35,7 +34,8 @@ end
|
|
35
34
|
opt.on("-f", "--log-file FILE", "File to write log to.") { |v| options[:log_file] = v }
|
36
35
|
opt.on("-c", "--[no-]log-color", "Whether to colorize log output.") { |v| options[:log_color] = v }
|
37
36
|
opt.on("-s", "--setup", "Whether to setup application commands.") { |v| options[:setup] = v }
|
38
|
-
opt.on("-
|
37
|
+
opt.on("-e", "--env [ENV]", "The name of the environment variable to use for token, or just `-e` or `--env` for intractive prompt.") { |v| options[:token] = v }
|
38
|
+
opt.on("-t", "--title TITLE", "The title of process.") { |v| options[:title] = v }
|
39
39
|
opt.parse!(ARGV)
|
40
40
|
|
41
41
|
script = ARGV[0]
|
@@ -54,6 +54,8 @@ elsif options[:token].nil? || options[:token] == "-"
|
|
54
54
|
puts ""
|
55
55
|
end
|
56
56
|
|
57
|
+
ENV["DISCORB_CLI_TITLE"] = options[:title]
|
58
|
+
|
57
59
|
begin
|
58
60
|
load script
|
59
61
|
rescue LoadError
|
data/lib/discorb/file.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "mime/types"
|
4
|
+
require "stringio"
|
4
5
|
|
5
6
|
module Discorb
|
6
7
|
#
|
@@ -62,8 +63,13 @@ module Discorb
|
|
62
63
|
def initialize(io, filename = nil, content_type: nil)
|
63
64
|
@io = io
|
64
65
|
@filename = filename || (io.respond_to?(:path) ? io.path : io.object_id)
|
65
|
-
@content_type = content_type || MIME::Types.type_for(@filename)[0].to_s
|
66
|
+
@content_type = content_type || MIME::Types.type_for(@filename.to_s)[0].to_s
|
66
67
|
@content_type = "application/octet-stream" if @content_type == ""
|
67
68
|
end
|
69
|
+
|
70
|
+
def self.from_string(string, filename: nil, content_type: nil)
|
71
|
+
io = StringIO.new(string)
|
72
|
+
new(io, filename, content_type: content_type)
|
73
|
+
end
|
68
74
|
end
|
69
75
|
end
|
data/lib/discorb/gateway.rb
CHANGED
@@ -499,9 +499,17 @@ module Discorb
|
|
499
499
|
while (message = @connection.read)
|
500
500
|
@buffer << message
|
501
501
|
if message.end_with?((+"\x00\x00\xff\xff").force_encoding("ASCII-8BIT"))
|
502
|
-
|
503
|
-
|
504
|
-
|
502
|
+
begin
|
503
|
+
data = @zlib_stream.inflate(@buffer)
|
504
|
+
@buffer = +""
|
505
|
+
message = JSON.parse(data, symbolize_names: true)
|
506
|
+
rescue JSON::ParserError
|
507
|
+
@buffer = +""
|
508
|
+
@log.error "Received invalid JSON from gateway."
|
509
|
+
@log.debug data
|
510
|
+
else
|
511
|
+
handle_gateway(message)
|
512
|
+
end
|
505
513
|
end
|
506
514
|
end
|
507
515
|
end
|
@@ -526,7 +534,7 @@ module Discorb
|
|
526
534
|
def send_gateway(opcode, **value)
|
527
535
|
@connection.write({ op: opcode, d: value }.to_json)
|
528
536
|
@connection.flush
|
529
|
-
@log.debug "Sent message
|
537
|
+
@log.debug "Sent message: #{{ op: opcode, d: value }.to_json.gsub(@token, "[Token]")}"
|
530
538
|
end
|
531
539
|
|
532
540
|
def handle_gateway(payload)
|
@@ -1034,7 +1042,7 @@ module Discorb
|
|
1034
1042
|
guild.fetch_members
|
1035
1043
|
end
|
1036
1044
|
end
|
1037
|
-
|
1045
|
+
barrier.wait
|
1038
1046
|
end
|
1039
1047
|
@ready = true
|
1040
1048
|
dispatch(:standby)
|
data/lib/discorb/http.rb
CHANGED
@@ -221,7 +221,7 @@ module Discorb
|
|
221
221
|
{ "User-Agent" => USER_AGENT, "authorization" => "Bot #{@client.token}",
|
222
222
|
"content-type" => "application/json" }
|
223
223
|
end
|
224
|
-
ret.merge(headers) if !headers.nil? && headers.length.positive?
|
224
|
+
ret.merge!(headers) if !headers.nil? && headers.length.positive?
|
225
225
|
ret["X-Audit-Log-Reason"] = audit_log_reason unless audit_log_reason.nil?
|
226
226
|
ret
|
227
227
|
end
|
data/lib/discorb/message.rb
CHANGED
@@ -213,6 +213,55 @@ module Discorb
|
|
213
213
|
!@updated_at.nil?
|
214
214
|
end
|
215
215
|
|
216
|
+
#
|
217
|
+
# Removes the mentions from the message.
|
218
|
+
#
|
219
|
+
# @param [Boolean] user Whether to clean user mentions.
|
220
|
+
# @param [Boolean] channel Whether to clean channel mentions.
|
221
|
+
# @param [Boolean] role Whether to clean role mentions.
|
222
|
+
# @param [Boolean] emoji Whether to clean emoji.
|
223
|
+
# @param [Boolean] everyone Whether to clean `@everyone` and `@here`.
|
224
|
+
# @param [Boolean] codeblock Whether to clean codeblocks.
|
225
|
+
#
|
226
|
+
# @return [String] The cleaned content of the message.
|
227
|
+
#
|
228
|
+
def clean_content(user: true, channel: true, role: true, emoji: true, everyone: true, codeblock: false)
|
229
|
+
ret = @content.dup
|
230
|
+
ret.gsub!(/<@!?(\d+)>/) do |match|
|
231
|
+
member = guild&.members&.[]($1)
|
232
|
+
member ||= @client.users[$1]
|
233
|
+
member ? "@#{member.name}" : "@Unknown User"
|
234
|
+
end if user
|
235
|
+
ret.gsub!(/<#(\d+)>/) do |match|
|
236
|
+
channel = @client.channels[$1]
|
237
|
+
channel ? "<##{channel.id}>" : "#Unknown Channel"
|
238
|
+
end
|
239
|
+
ret.gsub!(/<@&(\d+)>/) do |match|
|
240
|
+
role = guild&.roles&.[]($1)
|
241
|
+
role ? "@#{role.name}" : "@Unknown Role"
|
242
|
+
end if role
|
243
|
+
ret.gsub!(/<a?:([a-zA-Z0-9_]+):\d+>/) do |match|
|
244
|
+
$1
|
245
|
+
end if emoji
|
246
|
+
ret.gsub!(/@(everyone|here)/, "@\u200b\\1") if everyone
|
247
|
+
unless codeblock
|
248
|
+
codeblocks = ret.split("```", -1)
|
249
|
+
original_codeblocks = @content.scan(/```(.+?)```/m)
|
250
|
+
res = []
|
251
|
+
max = codeblocks.length
|
252
|
+
codeblocks.each_with_index do |codeblock, i|
|
253
|
+
if max % 2 == 0 && i == max - 1 or i.even?
|
254
|
+
res << codeblock
|
255
|
+
else
|
256
|
+
res << original_codeblocks[i / 2]
|
257
|
+
end
|
258
|
+
end
|
259
|
+
res.join("```")
|
260
|
+
else
|
261
|
+
ret
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
216
265
|
#
|
217
266
|
# Edit the message.
|
218
267
|
#
|
data/lib/discorb/modules.rb
CHANGED
@@ -59,7 +59,8 @@ module Discorb
|
|
59
59
|
end
|
60
60
|
files = [file] if file
|
61
61
|
if files
|
62
|
-
|
62
|
+
seperator, payload = HTTP.multipart(payload, files)
|
63
|
+
headers = { "content-type" => "multipart/form-data; boundary=#{seperator}" }
|
63
64
|
else
|
64
65
|
headers = {}
|
65
66
|
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.9.1
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -109,6 +109,8 @@ files:
|
|
109
109
|
- docs/cli/setup.md
|
110
110
|
- docs/events.md
|
111
111
|
- docs/extension.md
|
112
|
+
- docs/faq.md
|
113
|
+
- docs/license.md
|
112
114
|
- docs/tutorial.md
|
113
115
|
- docs/voice_events.md
|
114
116
|
- examples/commands/bookmarker.rb
|