better bug reporting
This commit is contained in:
parent
02a0d657e0
commit
c3aad850a7
@ -1,4 +1,5 @@
|
||||
import discord
|
||||
import json
|
||||
|
||||
ENCODING = "utf-8"
|
||||
|
||||
@ -15,6 +16,10 @@ class BaseModule:
|
||||
async def handle_message(self, message)-> bool:
|
||||
raise NotImplementedError
|
||||
|
||||
async def load_history(self, channel):
|
||||
messages = [{"id": message.id, "content": message.content, "date": message.created_at.strftime("%d/%m %H:%M:%S")} async for message in channel.history(limit=10)]
|
||||
return json.dumps(messages, ensure_ascii=False)
|
||||
|
||||
async def get_guild_name(self, guildId) -> str:
|
||||
guild = await self._client.fetch_guild(guildId)
|
||||
return "[Server={0}]".format(guild.name)
|
||||
|
@ -16,8 +16,15 @@ API_URL = "".join(
|
||||
MAINTAINER_ID = 151626081458192384
|
||||
|
||||
BUG_REPORT = """
|
||||
BUG REPORT from {user}:
|
||||
```{message}```
|
||||
BUG REPORT from {user} (`{user_id}`) in channel {channel} (`{channel_id}`) :
|
||||
|
||||
Message :
|
||||
> {message}
|
||||
|
||||
State :
|
||||
```json\n{state}```
|
||||
History :
|
||||
```json\n{history}```
|
||||
"""
|
||||
|
||||
ABOUT = """
|
||||
@ -46,8 +53,7 @@ class FourasModule(BaseModule):
|
||||
self._client.answers = [line.strip() for line in a_file.readlines()]
|
||||
print(f"Loaded {len(self._client.riddles)} riddles")
|
||||
|
||||
|
||||
def save(self):
|
||||
def save(self, save_to_file=True):
|
||||
dump = {}
|
||||
for key, value in self._client.ongoing_riddles.items():
|
||||
dump_channel = dict(value)
|
||||
@ -55,7 +61,7 @@ class FourasModule(BaseModule):
|
||||
dump[key.id] = dump_channel
|
||||
os.makedirs(os.path.dirname(SAVE_FILE), exist_ok=True)
|
||||
with open(SAVE_FILE, "w") as file:
|
||||
json.dump(dump, file)
|
||||
json.dump(dump, file, ensure_ascii=False)
|
||||
print('Saved fouras riddles state in file "{0}"'.format(SAVE_FILE))
|
||||
return dump
|
||||
|
||||
@ -149,13 +155,23 @@ class FourasModule(BaseModule):
|
||||
|
||||
if message_content.startswith("bug"):
|
||||
author_user = await self._client.fetch_user(MAINTAINER_ID)
|
||||
channel_name = await self.get_channel_name(message.channel)
|
||||
messages_json = await self.load_history(message.channel)
|
||||
await author_user.send(
|
||||
BUG_REPORT.format(user=message.author.mention, message=message_content, json=self.save())
|
||||
BUG_REPORT.format(
|
||||
user=message.author.mention,
|
||||
user_id=message.author.id,
|
||||
channel=channel_name,
|
||||
channel_id=message.channel.id,
|
||||
message=message_content,
|
||||
history=messages_json,
|
||||
state=self.save(False)
|
||||
)
|
||||
)
|
||||
await message.channel.send(f'Rapport de bug envoyé à {author_user.mention}\nMerci de ton feedback !')
|
||||
return True
|
||||
|
||||
broadcast_match = re.match(r"^broadcast\s+(\d+) (.*)", message_content)
|
||||
broadcast_match = re.match(r"^broadcast\s+(\d+) (.*)", message.content)
|
||||
if broadcast_match and message.author.id == MAINTAINER_ID:
|
||||
index = int(broadcast_match.group(1))
|
||||
broadcast_message = broadcast_match.group(2)
|
||||
@ -175,7 +191,7 @@ class FourasModule(BaseModule):
|
||||
|
||||
if message_content == "save fouras":
|
||||
if(message.author.id == 151626081458192384):
|
||||
json_str = "```json\n{0}```".format(json.dumps(self.save(), ensure_ascii=False, indent=4))
|
||||
json_str = "```json\n{0}```".format(json.dumps(self.save(), ensure_ascii=False, indent=2))
|
||||
await message.author.send(json_str)
|
||||
return True
|
||||
|
||||
|
@ -33,10 +33,10 @@ class RhymesModule(BaseModule):
|
||||
print(str)
|
||||
return str
|
||||
|
||||
def save(self):
|
||||
def save(self, save_to_file=True):
|
||||
os.makedirs(os.path.dirname(SAVE_FILE), exist_ok=True)
|
||||
with open(SAVE_FILE, "w") as file:
|
||||
json.dump(self.guild_config, file)
|
||||
json.dump(self.guild_config, file, ensure_ascii=False, indent=2)
|
||||
print('Saved poilau state in file "{0}"'.format(SAVE_FILE))
|
||||
|
||||
def get_last_word(self, ch: str) -> str:
|
||||
@ -72,21 +72,21 @@ class RhymesModule(BaseModule):
|
||||
sleeping_time = "{:.2f} s".format(max(0, value["cooldown"] - time.time()))
|
||||
dump[channel_name] = {"cooldown": sleeping_time, "self-control": value["self-control"]}
|
||||
await message.author.send(
|
||||
"```json\n{0}```".format(json.dumps(dump, ensure_ascii=False, indent=4))
|
||||
"```json\n{0}```".format(json.dumps(dump, ensure_ascii=False, indent=2))
|
||||
)
|
||||
return True
|
||||
|
||||
if message_content == "save poilau":
|
||||
if(message.author.id == 151626081458192384):
|
||||
self.save()
|
||||
json_str = "```json\n{0}```".format(json.dumps(self.guild_config, ensure_ascii=False, indent=4))
|
||||
json_str = "```json\n{0}```".format(json.dumps(self.guild_config, ensure_ascii=False, indent=2))
|
||||
await message.author.send(json_str)
|
||||
return True
|
||||
|
||||
if message_content == "load poilau":
|
||||
if(message.author.id == 151626081458192384):
|
||||
await message.author.send(self.load())
|
||||
json_str = "```json\n{0}```".format(json.dumps(self.guild_config, ensure_ascii=False, indent=4))
|
||||
json_str = "```json\n{0}```".format(json.dumps(self.guild_config, ensure_ascii=False, indent=2))
|
||||
await message.author.send(json_str)
|
||||
return True
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user