Snaacky / chiya

A moderation-heavy general purpose Discord bot
The Unlicense
38 stars 11 forks source link

[BUG] The bot doesn't handle other character encodings #29

Closed Snaacky closed 3 years ago

Snaacky commented 3 years ago

Describe the bug If a user has characters in their name from other character encodings such as symbols from latin-1, it breaks bot features. Interestingly enough, things like !warns will still say they went through successfully on the mods end but the end-user will never receive the DM.

To Reproduce Steps to reproduce the behavior:

  1. Add a character like "ඞ" to your name
  2. Try warning yourself

Expected behavior Other character encodings not to break the bot.

Screenshots N/A

Additional context Chat context: https://canary.discord.com/channels/622243127435984927/828021856358367272/828240662591176778

Log from console:

 --- Logging error ---
0|chiya    | Traceback (most recent call last):
0|chiya    |   File "/usr/lib/python3.8/logging/__init__.py", line 1084, in emit
0|chiya    |     stream.write(msg + self.terminator)
0|chiya    | UnicodeEncodeError: 'latin-1' codec can't encode character '\u014d' in position 63: ordinal not in range(256)
0|chiya    | Call stack:
0|chiya    |   File "/home/snaacky/Chiya/chiya.py", line 56, in <module>
0|chiya    |     bot.run(config.token)
0|chiya    |   File "/home/snaacky/.local/lib/python3.8/site-packages/discord/client.py", line 708, in run
0|chiya    |     loop.run_forever()
0|chiya    |   File "/usr/lib/python3.8/asyncio/base_events.py", line 570, in run_forever
0|chiya    |     self._run_once()
0|chiya    |   File "/usr/lib/python3.8/asyncio/base_events.py", line 1859, in _run_once
0|chiya    |     handle._run()
0|chiya    |   File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
0|chiya    |     self._context.run(self._callback, *self._args)
0|chiya    |   File "/home/snaacky/.local/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
0|chiya    |     await coro(*args, **kwargs)
0|chiya    |   File "/home/snaacky/Chiya/cogs/listeners/member_updates.py", line 79, in on_member_remove
0|chiya    |     log.info(f'{member} has left {member.guild.name}.')
0|chiya    | Message: 'Sh\u014dto#6905 has left /r/animepiracy.'```

--- Logging error ---
0|chiya    | Traceback (most recent call last):
0|chiya    |   File "/usr/lib/python3.8/logging/__init__.py", line 1084, in emit
0|chiya    |     stream.write(msg + self.terminator)
0|chiya    | UnicodeEncodeError: 'latin-1' codec can't encode character '\U0001f62d' in position 88: ordinal not in range(256)
0|chiya    | Call stack:
0|chiya    |   File "/home/snaacky/Chiya/chiya.py", line 56, in <module>
0|chiya    |     bot.run(config.token)
0|chiya    |   File "/home/snaacky/.local/lib/python3.8/site-packages/discord/client.py", line 708, in run
0|chiya    |     loop.run_forever()
0|chiya    |   File "/usr/lib/python3.8/asyncio/base_events.py", line 570, in run_forever
0|chiya    |     self._run_once()
0|chiya    |   File "/usr/lib/python3.8/asyncio/base_events.py", line 1859, in _run_once
0|chiya    |     handle._run()
0|chiya    |   File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
0|chiya    |     self._context.run(self._callback, *self._args)
0|chiya    |   File "/home/snaacky/.local/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
0|chiya    |     await coro(*args, **kwargs)
0|chiya    |   File "/home/snaacky/Chiya/cogs/listeners/message_updates.py", line 36, in on_message_delete
0|chiya    |     log.info(f"{message.author} was deleted: {message.clean_content}")
0|chiya    | Message: 'Snaacky#0001 was deleted: \U0001f62d'

and so on.

Snaacky commented 3 years ago

Fixed by Dockerization.