From f2f2ec55fed4cc57874b4997bbf2c79a3f7b16d9 Mon Sep 17 00:00:00 2001 From: Droid Date: Sun, 9 Mar 2025 21:16:37 -0400 Subject: [PATCH] GitHub Workflows & Rubocop --- .github/workflows/codeql.yml | 6 +++--- .rubocop.yml | 2 +- lib/discordrb/commands/command_bot.rb | 20 ++++---------------- lib/discordrb/commands/parser.rb | 4 ++-- lib/discordrb/data/channel.rb | 2 ++ lib/discordrb/gateway.rb | 4 ++++ 6 files changed, 16 insertions(+), 22 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f1515e901..c6aed42fe 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -33,7 +33,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -47,7 +47,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@v3 # ℹī¸ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun @@ -60,6 +60,6 @@ jobs: # ./location_of_script_within_repo/buildscript.sh - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 with: category: "/language:${{matrix.language}}" diff --git a/.rubocop.yml b/.rubocop.yml index 368fd948e..a2b46c205 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,4 @@ -require: +plugins: - rubocop-performance - rubocop-rake diff --git a/lib/discordrb/commands/command_bot.rb b/lib/discordrb/commands/command_bot.rb index 2f315628b..c4068da1b 100644 --- a/lib/discordrb/commands/command_bot.rb +++ b/lib/discordrb/commands/command_bot.rb @@ -109,7 +109,7 @@ def initialize(**attributes) spaces_allowed: attributes[:spaces_allowed].nil? ? false : attributes[:spaces_allowed], # Webhooks allowed to trigger commands - webhook_commands: attributes[:webhook_commands].nil? ? true : attributes[:webhook_commands], + webhook_commands: attributes[:webhook_commands].nil? || attributes[:webhook_commands], channels: attributes[:channels] || [], @@ -257,17 +257,9 @@ def arg_check(args, types = nil, server = nil) next arg if types[i].nil? || types[i] == String if types[i] == Integer - begin - Integer(arg, 10) - rescue ArgumentError - nil - end + Integer(arg, 10, exception: false) elsif types[i] == Float - begin - Float(arg) - rescue ArgumentError - nil - end + Float(arg, exception: false) elsif types[i] == Time begin Time.parse arg @@ -295,11 +287,7 @@ def arg_check(args, types = nil, server = nil) nil end elsif types[i] == Rational - begin - Rational(arg) - rescue ArgumentError - nil - end + Rational(arg, exception: false) elsif types[i] == Range begin if arg.include? '...' diff --git a/lib/discordrb/commands/parser.rb b/lib/discordrb/commands/parser.rb index d96f21778..8b0e51adf 100644 --- a/lib/discordrb/commands/parser.rb +++ b/lib/discordrb/commands/parser.rb @@ -32,10 +32,10 @@ def initialize(name, attributes = {}, &block) channels: attributes[:channels] || nil, # Whether this command is usable in a command chain - chain_usable: attributes[:chain_usable].nil? ? true : attributes[:chain_usable], + chain_usable: attributes[:chain_usable].nil? || attributes[:chain_usable], # Whether this command should show up in the help command - help_available: attributes[:help_available].nil? ? true : attributes[:help_available], + help_available: attributes[:help_available].nil? || attributes[:help_available], # Description (for help command) description: attributes[:description] || nil, diff --git a/lib/discordrb/data/channel.rb b/lib/discordrb/data/channel.rb index 4a49894e2..f4cf31e20 100644 --- a/lib/discordrb/data/channel.rb +++ b/lib/discordrb/data/channel.rb @@ -944,8 +944,10 @@ def link private + # rubocop:disable Lint/UselessConstantScoping # For bulk_delete checking TWO_WEEKS = 86_400 * 14 + # rubocop:enable Lint/UselessConstantScoping # Deletes a list of messages on this channel using bulk delete. def bulk_delete(ids, strict = false, reason = nil) diff --git a/lib/discordrb/gateway.rb b/lib/discordrb/gateway.rb index 1907a27c3..32e988112 100644 --- a/lib/discordrb/gateway.rb +++ b/lib/discordrb/gateway.rb @@ -656,7 +656,9 @@ def handle_error(e) LOGGER.log_exception(e) end + # rubocop:disable Lint/UselessConstantScoping ZLIB_SUFFIX = "\x00\x00\xFF\xFF".b.freeze + # rubocop:enable Lint/UselessConstantScoping def handle_message(msg) case @compress_mode @@ -794,7 +796,9 @@ def handle_internal_close(e) # - 4004: Authentication failed. Token was wrong, nothing we can do. # - 4011: Sharding required. Currently requires developer intervention. # - 4014: Use of disabled privileged intents. + # rubocop:disable Lint/UselessConstantScoping FATAL_CLOSE_CODES = [4003, 4004, 4011, 4014].freeze + # rubocop:enable Lint/UselessConstantScoping def handle_close(e) @bot.__send__(:raise_event, Events::DisconnectEvent.new(@bot))