discordrb 3.3.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +152 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +24 -0
  5. data/.github/pull_request_template.md +37 -0
  6. data/.github/workflows/codeql.yml +65 -0
  7. data/.markdownlint.json +4 -0
  8. data/.rubocop.yml +39 -36
  9. data/CHANGELOG.md +874 -552
  10. data/Gemfile +2 -0
  11. data/LICENSE.txt +1 -1
  12. data/README.md +80 -86
  13. data/Rakefile +2 -0
  14. data/bin/console +1 -0
  15. data/discordrb-webhooks.gemspec +9 -6
  16. data/discordrb.gemspec +21 -18
  17. data/lib/discordrb/allowed_mentions.rb +36 -0
  18. data/lib/discordrb/api/application.rb +202 -0
  19. data/lib/discordrb/api/channel.rb +236 -47
  20. data/lib/discordrb/api/interaction.rb +54 -0
  21. data/lib/discordrb/api/invite.rb +5 -5
  22. data/lib/discordrb/api/server.rb +94 -66
  23. data/lib/discordrb/api/user.rb +17 -11
  24. data/lib/discordrb/api/webhook.rb +63 -6
  25. data/lib/discordrb/api.rb +55 -16
  26. data/lib/discordrb/await.rb +0 -1
  27. data/lib/discordrb/bot.rb +480 -93
  28. data/lib/discordrb/cache.rb +31 -24
  29. data/lib/discordrb/colour_rgb.rb +43 -0
  30. data/lib/discordrb/commands/command_bot.rb +35 -12
  31. data/lib/discordrb/commands/container.rb +21 -24
  32. data/lib/discordrb/commands/parser.rb +20 -20
  33. data/lib/discordrb/commands/rate_limiter.rb +4 -3
  34. data/lib/discordrb/container.rb +209 -20
  35. data/lib/discordrb/data/activity.rb +271 -0
  36. data/lib/discordrb/data/application.rb +50 -0
  37. data/lib/discordrb/data/attachment.rb +71 -0
  38. data/lib/discordrb/data/audit_logs.rb +345 -0
  39. data/lib/discordrb/data/channel.rb +993 -0
  40. data/lib/discordrb/data/component.rb +229 -0
  41. data/lib/discordrb/data/embed.rb +251 -0
  42. data/lib/discordrb/data/emoji.rb +82 -0
  43. data/lib/discordrb/data/integration.rb +122 -0
  44. data/lib/discordrb/data/interaction.rb +800 -0
  45. data/lib/discordrb/data/invite.rb +137 -0
  46. data/lib/discordrb/data/member.rb +372 -0
  47. data/lib/discordrb/data/message.rb +414 -0
  48. data/lib/discordrb/data/overwrite.rb +108 -0
  49. data/lib/discordrb/data/profile.rb +91 -0
  50. data/lib/discordrb/data/reaction.rb +33 -0
  51. data/lib/discordrb/data/recipient.rb +34 -0
  52. data/lib/discordrb/data/role.rb +248 -0
  53. data/lib/discordrb/data/server.rb +1004 -0
  54. data/lib/discordrb/data/user.rb +264 -0
  55. data/lib/discordrb/data/voice_region.rb +45 -0
  56. data/lib/discordrb/data/voice_state.rb +41 -0
  57. data/lib/discordrb/data/webhook.rb +238 -0
  58. data/lib/discordrb/data.rb +28 -4180
  59. data/lib/discordrb/errors.rb +46 -4
  60. data/lib/discordrb/events/bans.rb +7 -5
  61. data/lib/discordrb/events/channels.rb +3 -1
  62. data/lib/discordrb/events/guilds.rb +16 -9
  63. data/lib/discordrb/events/interactions.rb +482 -0
  64. data/lib/discordrb/events/invites.rb +125 -0
  65. data/lib/discordrb/events/members.rb +6 -2
  66. data/lib/discordrb/events/message.rb +72 -27
  67. data/lib/discordrb/events/presence.rb +35 -18
  68. data/lib/discordrb/events/raw.rb +1 -3
  69. data/lib/discordrb/events/reactions.rb +49 -4
  70. data/lib/discordrb/events/threads.rb +96 -0
  71. data/lib/discordrb/events/typing.rb +6 -4
  72. data/lib/discordrb/events/voice_server_update.rb +47 -0
  73. data/lib/discordrb/events/voice_state_update.rb +15 -10
  74. data/lib/discordrb/events/webhooks.rb +9 -6
  75. data/lib/discordrb/gateway.rb +99 -71
  76. data/lib/discordrb/id_object.rb +39 -0
  77. data/lib/discordrb/light/integrations.rb +1 -1
  78. data/lib/discordrb/light/light_bot.rb +1 -1
  79. data/lib/discordrb/logger.rb +4 -4
  80. data/lib/discordrb/paginator.rb +57 -0
  81. data/lib/discordrb/permissions.rb +159 -39
  82. data/lib/discordrb/version.rb +1 -1
  83. data/lib/discordrb/voice/encoder.rb +16 -7
  84. data/lib/discordrb/voice/network.rb +99 -47
  85. data/lib/discordrb/voice/sodium.rb +98 -0
  86. data/lib/discordrb/voice/voice_bot.rb +33 -25
  87. data/lib/discordrb/webhooks.rb +2 -0
  88. data/lib/discordrb.rb +107 -1
  89. metadata +126 -54
  90. data/.codeclimate.yml +0 -16
  91. data/.travis.yml +0 -33
  92. data/bin/travis_build_docs.sh +0 -17
  93. /data/{CONTRIBUTING.md → .github/CONTRIBUTING.md} +0 -0
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in discordrb.gemspec
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2016 meew0
3
+ Copyright (c) 2015-2023 meew0
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,41 +1,59 @@
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
- [![Build Status](https://travis-ci.org/meew0/discordrb.svg?branch=master)](https://travis-ci.org/meew0/discordrb)
4
- [![Inline docs](https://inch-ci.org/github/meew0/discordrb.svg?branch=master&style=shields)](https://inch-ci.org/github/meew0/discordrb)
5
- [![Code Climate](https://codeclimate.com/github/meew0/discordrb/badges/gpa.svg)](https://codeclimate.com/github/meew0/discordrb)
6
- [![Test Coverage](https://codeclimate.com/github/meew0/discordrb/badges/coverage.svg)](https://codeclimate.com/github/meew0/discordrb/coverage)
5
+ [![CircleCI](https://circleci.com/gh/shardlab/discordrb.svg?style=svg)](https://circleci.com/gh/shardlab/discordrb)
6
+ [![Inline docs](https://inch-ci.org/github/shardlab/discordrb.svg?branch=main)](https://drb.shardlab.dev/v3.4.0/)
7
7
  [![Join Discord](https://img.shields.io/badge/discord-join-7289DA.svg)](https://discord.gg/cyK3Hjm)
8
- # discordrb
9
8
 
10
- An implementation of the [Discord](https://discordapp.com/) API using Ruby.
9
+ An implementation of the [Discord](https://discord.com/) API using Ruby.
11
10
 
12
11
  ## Quick links to sections
13
12
 
14
- * [Dependencies](https://github.com/meew0/discordrb#dependencies)
15
- * [Installation](https://github.com/meew0/discordrb#installation)
16
- * [Usage](https://github.com/meew0/discordrb#usage)
17
- * [Webhooks Client](https://github.com/meew0/discordrb#webhooks-client)
18
- * [Support](https://github.com/meew0/discordrb#support)
19
- * [Development](https://github.com/meew0/discordrb#development), [Contributing](https://github.com/meew0/discordrb#contributing)
20
- * [License](https://github.com/meew0/discordrb#license)
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)
21
21
 
22
- See also: [Documentation](https://www.rubydoc.info/gems/discordrb), [Tutorials](https://github.com/meew0/discordrb/wiki)
22
+ See also: [Documentation](https://drb.shardlab.dev/v3.4.0/), [Tutorials](https://github.com/shardlab/discordrb/wiki)
23
23
 
24
- ## Dependencies
24
+ ## Introduction
25
+
26
+ `discordrb` aims to meet the following design goals:
27
+
28
+ 1. Full coverage of the public bot API.
29
+ 2. Expressive, high level abstractions for rapid development of common applications.
30
+ 3. Friendly to Ruby beginners and beginners of open source contribution.
25
31
 
26
- * Ruby 2.2+
27
- * An installed build system for native extensions (on Windows for Ruby < 2.4, try the [DevKit](https://rubyinstaller.org/downloads/); installation instructions [here](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit#quick-start) - you only need to do the quick start)
32
+ If you enjoy using the library, consider getting involved with the community to help us improve and meet these goals!
33
+
34
+ **You should consider using `discordrb` if:**
35
+
36
+ - You need a bot - and fast - for small or medium sized communities, and don't want to be bogged down with "low level" details. Getting started takes minutes, and utilities like a command parser and tools for modularization make it simple to quickly add or change your bots functionality.
37
+ - You like or want to learn Ruby, or want to contribute to a Ruby project. A lot of our users are new to Ruby, and eventually make their first open source contributions with us. We have an active Discord channel with experienced members who will happily help you get involved, either as a user or contributor.
38
+ - You want to experiment with Discord's API or prototype concepts for Discord bots without too much commitment.
39
+
40
+ **You should consider other libraries if:**
41
+
42
+ - You need to scale to large volumes of servers (>2,500) with lots of members. It's still possible, but it can be difficult to scale Ruby processes, and it requires more in depth knowledge to do so well. Especially if you already have a bot that is on a large amount of servers, porting to Ruby is unlikely to improve your performance in most cases.
43
+ - You want full control over the library that you're using. While we expose some "lower level" interfaces, they are unstable, and only exist to serve the more powerful abstractions in the library.
44
+
45
+ ## Dependencies
28
46
 
29
- > **Note:** RubyInstaller for Ruby versions 2.4+ will install the DevKit as the last step of the installation.
47
+ * Ruby >= 2.7 supported
48
+ * An installed build system for native extensions (on Windows, make sure you download the "Ruby+Devkit" version of [RubyInstaller](https://rubyinstaller.org/downloads/))
30
49
 
31
50
  ### Voice dependencies
32
51
 
33
52
  This section only applies to you if you want to use voice functionality.
34
- * [libsodium](https://github.com/meew0/discordrb/wiki/Installing-libsodium)
35
- * A compiled libopus distribution for your system, anywhere the script can find it. See [here](https://github.com/meew0/discordrb/wiki/Installing-libopus) for installation instructions.
36
- * [FFmpeg](https://www.ffmpeg.org/download.html) installed and in your PATH
37
53
 
38
- In addition to this, if you're on Windows and want to use voice functionality, your installed Ruby version **needs to be 32 bit**, as otherwise Opus won't work.
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
39
57
 
40
58
  ## Installation
41
59
 
@@ -43,15 +61,19 @@ In addition to this, if you're on Windows and want to use voice functionality, y
43
61
 
44
62
  Using [Bundler](https://bundler.io/#getting-started), you can add discordrb to your Gemfile:
45
63
 
46
- gem 'discordrb'
64
+ ```ruby
65
+ gem 'discordrb'
66
+ ```
47
67
 
48
68
  And then install via `bundle install`.
49
69
 
50
- Run the [ping example](https://github.com/meew0/discordrb/blob/master/examples/ping.rb) to verify that the installation works (make sure to replace the token and client ID in there with your bots'!):
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'!):
51
71
 
52
72
  To run the bot while using bundler:
53
73
 
54
- bundle exec ruby ping.rb
74
+ ```sh
75
+ bundle exec ruby ping.rb
76
+ ```
55
77
 
56
78
  ### With Gem
57
79
 
@@ -59,65 +81,27 @@ Alternatively, while Bundler is the recommended option, you can also install dis
59
81
 
60
82
  #### Linux / macOS
61
83
 
62
- gem install discordrb
84
+ ```sh
85
+ gem install discordrb
86
+ ```
63
87
 
64
88
  #### Windows
65
89
 
66
- > **Make sure you have the DevKit installed! See the [Dependencies](https://github.com/meew0/discordrb#dependencies) section)**
90
+ > **Make sure you have the DevKit installed! See the [Dependencies](https://github.com/shardlab/discordrb#dependencies) section)**
67
91
 
68
- gem install discordrb --platform=ruby
92
+ ```sh
93
+ gem install discordrb --platform=ruby
94
+ ```
69
95
 
70
96
  To run the bot:
71
97
 
72
- ruby ping.rb
73
-
74
- #### Troubleshooting
75
-
76
- **If you get an error like this when installing the gem**:
77
-
78
- ERROR: Error installing discordrb:
79
- The 'websocket-driver' native gem requires installed build tools.
80
-
81
- You're missing the development kit required to build native extensions.
82
-
83
- ##### RubyInstaller for ruby 2.4.3-2 and above
84
-
85
- RubyInstaller after version 2.3.3 now includes the development kit in the installer. If you do not have the development kit and have installed ruby using RubyInstaller, open a command prompt with administrator privileges and run:
86
-
87
- ridk install
88
-
89
- Select option 3, and then run
90
-
91
- ridk enable
92
-
93
- To enable the changes
94
-
95
- ##### RubyInstaller for ruby 2.3.3 and below
96
-
97
- Download the development kit [here](https://rubyinstaller.org/downloads/) (scroll down to "Development Kit", then choose the one for Ruby 2.0 and your system architecture) and extract it somewhere. Open a command prompt in that folder and run:
98
-
99
- ruby dk.rb init
100
- ruby dk.rb install
101
-
102
- Then reinstall discordrb:
103
-
104
- gem uninstall discordrb
105
- bundle install
106
-
107
- # Or, if you didn't use bundler:
108
- gem install discordrb
109
-
110
- **If Ruby complains about `ffi_c` not being able to be found:**
111
-
112
- For example
113
-
114
- C:/Ruby23-x64/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- ffi_c (LoadError)
115
-
116
- Your ffi setup is screwed up, first run `gem uninstall ffi` (uninstall all versions if it asks you, say yes to any unmet dependencies), then run `gem install ffi --platform=ruby` to fix it. If it says something about build tools, follow the steps in the first troubleshooting section.
98
+ ```sh
99
+ ruby ping.rb
100
+ ```
117
101
 
118
- **If you're having trouble getting voice playback to work**:
102
+ ### Installation Troubleshooting
119
103
 
120
- Look here: https://github.com/meew0/discordrb/wiki/Voice-sending#troubleshooting
104
+ See <https://github.com/shardlab/discordrb/wiki/FAQ#installation> for a list of common problems and solutions when installing `discordrb`.
121
105
 
122
106
  ## Usage
123
107
 
@@ -137,7 +121,7 @@ bot.run
137
121
 
138
122
  This bot responds to every "Ping!" with a "Pong!".
139
123
 
140
- See [additional examples here](https://github.com/meew0/discordrb/tree/master/examples).
124
+ See [additional examples here](https://github.com/shardlab/discordrb/tree/main/examples).
141
125
 
142
126
  You can find examples of projects that use discordrb by [searching for the discordrb topic on GitHub](https://github.com/topics/discordrb).
143
127
 
@@ -147,8 +131,8 @@ If you've made an open source project on GitHub that uses discordrb, consider ad
147
131
 
148
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.
149
133
 
150
- - [`discordrb-webhooks` documentation](https://www.rubydoc.info/gems/discordrb-webhooks)
151
- - [More information about webhooks](https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks)
134
+ - [`discordrb-webhooks` documentation](https://drb.shardlab.dev/v3.4.0/Discordrb/Webhooks.html)
135
+ - [More information about webhooks](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks)
152
136
  - [Embed visualizer tool](https://leovoel.github.io/embed-visualizer/) - Includes a discordrb code generator for forming embeds
153
137
 
154
138
  ### Usage
@@ -156,7 +140,7 @@ Also included is a webhooks client, which can be used as a separate gem `discord
156
140
  ```ruby
157
141
  require 'discordrb/webhooks'
158
142
 
159
- WEBHOOK_URL = 'https://discordapp.com/api/webhooks/424070213278105610/yByxDncRvHi02mhKQheviQI2erKkfRRwFcEp0MMBfib1ds6ZHN13xhPZNS2-fJo_ApSw'.freeze
143
+ WEBHOOK_URL = 'https://discord.com/api/webhooks/424070213278105610/yByxDncRvHi02mhKQheviQI2erKkfRRwFcEp0MMBfib1ds6ZHN13xhPZNS2-fJo_ApSw'.freeze
160
144
 
161
145
  client = Discordrb::Webhooks::Client.new(url: WEBHOOK_URL)
162
146
  client.execute do |builder|
@@ -173,19 +157,29 @@ end
173
157
 
174
158
  ## Support
175
159
 
176
- You can find me (@meew0, ID 66237334693085184) on the unofficial Discord API server - if you have a question, just ask there, I or somebody else will probably answer you: https://discord.gg/3Trm6FW
160
+ If you need help or have a question, you can:
177
161
 
178
- ## Development
162
+ 1. Join our [Discord channel](https://discord.gg/cyK3Hjm). This is the fastest means of getting support.
163
+ 2. [Open an issue](https://github.com/shardlab/discordrb/issues). Be sure to read the issue template, and provide as much detail as you can.
179
164
 
180
- **This section is for developing discordrb itself! If you just want to make a bot, see the [Installation](https://github.com/meew0/discordrb#installation) section.**
165
+ ## Contributing
181
166
 
182
- After checking out the repo, run `bin/setup` to install dependencies. You can then run tests via `bundle exec rspec spec`. Make sure to run rubocop also: `bundle exec rubocop`. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
167
+ Thank you for your interest in contributing!
168
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/shardlab/discordrb>.
183
169
 
184
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
170
+ In general, we recommend starting by discussing what you would like to contribute in the [Discord channel](https://discord.gg/cyK3Hjm).
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.
185
172
 
186
- ## Contributing
173
+ Additionally, there is a chance what you are looking for might already exist, or we decided not to pursue it for some reason.
174
+ Be sure to use the search feature on our documentation, GitHub, and Discord to see if this might be the case.
187
175
 
188
- Bug reports and pull requests are welcome on GitHub at https://github.com/meew0/discordrb.
176
+ ## Development setup
177
+
178
+ **This section is for developing discordrb itself! If you just want to make a bot, see the [Installation](https://github.com/shardlab/discordrb#installation) section.**
179
+
180
+ After checking out the repo, run `bin/setup` to install dependencies. You can then run tests via `bundle exec rspec spec`. Make sure to run rubocop also: `bundle exec rubocop`. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
181
+
182
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
189
183
 
190
184
  ## License
191
185
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_helper'
2
4
 
3
5
  namespace :main do
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'discordrb'
@@ -1,18 +1,18 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'discordrb/webhooks/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'discordrb-webhooks'
9
9
  spec.version = Discordrb::Webhooks::VERSION
10
- spec.authors = ['meew0']
10
+ spec.authors = %w[meew0 swarley]
11
11
  spec.email = ['']
12
12
 
13
13
  spec.summary = 'Webhook client for discordrb'
14
14
  spec.description = "A client for Discord's webhooks to fit alongside [discordrb](https://rubygems.org/gems/discordrb)."
15
- spec.homepage = 'https://github.com/meew0/discordrb'
15
+ spec.homepage = 'https://github.com/shardlab/discordrb'
16
16
  spec.license = 'MIT'
17
17
 
18
18
  spec.files = `git ls-files -z lib/discordrb/webhooks/`.split("\x0") + ['lib/discordrb/webhooks.rb']
@@ -20,7 +20,10 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_dependency 'rest-client', '>= 2.1.0.rc1'
23
+ spec.add_dependency 'rest-client', '>= 2.0.0'
24
24
 
25
- spec.required_ruby_version = '>= 2.1.0'
25
+ spec.required_ruby_version = '>= 2.7'
26
+ spec.metadata = {
27
+ 'rubygems_mfa_required' => 'true'
28
+ }
26
29
  end
data/discordrb.gemspec CHANGED
@@ -1,44 +1,47 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'discordrb/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'discordrb'
9
9
  spec.version = Discordrb::VERSION
10
- spec.authors = ['meew0']
10
+ spec.authors = %w[meew0 swarley]
11
11
  spec.email = ['']
12
12
 
13
13
  spec.summary = 'Discord API for Ruby'
14
- spec.description = 'A Ruby implementation of the Discord (https://discordapp.com) API.'
15
- spec.homepage = 'https://github.com/meew0/discordrb'
14
+ spec.description = 'A Ruby implementation of the Discord (https://discord.com) API.'
15
+ spec.homepage = 'https://github.com/shardlab/discordrb'
16
16
  spec.license = 'MIT'
17
17
 
18
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|examples|lib/discordrb/webhooks)/}) }
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/meew0/discordrb/blob/master/CHANGELOG.md'
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
 
26
- spec.add_dependency 'rest-client', '>= 2.1.0.rc1'
27
+ spec.add_dependency 'ffi', '>= 1.9.24'
27
28
  spec.add_dependency 'opus-ruby'
29
+ spec.add_dependency 'rest-client', '>= 2.0.0'
28
30
  spec.add_dependency 'websocket-client-simple', '>= 0.3.0'
29
- spec.add_dependency 'rbnacl', '~> 3.4.0' # 24: update
30
- spec.add_dependency 'ffi', '>= 1.9.24'
31
31
 
32
- spec.add_dependency 'discordrb-webhooks', '~> 3.3.0'
32
+ spec.add_dependency 'discordrb-webhooks', '~> 3.5.0'
33
33
 
34
- spec.required_ruby_version = '>= 2.2.4'
34
+ spec.required_ruby_version = '>= 2.7'
35
35
 
36
- spec.add_development_dependency 'bundler', '~> 1.10'
37
- spec.add_development_dependency 'rake', '~> 10.0'
38
- spec.add_development_dependency 'yard', '~> 0.9.9'
39
- spec.add_development_dependency 'redcarpet', '~> 3.4.0' # YARD markdown formatting
40
- spec.add_development_dependency 'rspec', '~> 3.4.0'
36
+ spec.add_development_dependency 'bundler', '>= 1.10', '< 3'
37
+ spec.add_development_dependency 'rake', '~> 13.0'
38
+ spec.add_development_dependency 'redcarpet', '~> 3.5.0' # YARD markdown formatting
39
+ spec.add_development_dependency 'rspec', '~> 3.11.0'
40
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0.5.1'
41
41
  spec.add_development_dependency 'rspec-prof', '~> 0.0.7'
42
- spec.add_development_dependency 'rubocop', '0.49.1'
43
- spec.add_development_dependency 'simplecov', '~> 0.16.0'
42
+ spec.add_development_dependency 'rubocop', '~> 1.36.0'
43
+ spec.add_development_dependency 'rubocop-performance', '~> 1.0'
44
+ spec.add_development_dependency 'rubocop-rake', '~> 0.6.0'
45
+ spec.add_development_dependency 'simplecov', '~> 0.21.0'
46
+ spec.add_development_dependency 'yard', '~> 0.9.9'
44
47
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'discordrb/id_object'
4
+
5
+ module Discordrb
6
+ # Builder class for `allowed_mentions` when sending messages.
7
+ class AllowedMentions
8
+ # @return [Array<"users", "roles", "everyone">, nil]
9
+ attr_accessor :parse
10
+
11
+ # @return [Array<String, Integer>, nil]
12
+ attr_accessor :users
13
+
14
+ # @return [Array<String, Integer>, nil]
15
+ attr_accessor :roles
16
+
17
+ # @param parse [Array<"users", "roles", "everyone">] Mention types that can be inferred from the message.
18
+ # `users` and `roles` allow for all mentions of the respective type to ping. `everyone` allows usage of `@everyone` and `@here`
19
+ # @param users [Array<User, String, Integer>] Users or user IDs that can be pinged. Cannot be used in conjunction with `"users"` in `parse`
20
+ # @param roles [Array<Role, String, Integer>] Roles or role IDs that can be pinged. Cannot be used in conjunction with `"roles"` in `parse`
21
+ def initialize(parse: nil, users: nil, roles: nil)
22
+ @parse = parse
23
+ @users = users
24
+ @roles = roles
25
+ end
26
+
27
+ # @!visibility private
28
+ def to_hash
29
+ {
30
+ parse: @parse,
31
+ users: @users&.map { |user| user.is_a?(IDObject) ? user.id : user },
32
+ roles: @roles&.map { |role| role.is_a?(IDObject) ? role.id : role }
33
+ }.compact
34
+ end
35
+ end
36
+ 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