From 8f9f4adbb9438796877a1a3f18b10d21c6c4726f Mon Sep 17 00:00:00 2001 From: Dakurei Date: Mon, 27 Mar 2023 22:37:24 +0200 Subject: [PATCH 01/10] Attempt to create Github Actions based on CircleCI jobs + Rspec tasks (for Ruby 2.7.x, 3.0.x, 3.1.x, 3.2.x) + Rubocop task (with Ruby 2.7.x) + Yard & Github pages tasks (with Ruby 2.7.x) + Update rspec version constraint in discordrb.gemspec (from ~> 3.11.0 to ~> 3.12.0) + Update redcarpet version constraint in discordrb.gemspec (from ~> 3.5.0 to ~> 3.6.0) --- .github/workflows/github-pages.yml | 65 ++++++++++++++++++++++++++++++ .github/workflows/rspec.yml | 53 ++++++++++++++++++++++++ .github/workflows/rubocop.yml | 39 ++++++++++++++++++ .github/workflows/yard.yml | 51 +++++++++++++++++++++++ discordrb.gemspec | 4 +- 5 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/github-pages.yml create mode 100644 .github/workflows/rspec.yml create mode 100644 .github/workflows/rubocop.yml create mode 100644 .github/workflows/yard.yml diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml new file mode 100644 index 000000000..1e02f2d6b --- /dev/null +++ b/.github/workflows/github-pages.yml @@ -0,0 +1,65 @@ +name: "Github Pages" + +on: + push: + branches: + - main + tags: + - v* + +jobs: + pages: + name: Github Pages + runs-on: ubuntu-latest + env: + api-dir: ./ + + strategy: + fail-fast: false + + steps: + - name: Checkout repository for Yard + uses: actions/checkout@v3 + with: + path: discordrb_docs + + - name: Install OS package + run: | + sudo apt update + sudo apt install -y git openssh-client + + - name: Setup Ruby 2.7 + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.7' + bundler-cache: true + + - name: Checkout repository for Github Pages + uses: actions/checkout@v3 + with: + path: discordrb_gh + ref: gh-pages + + - name: Run bundle install + working-directory: ${{env.api-dir}} + run: | + gem install bundler + BUNDLE_GEMFILE=discordrb_docs/Gemfile bundle install --jobs 4 --retry 3 + + - name: Generate Yard docs + working-directory: ${{env.api-dir}} + run: | + cd discordrb_docs + bundle exec yard --output-dir /tmp/docs + + - name: Commit & Push docs + run: | + cd discordrb_gh + git config user.email "github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + mkdir -p $GITHUB_REF_NAME + rm -rf $GITHUB_REF_NAME/* + cp -r /tmp/docs/. $GITHUB_REF_NAME + git add $GITHUB_REF_NAME + git commit --allow-empty -m "[skip ci] Deploy docs" + git push \ No newline at end of file diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml new file mode 100644 index 000000000..9974bc64b --- /dev/null +++ b/.github/workflows/rspec.yml @@ -0,0 +1,53 @@ +name: "Rspec" + +on: + push: + branches-ignore: + - gh-pages + pull_request: + branches-ignore: + - gh-pages + +jobs: + rspec: + name: Rspec + runs-on: ubuntu-latest + env: + api-dir: ./ + + strategy: + fail-fast: false + matrix: + versions: [ '2.7', '3.0', '3.1', '3.2' ] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup libraries + run: | + sudo apt update + sudo apt install -y libsodium-dev + + - name: Setup Ruby ${{ matrix.versions }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.versions }} + bundler-cache: true + + - name: Run bundle install (Ruby ${{ matrix.versions }}) + working-directory: ${{env.api-dir}} + run: | + gem install bundler + bundle install --jobs 4 --retry 3 + + - name: Rspec spec (Ruby ${{ matrix.versions }}) + working-directory: ${{env.api-dir}} + run: bundle exec rspec spec --format progress --format RspecJunitFormatter -o ~/rspec/rspec.xml + + - name: Save test results (Ruby ${{ matrix.versions }}) + uses: actions/upload-artifact@v3 + with: + name: rspec_results_${{ matrix.versions }} + path: ~/rspec/rspec.xml + retention-days: 30 \ No newline at end of file diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml new file mode 100644 index 000000000..5e893f2a7 --- /dev/null +++ b/.github/workflows/rubocop.yml @@ -0,0 +1,39 @@ +name: "Rubocop" + +on: + push: + branches-ignore: + - gh-pages + pull_request: + branches-ignore: + - gh-pages + +jobs: + rubocop: + name: Rubocop + runs-on: ubuntu-latest + env: + api-dir: ./ + + strategy: + fail-fast: false + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Ruby 2.7 + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.7' + bundler-cache: true + + - name: Run bundle install + working-directory: ${{env.api-dir}} + run: | + gem install bundler + bundle install --jobs 4 --retry 3 + + - name: Rubocop checks + working-directory: ${{env.api-dir}} + run: bundle exec rubocop diff --git a/.github/workflows/yard.yml b/.github/workflows/yard.yml new file mode 100644 index 000000000..d1490e4fb --- /dev/null +++ b/.github/workflows/yard.yml @@ -0,0 +1,51 @@ +name: "Yard" + +on: + push: + branches-ignore: + - gh-pages + pull_request: + branches-ignore: + - gh-pages + +jobs: + yard: + name: Yard + runs-on: ubuntu-latest + env: + api-dir: ./ + + strategy: + fail-fast: false + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Ruby 2.7 + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.7' + bundler-cache: true + + - name: Run bundle install + working-directory: ${{env.api-dir}} + run: | + gem install bundler + bundle install --jobs 4 --retry 3 + + - name: Generate Yard docs + working-directory: ${{env.api-dir}} + run: bundle exec yard --output-dir /tmp/docs + + - name: Compress docs to prevent error 429 + run: | + cd /tmp/docs + tar -cvf /tmp/docs.tar . + + - name: Keep temporary the generated docs + uses: actions/upload-artifact@v3 + with: + name: docs_${{ github.run_number }} + path: /tmp/docs.tar + retention-days: 30 \ No newline at end of file diff --git a/discordrb.gemspec b/discordrb.gemspec index 8867fd132..bba67e037 100644 --- a/discordrb.gemspec +++ b/discordrb.gemspec @@ -35,8 +35,8 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'bundler', '>= 1.10', '< 3' spec.add_development_dependency 'rake', '~> 13.0' - spec.add_development_dependency 'redcarpet', '~> 3.5.0' # YARD markdown formatting - spec.add_development_dependency 'rspec', '~> 3.11.0' + spec.add_development_dependency 'redcarpet', '~> 3.6.0' # YARD markdown formatting + spec.add_development_dependency 'rspec', '~> 3.12.0' spec.add_development_dependency 'rspec_junit_formatter', '~> 0.5.1' spec.add_development_dependency 'rspec-prof', '~> 0.0.7' spec.add_development_dependency 'rubocop', '~> 1.36.0' From 9bed24ad4cc1e40a513f178edf0907d7f62b3fa6 Mon Sep 17 00:00:00 2001 From: Dakurei Date: Tue, 28 Mar 2023 10:57:23 +0200 Subject: [PATCH 02/10] Edit README.md --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b492a372f..72c627b9c 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,10 @@ [![Gem](https://img.shields.io/gem/v/discordrb.svg)](https://rubygems.org/gems/discordrb) [![Gem](https://img.shields.io/gem/dt/discordrb.svg)](https://rubygems.org/gems/discordrb) -[![CircleCI](https://circleci.com/gh/shardlab/discordrb.svg?style=svg)](https://circleci.com/gh/shardlab/discordrb) -[![Inline docs](https://inch-ci.org/github/shardlab/discordrb.svg?branch=main)](https://drb.shardlab.dev/v3.4.0/) +[![Gem](https://img.shields.io/badge/docs-v3.4.0-979797.svg)](https://drb.shardlab.dev/v3.4.0/) +[![Github Actions Rspec](https://github.com/shardlab/discordrb/actions/workflows/rspec.yml/badge.svg?branch=main&event=push)](https://github.com/shardlab/discordrb/actions/workflows/rspec.yml) +[![Github Actions Rubocop](https://github.com/shardlab/discordrb/actions/workflows/rubocop.yml/badge.svg?branch=main&event=push)](https://github.com/shardlab/discordrb/actions/workflows/rubocop.yml) +[![Inline docs](https://img.shields.io/badge/docs-main-979797.svg)](https://drb.shardlab.dev/main/) [![Join Discord](https://img.shields.io/badge/discord-join-7289DA.svg)](https://discord.gg/cyK3Hjm) An implementation of the [Discord](https://discord.com/) API using Ruby. @@ -67,6 +69,13 @@ gem 'discordrb' And then install via `bundle install`. +_If you want to run the latest code instead, use this gem line instead:_ +```ruby +gem 'discordrb', github: 'shardlab/discordrb', branch: 'main' +``` + +⚠️ **Note that main may contain breaking changes or other unstable code !** + 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'!): To run the bot while using bundler: From 75c157f0b3e6f8ac2e748ec7255c25ac12d2509f Mon Sep 17 00:00:00 2001 From: Dakurei Date: Tue, 28 Mar 2023 10:23:54 +0200 Subject: [PATCH 03/10] Reversal of a previous modification concerning Webhook#update_webhook Finally, after doing my tests on the latest version of Rspec, and looking at the code, I realize that the modification was not necessary, and PixeLInc was right in his PR #199 --- examples/webhooks.rb | 2 +- lib/discordrb/data/webhook.rb | 2 +- spec/data/webhook_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/webhooks.rb b/examples/webhooks.rb index fa4e5584b..dc31f5957 100644 --- a/examples/webhooks.rb +++ b/examples/webhooks.rb @@ -26,7 +26,7 @@ if event.message.content == 'EDIT_TWO' wh = event.channel.webhooks.first - wh.update(avatar: BASE64_SMALL_PICTURE, reason: 'Edition test two') + wh.update({ avatar: BASE64_SMALL_PICTURE, reason: 'Edition test two' }) puts wh.inspect wh.execute(content: '[EDIT TWO]') diff --git a/lib/discordrb/data/webhook.rb b/lib/discordrb/data/webhook.rb index 3e2bb8260..cb5693649 100644 --- a/lib/discordrb/data/webhook.rb +++ b/lib/discordrb/data/webhook.rb @@ -86,7 +86,7 @@ def update(data) data[:avatar] = avatarise(data[:avatar]) if data.key?(:avatar) data[:channel_id] = data[:channel]&.resolve_id data.delete(:channel) - update_webhook(**data) + update_webhook(data) end # Deletes the webhook. diff --git a/spec/data/webhook_spec.rb b/spec/data/webhook_spec.rb index d6c5a5a05..1f3aa6b49 100644 --- a/spec/data/webhook_spec.rb +++ b/spec/data/webhook_spec.rb @@ -101,7 +101,7 @@ describe '#update' do it 'calls update_webhook' do - expect(webhook).to receive(:update_webhook).with(avatar: avatar_string, channel_id: edited_webhook_channel_id.to_i, name: edited_webhook_name, reason: reason) + expect(webhook).to receive(:update_webhook).with(hash_including(avatar: avatar_string, channel_id: edited_webhook_channel_id.to_i, name: edited_webhook_name, reason: reason)) webhook.update(avatar: avatar_string, channel: edited_webhook_channel_id, name: edited_webhook_name, reason: reason) end end From b3433aba050fb56cb3230bd23d782b56492c9839 Mon Sep 17 00:00:00 2001 From: Dakurei Date: Tue, 28 Mar 2023 15:53:16 +0200 Subject: [PATCH 04/10] Remove CircleCI configuration which is not required anymore --- .circleci/config.yml | 152 ------------------------------------------- 1 file changed, 152 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index c845ea722..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,152 +0,0 @@ -version: 2.1 - -commands: - setup-env: - description: Sets up the testing environment - steps: - - run: - name: Install OS packages - command: apk add git build-base ruby-dev ruby-etc ruby-json libsodium - - checkout - - run: - name: "Ruby version" - command: | - ruby -v - echo $RUBY_VERSION > ruby_version.txt - - restore_cache: - keys: - - bundle-cache-v1-{{ checksum "ruby_version.txt" }}-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "discordrb.gemspec" }} - - bundle-cache-v1-{{ checksum "ruby_version.txt" }}-{{ .Branch }} - - bundle-cache-v1-{{ checksum "ruby_version.txt" }} - - run: - name: Install dependencies - command: bundle install --path vendor/bundle - - save_cache: - key: bundle-cache-v1-{{ checksum "ruby_version.txt" }}-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "discordrb.gemspec" }} - paths: - - ./vendor/bundle - -jobs: - test_ruby_27: - docker: - - image: ruby:2.7-alpine - steps: - - setup-env - - run: - name: Run RSpec - command: bundle exec rspec --format progress --format RspecJunitFormatter -o ~/rspec/rspec.xml - - store_test_results: - path: ~/rspec - - test_ruby_30: - docker: - - image: ruby:3.0-alpine - steps: - - setup-env - - run: - name: Run RSpec - command: bundle exec rspec --format progress --format RspecJunitFormatter -o ~/rspec/rspec.xml - - store_test_results: - path: ~/rspec - - - test_ruby_31: - docker: - - image: ruby:3.1-alpine - steps: - - setup-env - - run: - name: Run RSpec - command: bundle exec rspec --format progress --format RspecJunitFormatter -o ~/rspec/rspec.xml - - rubocop: - docker: - - image: ruby:2.7-alpine - steps: - - setup-env - - run: - name: Run Rubocop - command: bundle exec rubocop - - yard: - docker: - - image: ruby:2.7-alpine - steps: - - setup-env - - attach_workspace: - at: /tmp/workspace - - run: - name: Run YARD - command: bundle exec yard --output-dir /tmp/workspace/docs - - persist_to_workspace: - root: /tmp/workspace - paths: - - docs - - pages: - docker: - - image: alpine - steps: - - run: - name: Install OS packages - command: apk add git openssh-client-default - - attach_workspace: - at: /tmp/workspace - - run: - name: Clone docs - command: | - mkdir -p ~/.ssh - - echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk=' >> ~/.ssh/known_hosts - - git clone $CIRCLE_REPOSITORY_URL -b gh-pages . - - add_ssh_keys: - fingerprints: - - "9a:4c:50:94:23:46:81:74:41:97:87:04:4e:59:4b:4e" - - run: - name: Push updated docs - command: | - git config user.name "Circle CI" - git config user.email "ci-build@shardlab.dev" - - SOURCE_BRANCH=$CIRCLE_BRANCH - if [ -n "$CIRCLE_TAG" ]; then - SOURCE_BRANCH=$CIRCLE_TAG - fi - - mkdir -p $SOURCE_BRANCH - rm -rf $SOURCE_BRANCH/* - cp -r /tmp/workspace/docs/. ./$SOURCE_BRANCH/ - - git add $SOURCE_BRANCH - git commit --allow-empty -m "[skip ci] Deploy docs" - git push -u origin gh-pages - -workflows: - test: - jobs: - - test_ruby_27 - - test_ruby_30 - - test_ruby_31 - - rubocop - - yard - deploy: - jobs: - - yard: - filters: - branches: - only: - - main - - slash_commands - tags: - only: /^v.*/ - - pages: - requires: - - yard - filters: - branches: - only: - - main - - slash_commands - tags: - only: /^v.*/ From 6a647abeb5cc70c8c4b149220a88204df91007ed Mon Sep 17 00:00:00 2001 From: Dakurei Date: Mon, 24 Apr 2023 15:43:24 +0200 Subject: [PATCH 05/10] Fix a bug in update_channel_data Contrary to what the documentation indicated, it was not possible to provide an Array to Channel#permission_overwrites= It was necessary to provide the Hash similar to what the method Channel#permission_overwrites returns + Added an example file to test the overwrites (I used it as a debug) + Modification of a test in spec/data/channel_spec.rb following this correction --- examples/channel_overwrite.rb | 66 +++++++++++++++++++++++++++++++++++ lib/discordrb/data/channel.rb | 9 +++-- spec/data/channel_spec.rb | 2 +- 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 examples/channel_overwrite.rb diff --git a/examples/channel_overwrite.rb b/examples/channel_overwrite.rb new file mode 100644 index 000000000..4723f577e --- /dev/null +++ b/examples/channel_overwrite.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +require 'discordrb' +require 'securerandom' + +CHANNEL_EDIT = ENV.fetch('CHANNEL_EDIT') +ROLE_1 = ENV.fetch('ROLE_1') +ROLE_2 = ENV.fetch('ROLE_2') + +bot = Discordrb::Bot.new(token: ENV.fetch('DISCORDRB_TOKEN')) + +bot.message do |event| + if event.message.content == 'DEFINE_OVERWRITE' + event.channel.send_message('Define overwrite in this channel') + + allow = Discordrb::Permissions.new + allow.can_mention_everyone = true + + overwrite = Discordrb::Overwrite.new(ROLE_1, type: 'role', allow: allow, deny: Discordrb::Permissions.new) + + event.bot.channel(CHANNEL_EDIT, event.server).define_overwrite(overwrite) + end + + if event.message.content == 'CHECK_OVERWRITE' + event.channel.send_message('Check overwrite in this channel') + puts(event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites.map { |_, v| "#{v.type} - #{v.id} - #{v.allow.bits} / #{v.deny.bits}" }) + end + + if event.message.content == 'DELETE_OVERWRITE' + event.channel.send_message('Delete overwrite in this channel') + + event.bot.channel(CHANNEL_EDIT, event.server).delete_overwrite(ROLE_1) + end + + if event.message.content == 'BULK_OVERWRITE' + event.channel.send_message('Bulk overwrite in this channel') + + allow = Discordrb::Permissions.new + allow.can_mention_everyone = true + + deny = Discordrb::Permissions.new + deny.can_mention_everyone = true + + overwrites = [] + overwrites << Discordrb::Overwrite.new(ROLE_1, type: 'role', allow: allow, deny: Discordrb::Permissions.new) + overwrites << Discordrb::Overwrite.new(ROLE_2, type: 'role', allow: Discordrb::Permissions.new, deny: deny) + + event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites = overwrites + puts(event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites.map { |_, v| "#{v.type} - #{v.id} - #{v.allow.bits} / #{v.deny.bits}" }) + + # Bulk edit from permission_overwrites return values (this method return a Hash and not an Array) + event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites = event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites + puts(event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites.map { |_, v| "#{v.type} - #{v.id} - #{v.allow.bits} / #{v.deny.bits}" }) + + # Send nil to check if permission_overwrites not changed + event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites = nil + puts(event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites.map { |_, v| "#{v.type} - #{v.id} - #{v.allow.bits} / #{v.deny.bits}" }) + end + + if event.message.content == 'BULK_DELETE_OVERWRITE' + event.channel.send_message('Bulk delete overwrite in this channel') + event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites = [] + end +end + +bot.run diff --git a/lib/discordrb/data/channel.rb b/lib/discordrb/data/channel.rb index 4f442b7c8..5bd9f2368 100644 --- a/lib/discordrb/data/channel.rb +++ b/lib/discordrb/data/channel.rb @@ -341,7 +341,7 @@ def permission_overwrites(type = nil) alias_method :overwrites, :permission_overwrites # Bulk sets this channels permission overwrites - # @param overwrites [Array] + # @param overwrites [Array, Hash Overwrite>] def permission_overwrites=(overwrites) update_channel_data(permission_overwrites: overwrites) end @@ -965,7 +965,12 @@ def bulk_delete(ids, strict = false, reason = nil) def update_channel_data(new_data) new_nsfw = new_data[:nsfw].is_a?(TrueClass) || new_data[:nsfw].is_a?(FalseClass) ? new_data[:nsfw] : @nsfw # send permission_overwrite only when explicitly set - overwrites = new_data[:permission_overwrites] ? new_data[:permission_overwrites].map { |_, v| v.to_hash } : nil + overwrites = if new_data[:permission_overwrites].is_a?(Hash) + new_data[:permission_overwrites]&.map { |_, v| v&.to_hash } + else + new_data[:permission_overwrites]&.map(&:to_hash) + end + response = JSON.parse(API::Channel.update(@bot.token, @id, new_data[:name] || @name, new_data[:topic] || @topic, diff --git a/spec/data/channel_spec.rb b/spec/data/channel_spec.rb index acbae6cda..e068df8bf 100644 --- a/spec/data/channel_spec.rb +++ b/spec/data/channel_spec.rb @@ -103,7 +103,7 @@ allow(JSON).to receive(:parse) new_data = double('new data') allow(new_data).to receive(:[]) - allow(new_data).to receive(:[]).with(:permission_overwrites).and_return(false) + allow(new_data).to receive(:[]).with(:permission_overwrites).and_return(nil) expect(Discordrb::API::Channel).to receive(:update).with(any_args, nil, anything) channel.__send__(:update_channel_data, new_data) end From fd9ef3faa2e3e998576fed57abd2a2acb0a23732 Mon Sep 17 00:00:00 2001 From: Dakurei Date: Mon, 24 Apr 2023 11:24:12 +0200 Subject: [PATCH 06/10] Make sure to run Github Actions only on main or main's pull_request --- .github/workflows/rspec.yml | 8 ++++---- .github/workflows/rubocop.yml | 8 ++++---- .github/workflows/yard.yml | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 9974bc64b..116be03ce 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -2,11 +2,11 @@ name: "Rspec" on: push: - branches-ignore: - - gh-pages + branches: + - main pull_request: - branches-ignore: - - gh-pages + branches: + - main jobs: rspec: diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index 5e893f2a7..597277770 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -2,11 +2,11 @@ name: "Rubocop" on: push: - branches-ignore: - - gh-pages + branches: + - main pull_request: - branches-ignore: - - gh-pages + branches: + - main jobs: rubocop: diff --git a/.github/workflows/yard.yml b/.github/workflows/yard.yml index d1490e4fb..2f7a263a4 100644 --- a/.github/workflows/yard.yml +++ b/.github/workflows/yard.yml @@ -2,11 +2,11 @@ name: "Yard" on: push: - branches-ignore: - - gh-pages + branches: + - main pull_request: - branches-ignore: - - gh-pages + branches: + - main jobs: yard: From 65ac49f065bb26f8182dfb954960c1c55ea15ea3 Mon Sep 17 00:00:00 2001 From: Dakurei Date: Sat, 27 May 2023 22:08:39 +0200 Subject: [PATCH 07/10] Apply suggestions from code review Fix typo and newlines Co-authored-by: Adrien Smith --- .github/workflows/github-pages.yml | 2 +- .github/workflows/rspec.yml | 8 ++++---- .github/workflows/rubocop.yml | 6 +++--- .github/workflows/yard.yml | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml index 1e02f2d6b..a9def4743 100644 --- a/.github/workflows/github-pages.yml +++ b/.github/workflows/github-pages.yml @@ -62,4 +62,4 @@ jobs: cp -r /tmp/docs/. $GITHUB_REF_NAME git add $GITHUB_REF_NAME git commit --allow-empty -m "[skip ci] Deploy docs" - git push \ No newline at end of file + git push diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 116be03ce..64ad119ad 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -1,4 +1,4 @@ -name: "Rspec" +name: "RSpec" on: push: @@ -10,7 +10,7 @@ on: jobs: rspec: - name: Rspec + name: RSpec runs-on: ubuntu-latest env: api-dir: ./ @@ -41,7 +41,7 @@ jobs: gem install bundler bundle install --jobs 4 --retry 3 - - name: Rspec spec (Ruby ${{ matrix.versions }}) + - name: RSpec spec (Ruby ${{ matrix.versions }}) working-directory: ${{env.api-dir}} run: bundle exec rspec spec --format progress --format RspecJunitFormatter -o ~/rspec/rspec.xml @@ -50,4 +50,4 @@ jobs: with: name: rspec_results_${{ matrix.versions }} path: ~/rspec/rspec.xml - retention-days: 30 \ No newline at end of file + retention-days: 30 diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index 597277770..bf1634633 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -1,4 +1,4 @@ -name: "Rubocop" +name: "RuboCop" on: push: @@ -10,7 +10,7 @@ on: jobs: rubocop: - name: Rubocop + name: RuboCop runs-on: ubuntu-latest env: api-dir: ./ @@ -34,6 +34,6 @@ jobs: gem install bundler bundle install --jobs 4 --retry 3 - - name: Rubocop checks + - name: RuboCop checks working-directory: ${{env.api-dir}} run: bundle exec rubocop diff --git a/.github/workflows/yard.yml b/.github/workflows/yard.yml index 2f7a263a4..1b7cea63f 100644 --- a/.github/workflows/yard.yml +++ b/.github/workflows/yard.yml @@ -48,4 +48,4 @@ jobs: with: name: docs_${{ github.run_number }} path: /tmp/docs.tar - retention-days: 30 \ No newline at end of file + retention-days: 30 From a6d9605fcbe765f953123d74e7a64592895aaf30 Mon Sep 17 00:00:00 2001 From: Dakurei Date: Wed, 5 Jul 2023 19:49:31 +0200 Subject: [PATCH 08/10] Apply modifications from version bump 3.5.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 72c627b9c..5dc2196e5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Gem](https://img.shields.io/gem/v/discordrb.svg)](https://rubygems.org/gems/discordrb) [![Gem](https://img.shields.io/gem/dt/discordrb.svg)](https://rubygems.org/gems/discordrb) -[![Gem](https://img.shields.io/badge/docs-v3.4.0-979797.svg)](https://drb.shardlab.dev/v3.4.0/) +[![Gem](https://img.shields.io/badge/docs-v3.5.0-979797.svg)](https://drb.shardlab.dev/v3.5.0/) [![Github Actions Rspec](https://github.com/shardlab/discordrb/actions/workflows/rspec.yml/badge.svg?branch=main&event=push)](https://github.com/shardlab/discordrb/actions/workflows/rspec.yml) [![Github Actions Rubocop](https://github.com/shardlab/discordrb/actions/workflows/rubocop.yml/badge.svg?branch=main&event=push)](https://github.com/shardlab/discordrb/actions/workflows/rubocop.yml) [![Inline docs](https://img.shields.io/badge/docs-main-979797.svg)](https://drb.shardlab.dev/main/) @@ -21,7 +21,7 @@ An implementation of the [Discord](https://discord.com/) API using Ruby. - [Development](https://github.com/shardlab/discordrb#development), [Contributing](https://github.com/shardlab/discordrb#contributing) - [License](https://github.com/shardlab/discordrb#license) -See also: [Documentation](https://drb.shardlab.dev/v3.4.0/), [Tutorials](https://github.com/shardlab/discordrb/wiki) +See also: [Documentation](https://drb.shardlab.dev/v3.5.0/), [Tutorials](https://github.com/shardlab/discordrb/wiki) ## Introduction @@ -140,7 +140,7 @@ If you've made an open source project on GitHub that uses discordrb, consider ad 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. -- [`discordrb-webhooks` documentation](https://drb.shardlab.dev/v3.4.0/Discordrb/Webhooks.html) +- [`discordrb-webhooks` documentation](https://drb.shardlab.dev/v3.5.0/Discordrb/Webhooks.html) - [More information about webhooks](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) - [Embed visualizer tool](https://leovoel.github.io/embed-visualizer/) - Includes a discordrb code generator for forming embeds From 8cd5227c78a15ed5b9f6fb9710ef9760bdac4bec Mon Sep 17 00:00:00 2001 From: Dakurei Date: Mon, 8 Jan 2024 21:28:27 +0100 Subject: [PATCH 09/10] Add Ruby 3.3 to Rspec matrix --- .github/workflows/rspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 64ad119ad..3103db5f8 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - versions: [ '2.7', '3.0', '3.1', '3.2' ] + versions: [ '2.7', '3.0', '3.1', '3.2', '3.3' ] steps: - name: Checkout repository From 7f4936e062015ef3861cb806b3f991d2a9d5bd73 Mon Sep 17 00:00:00 2001 From: Dakurei Date: Thu, 30 Mar 2023 16:40:28 +0200 Subject: [PATCH 10/10] Ruby 3.0 EOL and Dependency Chores --- .github/workflows/github-pages.yml | 4 ++-- .github/workflows/rspec.yml | 2 +- .github/workflows/rubocop.yml | 4 ++-- .github/workflows/yard.yml | 4 ++-- .rubocop.yml | 16 +++++++++++++++- README.md | 2 +- discordrb-webhooks.gemspec | 2 +- discordrb.gemspec | 10 +++++----- examples/channel_overwrite.rb | 2 +- lib/discordrb/bot.rb | 6 +++--- lib/discordrb/commands/parser.rb | 2 +- lib/discordrb/data/component.rb | 2 +- lib/discordrb/data/embed.rb | 2 +- lib/discordrb/data/emoji.rb | 2 +- lib/discordrb/data/interaction.rb | 2 +- lib/discordrb/data/member.rb | 2 +- lib/discordrb/data/message.rb | 2 +- lib/discordrb/data/reaction.rb | 2 +- lib/discordrb/data/recipient.rb | 2 +- lib/discordrb/data/server.rb | 10 +++++----- lib/discordrb/data/user.rb | 4 ++-- lib/discordrb/light/data.rb | 2 +- lib/discordrb/permissions.rb | 12 ++++++------ lib/discordrb/voice/encoder.rb | 2 +- spec/data/channel_spec.rb | 2 +- spec/overwrite_spec.rb | 2 +- 26 files changed, 59 insertions(+), 45 deletions(-) diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml index a9def4743..e2ad3ffc7 100644 --- a/.github/workflows/github-pages.yml +++ b/.github/workflows/github-pages.yml @@ -28,10 +28,10 @@ jobs: sudo apt update sudo apt install -y git openssh-client - - name: Setup Ruby 2.7 + - name: Setup Ruby 3.1 uses: ruby/setup-ruby@v1 with: - ruby-version: '2.7' + ruby-version: '3.1' bundler-cache: true - name: Checkout repository for Github Pages diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 3103db5f8..3db590b25 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - versions: [ '2.7', '3.0', '3.1', '3.2', '3.3' ] + versions: [ '3.1', '3.2', '3.3' ] steps: - name: Checkout repository diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index bf1634633..3601e1536 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -22,10 +22,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Setup Ruby 2.7 + - name: Setup Ruby 3.1 uses: ruby/setup-ruby@v1 with: - ruby-version: '2.7' + ruby-version: '3.1' bundler-cache: true - name: Run bundle install diff --git a/.github/workflows/yard.yml b/.github/workflows/yard.yml index 1b7cea63f..c0022c115 100644 --- a/.github/workflows/yard.yml +++ b/.github/workflows/yard.yml @@ -22,10 +22,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Setup Ruby 2.7 + - name: Setup Ruby 3.1 uses: ruby/setup-ruby@v1 with: - ruby-version: '2.7' + ruby-version: '3.1' bundler-cache: true - name: Run bundle install diff --git a/.rubocop.yml b/.rubocop.yml index cbe94c83a..e8ce9977e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,7 +8,7 @@ inherit_mode: AllCops: NewCops: enable - TargetRubyVersion: 2.7 + TargetRubyVersion: 3.1 # Disable line length checks Layout/LineLength: @@ -66,3 +66,17 @@ Style/SingleLineBlockParams: Methods: - reduce: [m, e] - inject: [m, e] + +# Rule to keep development dependencies inside gemspec file +Gemspec/DevelopmentDependencies: + EnforcedStyle: gemspec + +# Rule disabled to avoid breaking methods or behaviors unnecessarily (Reactivate if you find it relevant) +Style/ReturnNilInPredicateMethodDefinition: + Enabled: false +Style/HashSyntax: + Enabled: false +Naming/BlockForwarding: + Enabled: false +Style/ArgumentsForwarding: + Enabled: false diff --git a/README.md b/README.md index 5dc2196e5..74ba99af1 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ If you enjoy using the library, consider getting involved with the community to ## Dependencies -* Ruby >= 2.7 supported +* Ruby >= 3.1 supported * An installed build system for native extensions (on Windows, make sure you download the "Ruby+Devkit" version of [RubyInstaller](https://rubyinstaller.org/downloads/)) ### Voice dependencies diff --git a/discordrb-webhooks.gemspec b/discordrb-webhooks.gemspec index 7705c97f8..4ea3caa11 100644 --- a/discordrb-webhooks.gemspec +++ b/discordrb-webhooks.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'rest-client', '>= 2.0.0' - spec.required_ruby_version = '>= 2.7' + spec.required_ruby_version = '>= 3.1' spec.metadata = { 'rubygems_mfa_required' => 'true' } diff --git a/discordrb.gemspec b/discordrb.gemspec index bba67e037..df1675d74 100644 --- a/discordrb.gemspec +++ b/discordrb.gemspec @@ -31,17 +31,17 @@ Gem::Specification.new do |spec| spec.add_dependency 'discordrb-webhooks', '~> 3.5.0' - spec.required_ruby_version = '>= 2.7' + spec.required_ruby_version = '>= 3.1' spec.add_development_dependency 'bundler', '>= 1.10', '< 3' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'redcarpet', '~> 3.6.0' # YARD markdown formatting - spec.add_development_dependency 'rspec', '~> 3.12.0' - spec.add_development_dependency 'rspec_junit_formatter', '~> 0.5.1' + spec.add_development_dependency 'rspec', '~> 3.13.0' + spec.add_development_dependency 'rspec_junit_formatter', '~> 0.6.0' spec.add_development_dependency 'rspec-prof', '~> 0.0.7' - spec.add_development_dependency 'rubocop', '~> 1.36.0' + spec.add_development_dependency 'rubocop', '~> 1.64.0' spec.add_development_dependency 'rubocop-performance', '~> 1.0' spec.add_development_dependency 'rubocop-rake', '~> 0.6.0' - spec.add_development_dependency 'simplecov', '~> 0.21.0' + spec.add_development_dependency 'simplecov', '~> 0.22.0' spec.add_development_dependency 'yard', '~> 0.9.9' end diff --git a/examples/channel_overwrite.rb b/examples/channel_overwrite.rb index 4723f577e..a65d95ce9 100644 --- a/examples/channel_overwrite.rb +++ b/examples/channel_overwrite.rb @@ -49,7 +49,7 @@ puts(event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites.map { |_, v| "#{v.type} - #{v.id} - #{v.allow.bits} / #{v.deny.bits}" }) # Bulk edit from permission_overwrites return values (this method return a Hash and not an Array) - event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites = event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites + event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites = event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites # rubocop:disable Lint/SelfAssignment puts(event.bot.channel(CHANNEL_EDIT, event.server).permission_overwrites.map { |_, v| "#{v.type} - #{v.id} - #{v.allow.bits} / #{v.deny.bits}" }) # Send nil to check if permission_overwrites not changed diff --git a/lib/discordrb/bot.rb b/lib/discordrb/bot.rb index 84bc987f3..1f1b83de2 100644 --- a/lib/discordrb/bot.rb +++ b/lib/discordrb/bot.rb @@ -339,7 +339,7 @@ def voice(thing) return nil unless channel server_id = channel.server.id - return @voices[server_id] if @voices[server_id] + @voices[server_id] end # Connects to a voice channel, initializes network connections and returns the {Voice::VoiceBot} over which audio @@ -1396,7 +1396,7 @@ def handle_dispatch(type, data) new_activities = (data['activities'] || []).map { |act_data| Activity.new(act_data, self) } presence_user = @users[data['user']['id'].to_i] - old_activities = (presence_user&.activities || []) + old_activities = presence_user&.activities || [] update_presence(data) # Starting a new game @@ -1700,7 +1700,7 @@ def call_event(handler, event) def handle_awaits(event) @awaits ||= {} - @awaits.each do |_, await| + @awaits.each_value do |await| key, should_delete = await.match(event) next unless key diff --git a/lib/discordrb/commands/parser.rb b/lib/discordrb/commands/parser.rb index 2d9574690..d96f21778 100644 --- a/lib/discordrb/commands/parser.rb +++ b/lib/discordrb/commands/parser.rb @@ -159,7 +159,7 @@ def execute_bare(event) escaped = false hacky_delim, hacky_space, hacky_prev, hacky_newline = [0xe001, 0xe002, 0xe003, 0xe004].pack('U*').chars - @chain.each_char.each_with_index do |char, index| + @chain.each_char.with_index do |char, index| # Escape character if char == '\\' && !escaped escaped = true diff --git a/lib/discordrb/data/component.rb b/lib/discordrb/data/component.rb index 035e22680..409166651 100644 --- a/lib/discordrb/data/component.rb +++ b/lib/discordrb/data/component.rb @@ -100,7 +100,7 @@ def initialize(data, bot) # @method link? # @return [true, false] Webhooks::View::BUTTON_STYLES.each do |name, value| - define_method("#{name}?") do + define_method(:"#{name}?") do @style == value end end diff --git a/lib/discordrb/data/embed.rb b/lib/discordrb/data/embed.rb index 546c57bd7..578285700 100644 --- a/lib/discordrb/data/embed.rb +++ b/lib/discordrb/data/embed.rb @@ -68,7 +68,7 @@ def initialize(data, message) @provider = data['provider'].nil? ? nil : EmbedProvider.new(data['provider'], self) @thumbnail = data['thumbnail'].nil? ? nil : EmbedThumbnail.new(data['thumbnail'], self) @author = data['author'].nil? ? nil : EmbedAuthor.new(data['author'], self) - @fields = data['fields'].nil? ? nil : data['fields'].map { |field| EmbedField.new(field, self) } + @fields = data['fields']&.map { |field| EmbedField.new(field, self) } end end diff --git a/lib/discordrb/data/emoji.rb b/lib/discordrb/data/emoji.rb index dc26aee58..5d81d7183 100644 --- a/lib/discordrb/data/emoji.rb +++ b/lib/discordrb/data/emoji.rb @@ -25,7 +25,7 @@ def initialize(data, bot, server = nil) @name = data['name'] @server = server - @id = data['id'].nil? ? nil : data['id'].to_i + @id = data['id']&.to_i @animated = data['animated'] process_roles(data['roles']) if server diff --git a/lib/discordrb/data/interaction.rb b/lib/discordrb/data/interaction.rb index 2e3b16561..02b0a4968 100644 --- a/lib/discordrb/data/interaction.rb +++ b/lib/discordrb/data/interaction.rb @@ -76,7 +76,7 @@ def initialize(data, bot) end @token = data['token'] @version = data['version'] - @components = @data['components']&.map { |component| Components.from_data(component, @bot) }&.compact || [] + @components = @data['components']&.filter_map { |component| Components.from_data(component, @bot) } || [] end # Respond to the creation of this interaction. An interaction must be responded to or deferred, diff --git a/lib/discordrb/data/member.rb b/lib/discordrb/data/member.rb index 0d5a3f8bb..f2cc80b2f 100644 --- a/lib/discordrb/data/member.rb +++ b/lib/discordrb/data/member.rb @@ -64,7 +64,7 @@ def initialize(data, server, bot) @bot = bot @user = bot.ensure_user(data['user']) - super @user # Initialize the delegate class + super(@user) # Initialize the delegate class @server = server @server_id = server&.id || data['guild_id'].to_i diff --git a/lib/discordrb/data/message.rb b/lib/discordrb/data/message.rb index 4066f512b..3e512aa6a 100644 --- a/lib/discordrb/data/message.rb +++ b/lib/discordrb/data/message.rb @@ -198,7 +198,7 @@ def respond(content, tts = false, embed = nil, attachments = nil, allowed_mentio # @return [Message] the resulting message. def edit(new_content, new_embeds = nil, new_components = nil) new_embeds = (new_embeds.instance_of?(Array) ? new_embeds.map(&:to_hash) : [new_embeds&.to_hash]).compact - new_components = new_components&.to_a || [] + new_components = new_components.to_a response = API::Channel.edit_message(@bot.token, @channel.id, @id, new_content, [], new_embeds, new_components) Message.new(JSON.parse(response), @bot) diff --git a/lib/discordrb/data/reaction.rb b/lib/discordrb/data/reaction.rb index 202d5795b..491f5eb49 100644 --- a/lib/discordrb/data/reaction.rb +++ b/lib/discordrb/data/reaction.rb @@ -19,7 +19,7 @@ class Reaction def initialize(data) @count = data['count'] @me = data['me'] - @id = data['emoji']['id'].nil? ? nil : data['emoji']['id'].to_i + @id = data['emoji']['id']&.to_i @name = data['emoji']['name'] end diff --git a/lib/discordrb/data/recipient.rb b/lib/discordrb/data/recipient.rb index 600c7356f..e0c046256 100644 --- a/lib/discordrb/data/recipient.rb +++ b/lib/discordrb/data/recipient.rb @@ -16,7 +16,7 @@ def initialize(user, channel, bot) raise ArgumentError, 'Tried to create a recipient for a public channel!' unless @channel.private? @user = user - super @user + super(@user) # Member attributes @mute = @deaf = @self_mute = @self_deaf = false diff --git a/lib/discordrb/data/server.rb b/lib/discordrb/data/server.rb index b868e9e84..71a538559 100644 --- a/lib/discordrb/data/server.rb +++ b/lib/discordrb/data/server.rb @@ -397,7 +397,7 @@ def add_role(role) # @!visibility private def delete_role(role_id) @roles.reject! { |r| r.id == role_id } - @members.each do |_, member| + @members.each_value do |member| new_roles = member.roles.reject { |r| r.id == role_id } member.update_roles(new_roles) end @@ -515,7 +515,7 @@ def create_channel(name, type = 0, topic: nil, bitrate: nil, user_limit: nil, pe # @param reason [String] The reason the for the creation of this role. # @return [Role] the created role. def create_role(name: 'new role', colour: 0, hoist: false, mentionable: false, permissions: 104_324_161, reason: nil) - colour = colour.respond_to?(:combined) ? colour.combined : colour + colour = colour.combined if colour.respond_to?(:combined) permissions = if permissions.is_a?(Array) Permissions.bits(permissions) @@ -830,11 +830,11 @@ def update_data(new_data = nil) @afk_timeout = new_data[:afk_timeout] || new_data['afk_timeout'] || @afk_timeout afk_channel_id = new_data[:afk_channel_id] || new_data['afk_channel_id'] || @afk_channel - @afk_channel_id = afk_channel_id.nil? ? nil : afk_channel_id.resolve_id + @afk_channel_id = afk_channel_id&.resolve_id widget_channel_id = new_data[:widget_channel_id] || new_data['widget_channel_id'] || @widget_channel - @widget_channel_id = widget_channel_id.nil? ? nil : widget_channel_id.resolve_id + @widget_channel_id = widget_channel_id&.resolve_id system_channel_id = new_data[:system_channel_id] || new_data['system_channel_id'] || @system_channel - @system_channel_id = system_channel_id.nil? ? nil : system_channel_id.resolve_id + @system_channel_id = system_channel_id&.resolve_id @widget_enabled = new_data[:widget_enabled] || new_data['widget_enabled'] @splash = new_data[:splash_id] || new_data['splash_id'] || @splash_id diff --git a/lib/discordrb/data/user.rb b/lib/discordrb/data/user.rb index b7be8500d..861794f96 100644 --- a/lib/discordrb/data/user.rb +++ b/lib/discordrb/data/user.rb @@ -90,7 +90,7 @@ def avatar_url(format = nil) attr_reader :public_flags FLAGS.each do |name, value| - define_method("#{name}?") do + define_method(:"#{name}?") do (@public_flags & value).positive? end end @@ -233,7 +233,7 @@ def process_client_status(client_status) # @!method dnd? # @return [true, false] whether this user is set to do not disturb. %i[offline idle online dnd].each do |e| - define_method("#{e}?") do + define_method(:"#{e}?") do @status.to_sym == e end end diff --git a/lib/discordrb/light/data.rb b/lib/discordrb/light/data.rb index d9576749f..d99798bb6 100644 --- a/lib/discordrb/light/data.rb +++ b/lib/discordrb/light/data.rb @@ -53,7 +53,7 @@ class LightServer < UltraLightServer # @!visibility private def initialize(data, bot) - super(data, bot) + super @bot_is_owner = data['owner'] @bot_permissions = Discordrb::Permissions.new(data['permissions']) diff --git a/lib/discordrb/permissions.rb b/lib/discordrb/permissions.rb index b9194bde7..a9af116cb 100644 --- a/lib/discordrb/permissions.rb +++ b/lib/discordrb/permissions.rb @@ -52,7 +52,7 @@ class Permissions FLAGS.each do |position, flag| attr_reader flag - define_method "can_#{flag}=" do |value| + define_method :"can_#{flag}=" do |value| new_bits = @bits if value new_bits |= (1 << position) @@ -81,7 +81,7 @@ def bits=(bits) def init_vars FLAGS.each do |position, flag| flag_set = ((@bits >> position) & 0x1) == 1 - instance_variable_set "@#{flag}", flag_set + instance_variable_set :"@#{flag}", flag_set end end @@ -194,7 +194,7 @@ def defined_permission?(action, channel = nil) # Define methods for querying permissions Discordrb::Permissions::FLAGS.each_value do |flag| - define_method "can_#{flag}?" do |channel = nil| + define_method :"can_#{flag}?" do |channel = nil| permission? flag, channel end end @@ -220,7 +220,7 @@ def defined_role_permission?(action, channel) false else # Otherwise defer to the role - role.permissions.instance_variable_get("@#{action}") || can_act + role.permissions.instance_variable_get(:"@#{action}") || can_act end end end @@ -232,9 +232,9 @@ def permission_overwrite(action, channel, id) # Otherwise, check the allow and deny objects allow = channel.permission_overwrites[id].allow deny = channel.permission_overwrites[id].deny - if allow.instance_variable_get("@#{action}") + if allow.instance_variable_get(:"@#{action}") :allow - elsif deny.instance_variable_get("@#{action}") + elsif deny.instance_variable_get(:"@#{action}") :deny end diff --git a/lib/discordrb/voice/encoder.rb b/lib/discordrb/voice/encoder.rb index 508848ae9..6e98ddb24 100644 --- a/lib/discordrb/voice/encoder.rb +++ b/lib/discordrb/voice/encoder.rb @@ -63,7 +63,7 @@ def adjust_volume(buf, mult) sample *= mult # clamp to s16 range - [32_767, [-32_768, sample].max].min + sample.clamp(-32_768, 32_767) end # After modification, make it s16le again diff --git a/spec/data/channel_spec.rb b/spec/data/channel_spec.rb index e068df8bf..656902bfb 100644 --- a/spec/data/channel_spec.rb +++ b/spec/data/channel_spec.rb @@ -19,7 +19,7 @@ shared_examples 'a Channel property' do |property_name| it 'should call #update_channel_data with data' do expect(channel).to receive(:update_channel_data).with(property_name => property_value) - channel.__send__("#{property_name}=", property_value) + channel.__send__(:"#{property_name}=", property_value) end end diff --git a/spec/overwrite_spec.rb b/spec/overwrite_spec.rb index 4362afd7e..0ced52e45 100644 --- a/spec/overwrite_spec.rb +++ b/spec/overwrite_spec.rb @@ -40,7 +40,7 @@ end it 'infers type from a User object' do - users.each do |_user_type, user| + users.each_value do |user| expect(described_class.new(user).type).to eq :member end end