modmail-dev / Modmail

A Discord bot that functions as a shared inbox between staff and members, similar to Reddit's Modmail.
https://docs.modmail.dev
GNU Affero General Public License v3.0
1.57k stars 4.59k forks source link

[BUG]: Modmail thinks a channel is a thread if a user ID is found within the topics #3114

Closed Taaku18 closed 2 years ago

Taaku18 commented 2 years ago

Bot Version

v3.10.2

How are you hosting Modmail?

Other

Error Logs

See section below:

Screenshots

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "/modmailbot/bot.py", line 1141, in on_message
    await self.process_commands(message)
  File "/modmailbot/bot.py", line 1148, in process_commands
    return await self.process_dm_modmail(message)
  File "/modmailbot/bot.py", line 907, in process_dm_modmail
    thread = await self.threads.find(recipient=message.author)
  File "/modmailbot/core/thread.py", line 1215, in find
    thread = await Thread.from_channel(self, channel)
  File "/modmailbot/core/thread.py", line 129, in from_channel
    recipient = manager.bot.get_user(recipient_id) or await manager.bot.fetch_user(recipient_id)
  File "/usr/local/lib/python3.9/site-packages/discord/client.py", line 1384, in fetch_user
    data = await self.http.get_user(user_id)
  File "/usr/local/lib/python3.9/site-packages/discord/http.py", line 254, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In user_id: snowflake value should be greater than or equal to 0.

Additional Information

Currently any @user (<@!1234>) or just the ID in a non-related channel's topic would cause Modmail to believe that the user has an open thread there. When the user do contact Modmail, that error would be raised.

There needs to be a better check here: https://github.com/kyb3r/modmail/blob/master/core/thread.py#L1209

Instead of str(recipient_id) in x.topic, use x.topic and utils.match_user_id(x.topic) == recipient_id.

StephenDaDev commented 2 years ago

@Taaku18 Is this still an issue after 4JR's PR?

Taaku18 commented 2 years ago

@Taaku18 Is this still an issue after 4JR's PR?

Nope, should be fixed.