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

Errbot tries to process webhooks as if they are users, can't find a username, and raises ValueError. #67

Closed
greenaar opened this issue Apr 21, 2024 · 3 comments

Comments

@greenaar
Copy link
Contributor

greenaar commented Apr 21, 2024

This took me the better part of an afternoon to identify, mostly because I thought it was something else. (I thought it was related to actions I was taking as a user).

ValueError: Failed to get the user 1231072357033185361

This occurs when curl webhook posts into a discord channel Errbot is monitoring.

In this case, fail2ban, as shown here:

actionstop = curl -X POST "<discord_webhook_url>"
-H "Content-Type: application/json"
-d '{"username": "Fail2Ban", "content":":no_entry: The [] jail has been stopped"}'

(with or without "username":"Fail2Ban", doesn't seem to matter)

It tries to use on_message() against it (from err-backend-discord.py) -- the first thing it does is

err_msg.frm = DiscordRoomOccupant(msg.author.id, msg.channel.id)

which immediately does

super().init(user_id)

And fails here:

    self.discord_user = DiscordPerson.client.get_user(self._user_id)
    if self.discord_user is None:
        raise ValueError(f"Failed to get the user {self._user_id}")

Unsurprisingly, because it's not a real user, so you can't reference a username. discord_user will always return 'None' in this case.

My workaround was to switch the raise in room.py (~line 79) to:

log.info("Ignoring message from id %s, username is %s, which means it is likely a webhook.", self._user_id, username)

and to add this around line 100 of err-backend-discord.py

    if msg.author.bot:
        return

I.e. this is not a person, so do not continue to process them.

I'm not convinced this is anything like an ideal result, but in the short term it silences this error. I'm open to alternatives, and I'd happily try my hand at writing a patch that is better than this hack.

Hopefully this issue helps someone else who sees this in their logs.

@nzlosh
Copy link
Collaborator

nzlosh commented Apr 22, 2024

Can you create a PR for this please?

@greenaar
Copy link
Contributor Author

#68 here you go. I'm using this successfully - though I'll reiterate, I'm not entirely sure it's the correct path. It's a simple patch at least.

@nzlosh
Copy link
Collaborator

nzlosh commented Apr 22, 2024

Thanks for your contribution. If others encounter a problem with the patch, they're most welcome to provide fixes.

@nzlosh nzlosh closed this as completed Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants