Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid stacktrace when bots send commands #133

Open
arancaytar opened this issue Feb 2, 2021 · 1 comment
Open

Avoid stacktrace when bots send commands #133

arancaytar opened this issue Feb 2, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@arancaytar
Copy link

Relevant part of the stacktrace

/home/keira/bots/huntress/vendor/sylae/huntress/src/Huntress/Permission.php:290

Huntress\Permission::filterRole(): Argument #1 ($target) must be of type CharlotteDunois\Yasmin\Models\GuildMember, CharlotteDunois\Yasmin\Models\User given, called in /home/keira/bots/huntress/vendor/sylae/huntress/src/Huntress/Permission.php on line 217

#0 /home/keira/bots/huntress/vendor/sylae/huntress/src/Huntress/Permission.php(217): Huntress\Permission->filterRole()
#1 /home/keira/bots/huntress/vendor/sylae/huntress/src/Huntress/Permission.php(156): Huntress\Permission->check()
#2 /home/keira/bots/huntress/src/Huntress/Plugin/Role.php(113): Huntress\Permission->resolve()

It looks like the assumption is that $this->context->user (when passed to Permission::filterRole()) is a GuildMember. But it's a bit odd, because in Permission::sendUnauthorizedMessage() that type is explicitly checked.

Specifically, this came up in a case where a !role command was proxied, which can't work in any case.

So I guess some of our options here are to:

  • ignore commands from bots entirely
  • specifically ignore !role commands from bots (since these would target the bot and not the user that was proxied)
  • make Permission::resolve() (or an earlier function in Permission) check the type of the EventData;:$user variable and reject if it's not a GuildMember?
@sylae
Copy link
Owner

sylae commented Feb 2, 2021

in this case the offending message was from a webhook, which isnt a GuildMember. normal bot users will still be GuildMembers. easiest way to check is $user->webhook iirc, which i'd be more than happy blanket denying somewhere in HPM.

Easiest way, i think?: Anything that depends on a user permission (ie addMemberContext or addMessageContext iirc) should probably throw an exception if it gets a webhook. Stuff that doesnt require a user context (some modules use HPM as a janky config store for channel/guild processes) should be fine with webhooks tho

@sylae sylae added the bug Something isn't working label Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants