Skip to content

Commit

Permalink
feat: work around discordrb's ignore_bots with whitelist behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
gregdan3 committed Oct 13, 2022
1 parent 46be006 commit 2799331
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/global.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ modules:

default_prefix: '.'

bot_id_allowlist:
- 204255221017214977

# vim: ft=yaml
17 changes: 16 additions & 1 deletion lib/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.init_bot
name: 'QueryBot',
prefix: method(:cmd_prefix),
fancy_log: true,
ignore_bots: true,
ignore_bots: false,
no_permission_message: 'You are not allowed to do that',
help_command: false,
intents: Discordrb::INTENTS.keys - %i[
Expand Down Expand Up @@ -78,3 +78,18 @@ def self.run!
end
# rubocop: enable Metrics/MethodLength, Metrics/AbcSize
end

# monkey-patch for reimplementing ignore_bot with a whitelist
module CommandEventIntercept
def call(event, arguments, _chained = false, _check_permissions = true)
return if event.author.bot_account && !(QBot.config.bot_id_allowlist.include? event.author.id)

super(event, arguments, _chained, _check_permissions)
end
end

module Discordrb::Commands
class Command
prepend CommandEventIntercept
end
end

0 comments on commit 2799331

Please sign in to comment.