discordrb 3.4.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +44 -18
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -1
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -1
- data/.github/workflows/codeql.yml +65 -0
- data/.markdownlint.json +4 -0
- data/.rubocop.yml +8 -2
- data/CHANGELOG.md +419 -222
- data/LICENSE.txt +1 -1
- data/README.md +37 -25
- data/discordrb-webhooks.gemspec +4 -1
- data/discordrb.gemspec +9 -6
- data/lib/discordrb/api/application.rb +202 -0
- data/lib/discordrb/api/channel.rb +182 -11
- data/lib/discordrb/api/interaction.rb +54 -0
- data/lib/discordrb/api/invite.rb +2 -2
- data/lib/discordrb/api/server.rb +42 -19
- data/lib/discordrb/api/user.rb +9 -3
- data/lib/discordrb/api/webhook.rb +57 -0
- data/lib/discordrb/api.rb +19 -5
- data/lib/discordrb/bot.rb +328 -33
- data/lib/discordrb/cache.rb +27 -22
- data/lib/discordrb/commands/command_bot.rb +14 -7
- data/lib/discordrb/commands/container.rb +1 -1
- data/lib/discordrb/commands/parser.rb +2 -2
- data/lib/discordrb/commands/rate_limiter.rb +1 -1
- data/lib/discordrb/container.rb +132 -3
- data/lib/discordrb/data/activity.rb +8 -1
- data/lib/discordrb/data/attachment.rb +15 -0
- data/lib/discordrb/data/audit_logs.rb +3 -3
- data/lib/discordrb/data/channel.rb +167 -23
- data/lib/discordrb/data/component.rb +229 -0
- data/lib/discordrb/data/integration.rb +42 -3
- data/lib/discordrb/data/interaction.rb +800 -0
- data/lib/discordrb/data/invite.rb +2 -2
- data/lib/discordrb/data/member.rb +108 -33
- data/lib/discordrb/data/message.rb +100 -20
- data/lib/discordrb/data/overwrite.rb +13 -7
- data/lib/discordrb/data/role.rb +58 -1
- data/lib/discordrb/data/server.rb +82 -80
- data/lib/discordrb/data/user.rb +69 -9
- data/lib/discordrb/data/webhook.rb +97 -4
- data/lib/discordrb/data.rb +3 -0
- data/lib/discordrb/errors.rb +44 -3
- data/lib/discordrb/events/channels.rb +1 -1
- data/lib/discordrb/events/interactions.rb +482 -0
- data/lib/discordrb/events/message.rb +9 -6
- data/lib/discordrb/events/presence.rb +21 -14
- data/lib/discordrb/events/reactions.rb +0 -1
- data/lib/discordrb/events/threads.rb +96 -0
- data/lib/discordrb/gateway.rb +30 -17
- data/lib/discordrb/permissions.rb +59 -34
- data/lib/discordrb/version.rb +1 -1
- data/lib/discordrb/voice/encoder.rb +13 -4
- data/lib/discordrb/voice/network.rb +18 -7
- data/lib/discordrb/voice/sodium.rb +3 -1
- data/lib/discordrb/voice/voice_bot.rb +3 -3
- data/lib/discordrb/webhooks.rb +2 -0
- data/lib/discordrb.rb +37 -4
- metadata +53 -19
- data/.codeclimate.yml +0 -16
- data/.travis.yml +0 -32
- data/bin/travis_build_docs.sh +0 -17
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,24 +1,25 @@
|
|
1
|
+
# discordrb
|
2
|
+
|
1
3
|
[![Gem](https://img.shields.io/gem/v/discordrb.svg)](https://rubygems.org/gems/discordrb)
|
2
4
|
[![Gem](https://img.shields.io/gem/dt/discordrb.svg)](https://rubygems.org/gems/discordrb)
|
3
5
|
[![CircleCI](https://circleci.com/gh/shardlab/discordrb.svg?style=svg)](https://circleci.com/gh/shardlab/discordrb)
|
4
|
-
[![Inline docs](
|
6
|
+
[![Inline docs](https://inch-ci.org/github/shardlab/discordrb.svg?branch=main)](https://drb.shardlab.dev/v3.4.0/)
|
5
7
|
[![Join Discord](https://img.shields.io/badge/discord-join-7289DA.svg)](https://discord.gg/cyK3Hjm)
|
6
|
-
# discordrb
|
7
8
|
|
8
9
|
An implementation of the [Discord](https://discord.com/) API using Ruby.
|
9
10
|
|
10
11
|
## Quick links to sections
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
- [Introduction](https://github.com/shardlab/discordrb#introduction)
|
14
|
+
- [Dependencies](https://github.com/shardlab/discordrb#dependencies)
|
15
|
+
- [Installation](https://github.com/shardlab/discordrb#installation)
|
16
|
+
- [Usage](https://github.com/shardlab/discordrb#usage)
|
17
|
+
- [Webhooks Client](https://github.com/shardlab/discordrb#webhooks-client)
|
18
|
+
- [Support](https://github.com/shardlab/discordrb#support)
|
19
|
+
- [Development](https://github.com/shardlab/discordrb#development), [Contributing](https://github.com/shardlab/discordrb#contributing)
|
20
|
+
- [License](https://github.com/shardlab/discordrb#license)
|
20
21
|
|
21
|
-
See also: [Documentation](https://
|
22
|
+
See also: [Documentation](https://drb.shardlab.dev/v3.4.0/), [Tutorials](https://github.com/shardlab/discordrb/wiki)
|
22
23
|
|
23
24
|
## Introduction
|
24
25
|
|
@@ -43,15 +44,16 @@ If you enjoy using the library, consider getting involved with the community to
|
|
43
44
|
|
44
45
|
## Dependencies
|
45
46
|
|
46
|
-
* Ruby >= 2.
|
47
|
+
* Ruby >= 2.7 supported
|
47
48
|
* An installed build system for native extensions (on Windows, make sure you download the "Ruby+Devkit" version of [RubyInstaller](https://rubyinstaller.org/downloads/))
|
48
49
|
|
49
50
|
### Voice dependencies
|
50
51
|
|
51
52
|
This section only applies to you if you want to use voice functionality.
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
|
54
|
+
- [libsodium](https://github.com/shardlab/discordrb/wiki/Installing-libsodium)
|
55
|
+
- A compiled libopus distribution for your system, anywhere the script can find it. See [here](https://github.com/shardlab/discordrb/wiki/Installing-libopus) for installation instructions.
|
56
|
+
- [FFmpeg](https://www.ffmpeg.org/download.html) installed and in your PATH
|
55
57
|
|
56
58
|
## Installation
|
57
59
|
|
@@ -59,15 +61,19 @@ This section only applies to you if you want to use voice functionality.
|
|
59
61
|
|
60
62
|
Using [Bundler](https://bundler.io/#getting-started), you can add discordrb to your Gemfile:
|
61
63
|
|
62
|
-
|
64
|
+
```ruby
|
65
|
+
gem 'discordrb'
|
66
|
+
```
|
63
67
|
|
64
68
|
And then install via `bundle install`.
|
65
69
|
|
66
|
-
Run the [ping example](https://github.com/shardlab/discordrb/blob/
|
70
|
+
Run the [ping example](https://github.com/shardlab/discordrb/blob/main/examples/ping.rb) to verify that the installation works (make sure to replace the token and client ID in there with your bots'!):
|
67
71
|
|
68
72
|
To run the bot while using bundler:
|
69
73
|
|
70
|
-
|
74
|
+
```sh
|
75
|
+
bundle exec ruby ping.rb
|
76
|
+
```
|
71
77
|
|
72
78
|
### With Gem
|
73
79
|
|
@@ -75,21 +81,27 @@ Alternatively, while Bundler is the recommended option, you can also install dis
|
|
75
81
|
|
76
82
|
#### Linux / macOS
|
77
83
|
|
78
|
-
|
84
|
+
```sh
|
85
|
+
gem install discordrb
|
86
|
+
```
|
79
87
|
|
80
88
|
#### Windows
|
81
89
|
|
82
90
|
> **Make sure you have the DevKit installed! See the [Dependencies](https://github.com/shardlab/discordrb#dependencies) section)**
|
83
91
|
|
84
|
-
|
92
|
+
```sh
|
93
|
+
gem install discordrb --platform=ruby
|
94
|
+
```
|
85
95
|
|
86
96
|
To run the bot:
|
87
97
|
|
88
|
-
|
98
|
+
```sh
|
99
|
+
ruby ping.rb
|
100
|
+
```
|
89
101
|
|
90
102
|
### Installation Troubleshooting
|
91
103
|
|
92
|
-
See https://github.com/shardlab/discordrb/wiki/FAQ#installation for a list of common problems and solutions when installing `discordrb`.
|
104
|
+
See <https://github.com/shardlab/discordrb/wiki/FAQ#installation> for a list of common problems and solutions when installing `discordrb`.
|
93
105
|
|
94
106
|
## Usage
|
95
107
|
|
@@ -109,7 +121,7 @@ bot.run
|
|
109
121
|
|
110
122
|
This bot responds to every "Ping!" with a "Pong!".
|
111
123
|
|
112
|
-
See [additional examples here](https://github.com/shardlab/discordrb/tree/
|
124
|
+
See [additional examples here](https://github.com/shardlab/discordrb/tree/main/examples).
|
113
125
|
|
114
126
|
You can find examples of projects that use discordrb by [searching for the discordrb topic on GitHub](https://github.com/topics/discordrb).
|
115
127
|
|
@@ -119,7 +131,7 @@ If you've made an open source project on GitHub that uses discordrb, consider ad
|
|
119
131
|
|
120
132
|
Also included is a webhooks client, which can be used as a separate gem `discordrb-webhooks`. This special client can be used to form requests to Discord webhook URLs in a high-level manner.
|
121
133
|
|
122
|
-
- [`discordrb-webhooks` documentation](https://
|
134
|
+
- [`discordrb-webhooks` documentation](https://drb.shardlab.dev/v3.4.0/Discordrb/Webhooks.html)
|
123
135
|
- [More information about webhooks](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks)
|
124
136
|
- [Embed visualizer tool](https://leovoel.github.io/embed-visualizer/) - Includes a discordrb code generator for forming embeds
|
125
137
|
|
@@ -153,7 +165,7 @@ If you need help or have a question, you can:
|
|
153
165
|
## Contributing
|
154
166
|
|
155
167
|
Thank you for your interest in contributing!
|
156
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/shardlab/discordrb
|
168
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/shardlab/discordrb>.
|
157
169
|
|
158
170
|
In general, we recommend starting by discussing what you would like to contribute in the [Discord channel](https://discord.gg/cyK3Hjm).
|
159
171
|
There are usually a handful of people working on things for the library, and what you're looking for may already be on the way.
|
data/discordrb-webhooks.gemspec
CHANGED
data/discordrb.gemspec
CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.bindir = 'exe'
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.metadata = {
|
22
|
-
'changelog_uri' => 'https://github.com/shardlab/discordrb/blob/
|
22
|
+
'changelog_uri' => 'https://github.com/shardlab/discordrb/blob/main/CHANGELOG.md',
|
23
|
+
'rubygems_mfa_required' => 'true'
|
23
24
|
}
|
24
25
|
spec.require_paths = ['lib']
|
25
26
|
|
@@ -28,17 +29,19 @@ Gem::Specification.new do |spec|
|
|
28
29
|
spec.add_dependency 'rest-client', '>= 2.0.0'
|
29
30
|
spec.add_dependency 'websocket-client-simple', '>= 0.3.0'
|
30
31
|
|
31
|
-
spec.add_dependency 'discordrb-webhooks', '~> 3.
|
32
|
+
spec.add_dependency 'discordrb-webhooks', '~> 3.5.0'
|
32
33
|
|
33
|
-
spec.required_ruby_version = '>= 2.
|
34
|
+
spec.required_ruby_version = '>= 2.7'
|
34
35
|
|
35
36
|
spec.add_development_dependency 'bundler', '>= 1.10', '< 3'
|
36
37
|
spec.add_development_dependency 'rake', '~> 13.0'
|
37
38
|
spec.add_development_dependency 'redcarpet', '~> 3.5.0' # YARD markdown formatting
|
38
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
39
|
+
spec.add_development_dependency 'rspec', '~> 3.11.0'
|
40
|
+
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.5.1'
|
39
41
|
spec.add_development_dependency 'rspec-prof', '~> 0.0.7'
|
40
|
-
spec.add_development_dependency 'rubocop', '~> 1.
|
42
|
+
spec.add_development_dependency 'rubocop', '~> 1.36.0'
|
41
43
|
spec.add_development_dependency 'rubocop-performance', '~> 1.0'
|
42
|
-
spec.add_development_dependency '
|
44
|
+
spec.add_development_dependency 'rubocop-rake', '~> 0.6.0'
|
45
|
+
spec.add_development_dependency 'simplecov', '~> 0.21.0'
|
43
46
|
spec.add_development_dependency 'yard', '~> 0.9.9'
|
44
47
|
end
|
@@ -0,0 +1,202 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# API calls for slash commands.
|
4
|
+
module Discordrb::API::Application
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# Get a list of global application commands.
|
8
|
+
# https://discord.com/developers/docs/interactions/slash-commands#get-global-application-commands
|
9
|
+
def get_global_commands(token, application_id)
|
10
|
+
Discordrb::API.request(
|
11
|
+
:applications_aid_commands,
|
12
|
+
nil,
|
13
|
+
:get,
|
14
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/commands",
|
15
|
+
Authorization: token
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Get a global application command by ID.
|
20
|
+
# https://discord.com/developers/docs/interactions/slash-commands#get-global-application-command
|
21
|
+
def get_global_command(token, application_id, command_id)
|
22
|
+
Discordrb::API.request(
|
23
|
+
:applications_aid_commands_cid,
|
24
|
+
nil,
|
25
|
+
:get,
|
26
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/commands/#{command_id}",
|
27
|
+
Authorization: token
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Create a global application command.
|
32
|
+
# https://discord.com/developers/docs/interactions/slash-commands#create-global-application-command
|
33
|
+
def create_global_command(token, application_id, name, description, options = [], default_permission = nil, type = 1)
|
34
|
+
Discordrb::API.request(
|
35
|
+
:applications_aid_commands,
|
36
|
+
nil,
|
37
|
+
:post,
|
38
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/commands",
|
39
|
+
{ name: name, description: description, options: options, default_permission: default_permission, type: type }.to_json,
|
40
|
+
Authorization: token,
|
41
|
+
content_type: :json
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Edit a global application command.
|
46
|
+
# https://discord.com/developers/docs/interactions/slash-commands#edit-global-application-command
|
47
|
+
def edit_global_command(token, application_id, command_id, name = nil, description = nil, options = nil, default_permission = nil, type = 1)
|
48
|
+
Discordrb::API.request(
|
49
|
+
:applications_aid_commands_cid,
|
50
|
+
nil,
|
51
|
+
:patch,
|
52
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/commands/#{command_id}",
|
53
|
+
{ name: name, description: description, options: options, default_permission: default_permission, type: type }.compact.to_json,
|
54
|
+
Authorization: token,
|
55
|
+
content_type: :json
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Delete a global application command.
|
60
|
+
# https://discord.com/developers/docs/interactions/slash-commands#delete-global-application-command
|
61
|
+
def delete_global_command(token, application_id, command_id)
|
62
|
+
Discordrb::API.request(
|
63
|
+
:applications_aid_commands_cid,
|
64
|
+
nil,
|
65
|
+
:delete,
|
66
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/commands/#{command_id}",
|
67
|
+
Authorization: token
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Set global application commands in bulk.
|
72
|
+
# https://discord.com/developers/docs/interactions/slash-commands#bulk-overwrite-global-application-commands
|
73
|
+
def bulk_overwrite_global_commands(token, application_id, commands)
|
74
|
+
Discordrb::API.request(
|
75
|
+
:applications_aid_commands,
|
76
|
+
nil,
|
77
|
+
:put,
|
78
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/commands",
|
79
|
+
commands.to_json,
|
80
|
+
Authorization: token,
|
81
|
+
content_type: :json
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Get a guild's commands for an application.
|
86
|
+
# https://discord.com/developers/docs/interactions/slash-commands#get-guild-application-commands
|
87
|
+
def get_guild_commands(token, application_id, guild_id)
|
88
|
+
Discordrb::API.request(
|
89
|
+
:applications_aid_guilds_gid_commands,
|
90
|
+
guild_id,
|
91
|
+
:get,
|
92
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands",
|
93
|
+
Authorization: token
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Get a guild command by ID.
|
98
|
+
# https://discord.com/developers/docs/interactions/slash-commands#get-guild-application-command
|
99
|
+
def get_guild_command(token, application_id, guild_id, command_id)
|
100
|
+
Discordrb::API.request(
|
101
|
+
:applications_aid_guilds_gid_commands_cid,
|
102
|
+
guild_id,
|
103
|
+
:get,
|
104
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands/#{command_id}",
|
105
|
+
Authorization: token
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Create an application command for a guild.
|
110
|
+
# https://discord.com/developers/docs/interactions/slash-commands#create-guild-application-command
|
111
|
+
def create_guild_command(token, application_id, guild_id, name, description, options = nil, default_permission = nil, type = 1)
|
112
|
+
Discordrb::API.request(
|
113
|
+
:applications_aid_guilds_gid_commands,
|
114
|
+
guild_id,
|
115
|
+
:post,
|
116
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands",
|
117
|
+
{ name: name, description: description, options: options, default_permission: default_permission, type: type }.to_json,
|
118
|
+
Authorization: token,
|
119
|
+
content_type: :json
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Edit an application command for a guild.
|
124
|
+
# https://discord.com/developers/docs/interactions/slash-commands#edit-guild-application-command
|
125
|
+
def edit_guild_command(token, application_id, guild_id, command_id, name = nil, description = nil, options = nil, default_permission = nil, type = 1)
|
126
|
+
Discordrb::API.request(
|
127
|
+
:applications_aid_guilds_gid_commands_cid,
|
128
|
+
guild_id,
|
129
|
+
:patch,
|
130
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands/#{command_id}",
|
131
|
+
{ name: name, description: description, options: options, default_permission: default_permission, type: type }.compact.to_json,
|
132
|
+
Authorization: token,
|
133
|
+
content_type: :json
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Delete an application command for a guild.
|
138
|
+
# https://discord.com/developers/docs/interactions/slash-commands#delete-guild-application-command
|
139
|
+
def delete_guild_command(token, application_id, guild_id, command_id)
|
140
|
+
Discordrb::API.request(
|
141
|
+
:applications_aid_guilds_gid_commands_cid,
|
142
|
+
guild_id,
|
143
|
+
:delete,
|
144
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands/#{command_id}",
|
145
|
+
Authorization: token
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
149
|
+
# Set guild commands in bulk.
|
150
|
+
# https://discord.com/developers/docs/interactions/slash-commands#bulk-overwrite-guild-application-commands
|
151
|
+
def bulk_overwrite_guild_commands(token, application_id, guild_id, commands)
|
152
|
+
Discordrb::API.request(
|
153
|
+
:applications_aid_guilds_gid_commands,
|
154
|
+
guild_id,
|
155
|
+
:put,
|
156
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands",
|
157
|
+
commands.to_json,
|
158
|
+
Authorization: token,
|
159
|
+
content_type: :json
|
160
|
+
)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Get the permissions for a specific guild command.
|
164
|
+
# https://discord.com/developers/docs/interactions/slash-commands#get-application-command-permissions
|
165
|
+
def get_guild_command_permissions(token, application_id, guild_id)
|
166
|
+
Discordrb::API.request(
|
167
|
+
:applications_aid_guilds_gid_commands_permissions,
|
168
|
+
guild_id,
|
169
|
+
:get,
|
170
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands/permissions",
|
171
|
+
Authorization: token
|
172
|
+
)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Edit the permissions for a specific guild command.
|
176
|
+
# https://discord.com/developers/docs/interactions/slash-commands#edit-application-command-permissions
|
177
|
+
def edit_guild_command_permissions(token, application_id, guild_id, command_id, permissions)
|
178
|
+
Discordrb::API.request(
|
179
|
+
:applications_aid_guilds_gid_commands_cid_permissions,
|
180
|
+
guild_id,
|
181
|
+
:put,
|
182
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands/#{command_id}/permissions",
|
183
|
+
{ permissions: permissions }.to_json,
|
184
|
+
Authorization: token,
|
185
|
+
content_type: :json
|
186
|
+
)
|
187
|
+
end
|
188
|
+
|
189
|
+
# Edit permissions for all commands in a guild.
|
190
|
+
# https://discord.com/developers/docs/interactions/slash-commands#batch-edit-application-command-permissions
|
191
|
+
def batch_edit_command_permissions(token, application_id, guild_id, permissions)
|
192
|
+
Discordrb::API.request(
|
193
|
+
:applications_aid_guilds_gid_commands_cid_permissions,
|
194
|
+
guild_id,
|
195
|
+
:put,
|
196
|
+
"#{Discordrb::API.api_base}/applications/#{application_id}/guilds/#{guild_id}/commands/permissions",
|
197
|
+
permissions.to_json,
|
198
|
+
Authorization: token,
|
199
|
+
content_type: :json
|
200
|
+
)
|
201
|
+
end
|
202
|
+
end
|