Skip to content

Commit

Permalink
Merge pull request #1 from starspritechippy/patch-1
Browse files Browse the repository at this point in the history
✨ add trusted users kwarg to bot class
  • Loading branch information
dolfies authored May 11, 2021
2 parents dfacda7 + 84112ad commit 0940ce4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions discord/ext/commands/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,27 @@ def __init__(self, command_prefix, help_command=_default, description=None, **op
self.owner_ids = options.get('owner_ids', set())
self.strip_after_prefix = options.get('strip_after_prefix', False)

self.self_bot = options.pop('self_bot', False)
self.trusted_users = options.pop('trusted_users', [])

if self.owner_id and self.owner_ids:
raise TypeError('Both owner_id and owner_ids are set.')

if self.owner_ids and not isinstance(self.owner_ids, collections.abc.Collection):
raise TypeError(f'owner_ids must be a collection not {self.owner_ids.__class__!r}')

if options.pop('self_bot', False):
self._skip_check = lambda x, y: x != y
if self.self_bot and self.trusted_users:
raise TypeError('Both self_bot and trusted_users are set.')

if self.trusted_users and not isinstance(self.trusted_users, collections.abc.Collection):
raise TypeError(f'trusted_users must be a collection not {self.trusted_users.__class__!r}')

if self.self_bot:
self._skip_check = lambda author, _, bot_id: author != bot_id
elif self.trusted_users:
self._skip_check = lambda author, trusted, _: author not in trusted
else:
self._skip_check = lambda x, y: x == y
self._skip_check = lambda author, _, bot_id: author == bot_id

if help_command is _default:
self.help_command = DefaultHelpCommand()
Expand Down Expand Up @@ -906,7 +917,7 @@ class be provided, it must be similar enough to :class:`.Context`\'s
view = StringView(message.content)
ctx = cls(prefix=None, view=view, bot=self, message=message)

if self._skip_check(message.author.id, self.user.id):
if self._skip_check(message.author.id, self.trusted_users, self.user.id):
return ctx

prefix = await self.get_prefix(message)
Expand Down

0 comments on commit 0940ce4

Please sign in to comment.