Skip to content

Commit a908ddd

Browse files
committed
Fixed author in the wrong form
1 parent d4b6a16 commit a908ddd

File tree

4 files changed

+73
-148
lines changed

4 files changed

+73
-148
lines changed

Examples/Logging/JSON files/History/2022/05/23/#David's dungeon.json

Lines changed: 0 additions & 133 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "David's py dungeon",
3+
"id": 863071397207212052,
4+
"type": "GUILD",
5+
"authors": {
6+
"909382417087881276": {
7+
"name": "[ŠSFE] Zajcek Bine",
8+
"id": 909382417087881276,
9+
"messages": [
10+
{
11+
"sent_data": {
12+
"streamed_audio": {
13+
"type:": "Youtube",
14+
"title": "Stripper Magician",
15+
"url": "https://www.youtube.com/watch?v=lDRjqI-fBVI"
16+
}
17+
},
18+
"channels": {
19+
"successful": [
20+
{
21+
"name": "test",
22+
"id": 1098345120455213126
23+
}
24+
],
25+
"failed": []
26+
},
27+
"type": "VoiceMESSAGE",
28+
"index": 1,
29+
"timestamp": "26.04.2023 20:37:36"
30+
},
31+
{
32+
"sent_data": {
33+
"streamed_audio": {
34+
"type:": "Youtube",
35+
"title": "Stripper Magician",
36+
"url": "https://www.youtube.com/watch?v=lDRjqI-fBVI"
37+
}
38+
},
39+
"channels": {
40+
"successful": [
41+
{
42+
"name": "test",
43+
"id": 1098345120455213126
44+
}
45+
],
46+
"failed": []
47+
},
48+
"type": "VoiceMESSAGE",
49+
"index": 0,
50+
"timestamp": "26.04.2023 20:35:40"
51+
}
52+
]
53+
}
54+
}
55+
}

docs/source/guide/core/logging.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,19 @@ All logs will contain keys:
4848
- "name": The name of the guild/user
4949
- "id": Snowflake ID of the guild/user
5050
- "type": object type (GUILD/USER) that generated the log.
51-
- "message_history": Array of logs for each sent message to the guild/user, the structure is message type dependant and is generated inside methods:
51+
- "authors": Dictionary which's values represent author ids and the values are dictionaries containing keys:
5252

53-
+ :py:meth:`daf.message.TextMESSAGE.generate_log_context`
54-
+ :py:meth:`daf.message.VoiceMESSAGE.generate_log_context`
55-
+ :py:meth:`daf.message.DirectMESSAGE.generate_log_context`
53+
- "name": Name of the sender (author)
54+
- "id": Snowflake ID of the sender
55+
- "messages": List of previously sent messages by the corresponding author with their context.
56+
It is message type dependent and is generated in:
5657

57-
.. seealso::
58-
:download:`Example structure <./DEP/Examples/Logging/JSON files/History/2022/05/23/#David's dungeon.json>`
58+
+ :py:meth:`daf.message.TextMESSAGE.generate_log_context`
59+
+ :py:meth:`daf.message.VoiceMESSAGE.generate_log_context`
60+
+ :py:meth:`daf.message.DirectMESSAGE.generate_log_context`
61+
62+
.. seealso::
63+
:download:`Example structure <./DEP/Examples/Logging/JSON files/History/2023/04/26/David's py dungeon.json>`
5964

6065

6166
.. only:: html

src/daf/logging/_logging.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ async def _save_log(self, guild_context: dict, message_context: dict, author_con
245245
file_exists = False
246246

247247
# Write to file
248-
with open(logging_output,'r+', encoding='utf-8') as f_writer:
248+
with open(logging_output, 'r+', encoding='utf-8') as f_writer:
249249
json_data = None
250250
if file_exists:
251251
try:
@@ -266,18 +266,16 @@ async def _save_log(self, guild_context: dict, message_context: dict, author_con
266266
json_data["authors"] = {}
267267

268268
author_id_str = str(author_context["id"])
269-
if author_id_str not in json_data["authors"]:
269+
if author_id_str not in json_data["authors"]:
270270
messages = author_context["messages"] = []
271271
json_data["authors"][author_id_str] = author_context
272272
else:
273273
messages = json_data["authors"][author_id_str]["messages"]
274274

275-
messages.insert(0,
276-
{
277-
**message_context,
278-
"index": messages[0]["index"] + 1 if len(messages) else 0,
279-
"timestamp": timestamp
280-
}
275+
messages.insert(0, {
276+
**message_context,
277+
"index": messages[0]["index"] + 1 if len(messages) else 0,
278+
"timestamp": timestamp}
281279
)
282280
json.dump(json_data, f_writer, indent=4, ensure_ascii=False)
283281
f_writer.truncate() # Remove any old data
@@ -286,7 +284,7 @@ async def _save_log(self, guild_context: dict, message_context: dict, author_con
286284
async def initialize(logger: LoggerBASE) -> None:
287285
"""
288286
Initialization coroutine for the module.
289-
287+
290288
Parameters
291289
--------------
292290
The logger manager to use for saving logs.

0 commit comments

Comments
 (0)