discorb 0.7.6 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build_version.yml +53 -0
- data/Changelog.md +10 -1
- data/README.md +1 -1
- data/docs/events.md +8 -4
- data/docs/tutorial.md +1 -1
- data/examples/commands/bookmarker.rb +1 -1
- data/examples/commands/inspect.rb +1 -1
- data/examples/components/authorization_button.rb +1 -1
- data/examples/components/select_menu.rb +1 -1
- data/examples/extension/main.rb +1 -1
- data/examples/simple/eval.rb +1 -1
- data/examples/simple/ping_pong.rb +1 -1
- data/examples/simple/rolepanel.rb +1 -1
- data/examples/simple/wait_for_message.rb +1 -1
- data/lib/discorb/client.rb +4 -1
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/error.rb +3 -1
- data/lib/discorb/exe/init.rb +1 -1
- data/lib/discorb/exe/irb.rb +1 -1
- data/lib/discorb/flag.rb +1 -0
- data/lib/discorb/gateway.rb +26 -6
- data/lib/discorb/guild.rb +33 -1
- data/lib/discorb/http.rb +4 -3
- data/lib/discorb/intents.rb +7 -3
- data/po/yard.pot +1 -1
- data/sig/discorb.rbs +7217 -7217
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb2e5dd94a2bda9644a1a5679fdab3006bbdb1b10c8bf3780764b7fc115aa002
|
4
|
+
data.tar.gz: 4bfd645c6e39a4f3bd48ed2b2afaaccc8c2cf5702eb6dc675cfb01b17667b09f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c18b4e0b809e66350c952a8d50cb2e4f899e2844cd33b43bfd6120cc4560c6889e2cc8015fe9729ecb84c1af26a434ac566f69baa1a58cfcc5b6e2232b41151
|
7
|
+
data.tar.gz: de89179dffd53f575e148c2240d278eb101dde91f8f2288c9cefcae403eb4ce2f04547a030bebb3912d33df639e8e516c92878d6eb1fe1650cde8dc4c6903d25
|
@@ -0,0 +1,53 @@
|
|
1
|
+
name: Build YARD by version
|
2
|
+
|
3
|
+
on:
|
4
|
+
workflow_dispatch:
|
5
|
+
push:
|
6
|
+
tags:
|
7
|
+
- "v*"
|
8
|
+
jobs:
|
9
|
+
main:
|
10
|
+
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
with:
|
16
|
+
fetch-depth: 0
|
17
|
+
- name: Set up Ruby
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: 3.0.2
|
21
|
+
bundler-cache: true
|
22
|
+
- name: Set up git settings
|
23
|
+
run: |
|
24
|
+
git config --global user.email "action@github.com"
|
25
|
+
git config --global user.name "GitHub Action"
|
26
|
+
- name: Clone pages
|
27
|
+
env:
|
28
|
+
SSH_SECRET: ${{ secrets.SSH }}
|
29
|
+
GIT_SSH_COMMAND: ssh -i ~/ssh_secret
|
30
|
+
run: |
|
31
|
+
echo "$SSH_SECRET" > ~/ssh_secret
|
32
|
+
chmod 600 ~/ssh_secret
|
33
|
+
git clone git@github.com:discorb-lib/discorb-lib.github.io /tmp/pages
|
34
|
+
- name: Install dependencies
|
35
|
+
run: |
|
36
|
+
bundle config --local with 'docs'
|
37
|
+
bundle install
|
38
|
+
- name: Generate document
|
39
|
+
run: bundle exec rake document:build_all
|
40
|
+
- name: Push document
|
41
|
+
env:
|
42
|
+
SSH_SECRET: ${{ secrets.SSH }}
|
43
|
+
GIT_SSH_COMMAND: ssh -i ~/ssh_secret
|
44
|
+
run: |
|
45
|
+
echo "$SSH_SECRET" > ~/ssh_secret
|
46
|
+
chmod 600 ~/ssh_secret
|
47
|
+
cp -r ./doc/. /tmp/pages
|
48
|
+
cd /tmp/pages
|
49
|
+
git add -A
|
50
|
+
git commit -m "Update: Update document"
|
51
|
+
git update-ref -d refs/remotes/origin/user
|
52
|
+
git push origin main -f
|
53
|
+
continue-on-error: true
|
data/Changelog.md
CHANGED
@@ -202,4 +202,13 @@ end
|
|
202
202
|
|
203
203
|
## 0.7.6
|
204
204
|
|
205
|
-
- Fix: Fix heartbeating error
|
205
|
+
- Fix: Fix heartbeating error
|
206
|
+
|
207
|
+
## 0.8.0
|
208
|
+
|
209
|
+
- Add: Add `Guild#fetch_members`
|
210
|
+
- Add: Add `Guild#fetch_member_list` as alias of `Guild#fetch_members`
|
211
|
+
- Add: Add `Intents#to_h`
|
212
|
+
- Add: Add `fetch_member` parameter to `Client#initialize`; Note you should set `false` if your bot doesn't have `GUILD_MEMBERS` intent
|
213
|
+
- Change: Change `ready` to `standby` event
|
214
|
+
- Change: `ready` will be fired when client receives `READY` event
|
data/README.md
CHANGED
data/docs/events.md
CHANGED
@@ -22,7 +22,7 @@ Since v0.2.5, you can also register event handlers by adding a method to the cli
|
|
22
22
|
client = Discorb::Client.new
|
23
23
|
|
24
24
|
class << client
|
25
|
-
def
|
25
|
+
def on_standby
|
26
26
|
puts "Ready!"
|
27
27
|
end
|
28
28
|
end
|
@@ -43,7 +43,7 @@ end
|
|
43
43
|
```
|
44
44
|
|
45
45
|
This example will print `Override!`, but not `This event handler is overrideable!`.
|
46
|
-
This is useful for registering event handlers
|
46
|
+
This is useful for registering event handlers as default behaviour, such as error handlers.
|
47
47
|
|
48
48
|
```ruby
|
49
49
|
# In the library...
|
@@ -55,7 +55,7 @@ end
|
|
55
55
|
# In your code...
|
56
56
|
|
57
57
|
client.on :command_error do |event, error|
|
58
|
-
event.message.reply "An error occurred while executing
|
58
|
+
event.message.reply "An error occurred while executing the command!\n#{error.full_message}"
|
59
59
|
end
|
60
60
|
```
|
61
61
|
|
@@ -73,7 +73,11 @@ Fires when a event is received.
|
|
73
73
|
|
74
74
|
#### `ready()`
|
75
75
|
|
76
|
-
Fires when the client
|
76
|
+
Fires when the client receives the `READY` event.
|
77
|
+
|
78
|
+
#### `standby()`
|
79
|
+
|
80
|
+
Fires when the client is standby. (When the client connects to Discord, and has cached guilds and members.)
|
77
81
|
|
78
82
|
#### `resumed()`
|
79
83
|
|
data/docs/tutorial.md
CHANGED
@@ -101,7 +101,7 @@ Dotenv.load # Loads .env file
|
|
101
101
|
|
102
102
|
client = Discorb::Client.new # Create client for connecting to Discord
|
103
103
|
|
104
|
-
client.once :
|
104
|
+
client.once :standby do
|
105
105
|
puts "Logged in as #{client.user}" # Prints username of logged in user
|
106
106
|
end
|
107
107
|
|
data/examples/extension/main.rb
CHANGED
data/examples/simple/eval.rb
CHANGED
data/lib/discorb/client.rb
CHANGED
@@ -64,11 +64,13 @@ module Discorb
|
|
64
64
|
# @param [Boolean] colorize_log Whether to colorize the log.
|
65
65
|
# @param [:debug, :info, :warn, :error, :critical] log_level The log level.
|
66
66
|
# @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
|
+
# Defaultly, it's `false` if {Discorb::Intents#members} is false. Otherwise, it's `true`.
|
67
69
|
#
|
68
70
|
def initialize(
|
69
71
|
allowed_mentions: nil, intents: nil, message_caches: 1000,
|
70
72
|
log: nil, colorize_log: false, log_level: :info,
|
71
|
-
wait_until_ready: true
|
73
|
+
wait_until_ready: true, fetch_member: nil
|
72
74
|
)
|
73
75
|
@allowed_mentions = allowed_mentions || AllowedMentions.new(everyone: true, roles: true, users: true)
|
74
76
|
@intents = (intents or Intents.default)
|
@@ -91,6 +93,7 @@ module Discorb
|
|
91
93
|
@commands = []
|
92
94
|
@bottom_commands = []
|
93
95
|
@status = :initialized
|
96
|
+
@fetch_member = fetch_member.nil? ? !(intents&.members) : fetch_member
|
94
97
|
set_default_events
|
95
98
|
end
|
96
99
|
|
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.8.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/error.rb
CHANGED
@@ -92,10 +92,12 @@ module Discorb
|
|
92
92
|
def initialize(resp, client)
|
93
93
|
@client = client
|
94
94
|
@client.close!
|
95
|
-
|
95
|
+
message = <<~MESSAGE
|
96
96
|
The client is banned from CloudFlare.
|
97
97
|
Hint: Try to decrease the number of requests per second, e.g. Use sleep in between requests.
|
98
98
|
MESSAGE
|
99
|
+
$stderr.puts message
|
100
|
+
DiscorbError.instance_method(:initialize).bind(self).call(message)
|
99
101
|
end
|
100
102
|
end
|
101
103
|
|
data/lib/discorb/exe/init.rb
CHANGED
data/lib/discorb/exe/irb.rb
CHANGED
data/lib/discorb/flag.rb
CHANGED
data/lib/discorb/gateway.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require "async/http"
|
4
4
|
require "async/websocket"
|
5
|
+
require "async/barrier"
|
6
|
+
require "async/semaphore"
|
5
7
|
require "json"
|
6
8
|
require "zlib"
|
7
9
|
|
@@ -610,19 +612,17 @@ module Discorb
|
|
610
612
|
@user = ClientUser.new(self, data[:user])
|
611
613
|
@uncached_guilds = data[:guilds].map { |g| g[:id] }
|
612
614
|
if @uncached_guilds == [] or !@intents.guilds
|
613
|
-
|
614
|
-
dispatch(:ready)
|
615
|
-
@log.info("Successfully connected to Discord.")
|
615
|
+
ready
|
616
616
|
end
|
617
|
+
dispatch(:ready)
|
617
618
|
@tasks << handle_heartbeat
|
618
619
|
when "GUILD_CREATE"
|
619
620
|
if @uncached_guilds.include?(data[:id])
|
620
621
|
Guild.new(self, data, true)
|
621
622
|
@uncached_guilds.delete(data[:id])
|
622
623
|
if @uncached_guilds == []
|
623
|
-
@
|
624
|
-
|
625
|
-
@log.info("Successfully connected to Discord, and cached all guilds.")
|
624
|
+
@log.debug "All guilds cached"
|
625
|
+
ready
|
626
626
|
end
|
627
627
|
elsif @guilds.has?(data[:id])
|
628
628
|
@guilds[data[:id]].send(:_set_data, data)
|
@@ -1021,6 +1021,26 @@ module Discorb
|
|
1021
1021
|
end
|
1022
1022
|
end
|
1023
1023
|
end
|
1024
|
+
|
1025
|
+
def ready
|
1026
|
+
Async do
|
1027
|
+
if @fetch_member
|
1028
|
+
@log.debug "Fetching members"
|
1029
|
+
barrier = Async::Barrier.new
|
1030
|
+
semaphore = Async::Semaphore.new(@guilds.length)
|
1031
|
+
|
1032
|
+
@guilds.each do |guild|
|
1033
|
+
semaphore.async(parent: barrier) do
|
1034
|
+
guild.fetch_members
|
1035
|
+
end
|
1036
|
+
end
|
1037
|
+
semaphore.__send__(:wait)
|
1038
|
+
end
|
1039
|
+
@ready = true
|
1040
|
+
dispatch(:standby)
|
1041
|
+
@log.info("Client is ready!")
|
1042
|
+
end
|
1043
|
+
end
|
1024
1044
|
end
|
1025
1045
|
|
1026
1046
|
#
|
data/lib/discorb/guild.rb
CHANGED
@@ -502,7 +502,6 @@ module Discorb
|
|
502
502
|
# Fetch a member in the guild.
|
503
503
|
# @macro async
|
504
504
|
# @macro http
|
505
|
-
# @macro members_intent
|
506
505
|
#
|
507
506
|
# @param [#to_s] id The ID of the member to fetch.
|
508
507
|
#
|
@@ -519,6 +518,39 @@ module Discorb
|
|
519
518
|
end
|
520
519
|
end
|
521
520
|
|
521
|
+
# Fetch members in the guild.
|
522
|
+
# @macro async
|
523
|
+
# @macro http
|
524
|
+
# @macro members_intent
|
525
|
+
#
|
526
|
+
# @param [Integer] limit The maximum number of members to fetch, 0 for all.
|
527
|
+
# @param [Integer] after The ID of the member to start fetching after.
|
528
|
+
#
|
529
|
+
# @return [Async::Task<Array<Discorb::Member>>] The list of members.
|
530
|
+
#
|
531
|
+
def fetch_members(limit: 0, after: nil)
|
532
|
+
Async do
|
533
|
+
unless limit == 0
|
534
|
+
_resp, data = @client.http.get("/guilds/#{@id}/members?#{URI.encode_www_form({ after: after, limit: limit })}").wait
|
535
|
+
next data[:members].map { |m| Member.new(@client, @id, m[:user], m) }
|
536
|
+
end
|
537
|
+
ret = []
|
538
|
+
after = 0
|
539
|
+
loop do
|
540
|
+
params = { after: after, limit: 100 }
|
541
|
+
_resp, data = @client.http.get("/guilds/#{@id}/members?#{URI.encode_www_form(params)}").wait
|
542
|
+
ret += data.map { |m| Member.new(@client, @id, m[:user], m) }
|
543
|
+
after = data.last[:user][:id]
|
544
|
+
if data.length != 1000
|
545
|
+
break
|
546
|
+
end
|
547
|
+
end
|
548
|
+
ret
|
549
|
+
end
|
550
|
+
end
|
551
|
+
|
552
|
+
alias fetch_member_list fetch_members
|
553
|
+
|
522
554
|
#
|
523
555
|
# Search for members by name in the guild.
|
524
556
|
# @macro async
|
data/lib/discorb/http.rb
CHANGED
@@ -242,12 +242,13 @@ module Discorb
|
|
242
242
|
else
|
243
243
|
API_BASE_URL + path
|
244
244
|
end
|
245
|
-
URI(full_path)
|
245
|
+
uri = URI(full_path)
|
246
|
+
full_path.sub(uri.scheme + "://" + uri.host, "")
|
246
247
|
end
|
247
248
|
|
248
249
|
def get_response_data(resp)
|
249
|
-
if resp["Via"].nil?
|
250
|
-
raise CloudFlareBanError.new(@client
|
250
|
+
if resp["Via"].nil? && resp.code == "429"
|
251
|
+
raise CloudFlareBanError.new(resp, @client)
|
251
252
|
end
|
252
253
|
rd = resp.body
|
253
254
|
if rd.nil? || rd.empty?
|
data/lib/discorb/intents.rb
CHANGED
@@ -82,7 +82,7 @@ module Discorb
|
|
82
82
|
if @raw_value.key?(name)
|
83
83
|
@raw_value[name]
|
84
84
|
elsif name.end_with?("=") && @raw_value.key?(name[0..-2].to_sym)
|
85
|
-
raise ArgumentError, "true/false expected"
|
85
|
+
raise ArgumentError, "true/false expected" unless args.is_a? TrueClass or args.is_a?(FalseClass)
|
86
86
|
|
87
87
|
@raw_value[name[0..-2].to_sym] = args
|
88
88
|
else
|
@@ -108,6 +108,10 @@ module Discorb
|
|
108
108
|
"#<#{self.class} value=#{value}>"
|
109
109
|
end
|
110
110
|
|
111
|
+
def to_h
|
112
|
+
@raw_value
|
113
|
+
end
|
114
|
+
|
111
115
|
class << self
|
112
116
|
# Create new intent object from raw value.
|
113
117
|
# @param value [Integer] The value of the intent.
|
@@ -121,12 +125,12 @@ module Discorb
|
|
121
125
|
|
122
126
|
# Create new intent object with default values.
|
123
127
|
def default
|
124
|
-
from_value(
|
128
|
+
from_value(32509)
|
125
129
|
end
|
126
130
|
|
127
131
|
# Create new intent object with all intents.
|
128
132
|
def all
|
129
|
-
from_value(
|
133
|
+
from_value(32767)
|
130
134
|
end
|
131
135
|
|
132
136
|
# Create new intent object with no intents.
|