any user without explicit display nick causes bot to crash
Closed this issue · 6 comments
Hello,
plugin starts ok in maubot docker 0.4.2
Config also seems ok (i just updated your chatgpt package from 0.0.4 to 0.0.7 and used the updated config template).
I also re-registered the bot within maubot.
When I open a chat, the bot joins automatically but I get no response. In maubot i see this error every time I write a message - how can I solve that? Is it a config error? Thank you!
Failed to run handler
Traceback (most recent call last):
File "/usr/lib/python3.11/site-packages/mautrix/client/syncer.py", line 236, in _catch_errors
await handler(data)
File "/data/plugins/org.jobmachine.chatgpt-v0.0.7.mbp/gpt.py", line 84, in on_message
if not await self.should_respond(event):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/plugins/org.jobmachine.chatgpt-v0.0.7.mbp/gpt.py", line 60, in should_respond
if re.search("(^|\s)(@)?" + self.name + "([ :,.!?]|$)", event.content.body, re.IGNORECASE):
~~~~~~~~~~~~~^~~~~~~~~~~
TypeError: can only concatenate str (not "NoneType") to str
seems like self.name
isn't getting resolved or set somehow... does your bot have a display nickname set? the way the code works currently, the bot will either use a name as you set it in the config file, or use the bot's displayed nick (which you can set in the maubot interface). do one of these and see if that solves the problem.
there would also be a debug log line that says DEBUG gpt plugin started with bot name: {your bots name}
. curious what that says.
Thanks, indeed the name was not set - did that.
Now I get that error, where the first line also gets through via chat:
Something went wrong: unsupported operand type(s) for +: 'NoneType' and 'str'
Traceback (most recent call last):
File "/data/plugins/org.jobmachine.chatgpt-v0.0.7.mbp/gpt.py", line 88, in on_message
context = await self.get_context(event)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/plugins/org.jobmachine.chatgpt-v0.0.7.mbp/gpt.py", line 177, in get_context
user = (await self.client.get_displayname(next_event.sender)) + ": "
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
Is the displayname something different? on the matrix homeserver, the name is set to the bot's name.
Thanks again!
yes, this time in the code it's getting the display names of all the people in the conversation to contextualize the data... seems like if anyone is missing a displayname, it will still crash.
my original code depended on the localpart of all users, but recent changes introduced by @MxMarx shifted that over to display names (a more logical choice, but sadly one more prone to issues if there isn't one set explicitly). i'll need to go through and fix that to keep the localpart as a fallback option.
i'll update this issue name to be more descriptive of the issue.
Ha, that's it, thank you! I never set my displayname and did that, now the bot is working.
I guess it's enough when you add that in a readme-format on the first page.
should be fixed by 8fea5c5