Closed greenaar closed 4 months ago
Can you create a PR for this please?
https://github.com/errbotio/err-backend-discord/pull/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.
Thanks for your contribution. If others encounter a problem with the patch, they're most welcome to provide fixes.
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 "" \
-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:
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
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.