mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 03:38:53 -05:00
[Trivia] Properly deal with trivia lists' encoding
Probably.
This commit is contained in:
parent
c6fcdd3449
commit
59979933e0
@ -8,6 +8,7 @@ import datetime
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import chardet
|
||||||
|
|
||||||
class Trivia:
|
class Trivia:
|
||||||
"""General commands."""
|
"""General commands."""
|
||||||
@ -152,8 +153,16 @@ class TriviaSession():
|
|||||||
await self.send_table()
|
await self.send_table()
|
||||||
trivia_manager.trivia_sessions.remove(self)
|
trivia_manager.trivia_sessions.remove(self)
|
||||||
|
|
||||||
|
def guess_encoding(self, trivia_list):
|
||||||
|
with open(trivia_list, "rb") as f:
|
||||||
|
try:
|
||||||
|
return chardet.detect(f.read())["encoding"]
|
||||||
|
except:
|
||||||
|
return "ISO-8859-1"
|
||||||
|
|
||||||
async def load_list(self, qlist):
|
async def load_list(self, qlist):
|
||||||
with open(qlist, "r", encoding="ISO-8859-1") as f:
|
encoding = self.guess_encoding(qlist)
|
||||||
|
with open(qlist, "r", encoding=encoding) as f:
|
||||||
qlist = f.readlines()
|
qlist = f.readlines()
|
||||||
parsed_list = []
|
parsed_list = []
|
||||||
for line in qlist:
|
for line in qlist:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user