We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent de4f757 commit 51ba505Copy full SHA for 51ba505
1 file changed
cloudbot/irc/client.py
@@ -24,6 +24,18 @@
24
}
25
26
27
+def decode(bytestring):
28
+ """
29
+ Tries to decode a bytestring using multiple encoding formats
30
31
+ for codec in ('utf-8', 'iso-8859-1', 'shift_jis', 'cp1252'):
32
+ try:
33
+ return bytestring.decode(codec)
34
+ except UnicodeDecodeError:
35
+ continue
36
+ return bytestring.decode('utf-8', errors='ignore')
37
+
38
39
class IrcClient(Client):
40
"""
41
An implementation of Client for IRC.
@@ -275,7 +287,7 @@ def data_received(self, data):
275
287
276
288
while b"\r\n" in self._input_buffer:
277
289
line_data, self._input_buffer = self._input_buffer.split(b"\r\n", 1)
278
- line = line_data.decode()
290
+ line = decode(line_data)
279
291
280
292
# parse the line into a message
281
293
if line.startswith(":"):
0 commit comments