Skip to content

Commit 0144b01

Browse files
authored
v1.8 (#74)
- JSON Logging [For easier parsing with different programs & compatibility with future addition of SQL logs] - Auto remove channels if they were deleted (messages will still be "sent" even if no channels remain making empty logs) - Updated the Pycord library to it's latest version
1 parent 704ce16 commit 0144b01

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2607
-3584
lines changed

DOC.md

Lines changed: 158 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
- [framework.**data_function**](#frameworkdata_function)
4343
- [**Logging**](#logging)
4444
- [**LOG OF SENT MESSAGES**](#log-of-sent-messages)
45+
- [**Example**](#example-4)
4546
- [**Trace messages**](#trace-messages)
4647
- [**Regarding Pycord/discord.py**](#regarding-pycorddiscordpy)
4748

@@ -328,7 +329,7 @@ framework.VoiceMESSAGE(
328329
- token : str = access token for account
329330
- server_list : list = List of [framework.GUILD](#frameworkguild) objects
330331
- is_user : bool = Set to True if token is from an user account and not a bot account
331-
- user_callback : function = User callback function (gets called after framework is ran)
332+
- user_callback : function = User callback async function (gets called after framework is ran)
332333
- server_log_output : str = Path where the server log files will be created
333334
- debug : bool = Print trace message to the console,
334335
usefull for debugging if you feel like something is not working
@@ -361,7 +362,7 @@ It is used to fully shutdown the framework and then **exit** out of the program.
361362

362363
## framework.**data_function**
363364

364-
- This decorator accepts a function as it's parameter and then returns a object that will be called by the framework. To use an <u>user defined function as parameter</u> to the [framework.TextMESSAGE/framework.VoiceMESSAGE](#frameworktextmessage--frameworkvoicemessage) data parameter, you **MUST** use this decorator beforehand. Please see the **Examples** folder.
365+
- This decorator accepts a function as it's parameter and then returns a object that will be called by the framework. To use an <u>user defined function as parameter</u> to the [framework.TextMESSAGE/framework.VoiceMESSAGE/DirectMESSAGE](#frameworkxxxmessage) data parameter, you **MUST** use this decorator beforehand. Please see the **Examples** folder.
365366
- Usage:
366367
```py
367368
import datetime
@@ -397,7 +398,10 @@ It is used to fully shutdown the framework and then **exit** out of the program.
397398
data=some_other_function(),
398399
channel_ids= [21345, 23132],
399400
start_now=True
400-
),
401+
)
402+
],
403+
generate_log=True
404+
),
401405
fw.USER(
402406
user_id=123456789,
403407
messages_to_send=[
@@ -415,9 +419,6 @@ It is used to fully shutdown the framework and then **exit** out of the program.
415419
],
416420
generate_log=True
417421
)
418-
],
419-
generate_log=True
420-
)
421422
]
422423

423424
...
@@ -426,13 +427,157 @@ It is used to fully shutdown the framework and then **exit** out of the program.
426427

427428
# **Logging**
428429
## **LOG OF SENT MESSAGES**
429-
The framework can keep a log of sent messages for **each guild/server**. To enable file logging of sent messages, set the parameter **Generate file log** to True inside each [GUILD OBJECT](#frameworkguild).<br>
430-
Inside the log you will find data of what was sent, a channel list it succeeded to send this message and a channel list of the ones it failed (If it failed due to slow mode, the message will be sent as soon as possible, overwriting the default period) <br>
431-
All of these file logs will be Markdown files.<br><br>
432-
![TextMESSAGE log](documentation_dep/msg_log_1.png)
433-
<br><br>
434-
![VoiceMESSAGE log](documentation_dep/msg_log_2.png)
435-
<br>
430+
The framework allows to log sent messages for each GUILD/USER (if you set the "generate_log" to True inside the [**GUILD**](#frameworkguild) or [**USER**](#frameworkuser) object).
431+
The logs are writen in the JSON format and saved into a .json file, that has the name of the guild or an user you were sending messages into.
432+
The .json files are fragmantated by day and stored into folder "Year/Month/Day", this means that each day a new json file will be generated for that specific day for easier managing,
433+
for example, if today is 13.07.2022, the log will be saved into the file that is located in
434+
```
435+
History
436+
└───2022
437+
│ └───07
438+
│ └───13
439+
| └─── #David's dungeon.json
440+
```
441+
442+
- name -- The display name of the guild or an user
443+
- id -- The discord's snowflake ID of the guild or the user
444+
- type -- The type of object that created this log ([GUILD](#frameworkguild) or [USER](#frameworkuser))
445+
- message_history -- A list of all the message logs, this is depandant on the type of [**xxxMESSAGE**](#frameworkxxxmessage):
446+
- for **TextMESSAGE**:
447+
- sent_data -- contains the information about the sent data, can contain (the following keys are only present if that type of data was sent):
448+
- sent_text -- the text that was sent
449+
- sent_embed -- The embed that was sent, can contain the following (it only contains certain item if it was specified in the embed):
450+
- title
451+
- author
452+
- thumbnail
453+
- image
454+
- description
455+
- color
456+
- fields -- list of the embedded fields, each field contains:
457+
- inline -- bool variable that specifies if the field was inline with the prev. or next field
458+
- name -- name of the field
459+
- content -- text inside the field body
460+
- sent_files -- List of paths to the sent files
461+
- channels -- dictionary of channels, contains:
462+
- successful -- list of channels that the message was successfuly sent to, contains:
463+
- name
464+
- id
465+
- failed -- list of channels that the message failed to be sent to, contains:
466+
- name
467+
- id
468+
- reason
469+
- type -- This is always TextMESSAGE
470+
- mode -- The sending mode ("send", "edit", "clear-send")
471+
- index -- Index of the log, new items are added to the top of the list
472+
- timestamp -- The timestamp of the message
473+
474+
- for **VoiceMESSAGE**:
475+
- streamed_audio -- The audio file that was streamed to the channels
476+
- channels -- dictionary of channels, contains:
477+
- successful -- list of channels that the message was successfuly sent to, contains:
478+
- name
479+
- id
480+
- failed -- list of channels that the message failed to be sent to, contains:
481+
- name
482+
- id
483+
- reason
484+
- type -- This is always VoiceMESSAGE
485+
- index -- Index of the log, new items are added to the top of the list
486+
- timestamp -- The timestamp of the message
487+
488+
- for **DirectMESSAGE**:
489+
- sent_data -- contains the information about the sent data, can contain (the following keys are only present if that type of data was sent):
490+
- This is exactly the same as in **TextMESSAGE**
491+
- success_info -- dictionary containing:
492+
- success -- bool variable that signals that sending was successful
493+
- reason -- [only present if success is false] The reason why sending failed
494+
- type -- This is always DirectMESSAGE
495+
- mode -- The sending mode ("send", "edit", "clear-send")
496+
- index -- Index of the log, new items are added to the top of the list
497+
- timestamp -- The timestamp of the message
498+
499+
### **Example**
500+
```json
501+
{
502+
"name": "\\David's dungeon",
503+
"id": 863071397207212052,
504+
"type": "GUILD",
505+
"message_history": [
506+
{
507+
"sent_data": {
508+
"text": "First message"
509+
},
510+
"channels": {
511+
"successful": [
512+
{
513+
"name": "spam",
514+
"id": 964251195168423999
515+
}
516+
],
517+
"failed": []
518+
},
519+
"type": "TextMESSAGE",
520+
"mode": "send",
521+
"index": 3,
522+
"timestamp": "18.04.2022 13:07:12"
523+
},
524+
{
525+
"sent_data": {
526+
"text": "First message"
527+
},
528+
"channels": {
529+
"successful": [
530+
{
531+
"name": "spam",
532+
"id": 964251195168423999
533+
}
534+
],
535+
"failed": []
536+
},
537+
"type": "TextMESSAGE",
538+
"mode": "send",
539+
"index": 2,
540+
"timestamp": "18.04.2022 13:07:07"
541+
},
542+
{
543+
"sent_data": {
544+
"text": "First message"
545+
},
546+
"channels": {
547+
"successful": [
548+
{
549+
"name": "spam",
550+
"id": 964251195168423999
551+
}
552+
],
553+
"failed": []
554+
},
555+
"type": "TextMESSAGE",
556+
"mode": "send",
557+
"index": 1,
558+
"timestamp": "18.04.2022 13:07:02"
559+
},
560+
{
561+
"sent_data": {
562+
"text": "First message"
563+
},
564+
"channels": {
565+
"successful": [
566+
{
567+
"name": "spam",
568+
"id": 964251195168423999
569+
}
570+
],
571+
"failed": []
572+
},
573+
"type": "TextMESSAGE",
574+
"mode": "send",
575+
"index": 0,
576+
"timestamp": "18.04.2022 13:06:57"
577+
}
578+
]
579+
}
580+
```
436581

437582
## **Trace messages**
438583
In case you feel like the framework is not doing it's job properly, eg. you feel like some messages aren't being send or the framework just stops without advertising, the framework offers **console logging** of **trace** messages. Trace messages can be **informative** (eg. which account is logged in), they can be **warnings** (eg. some channels could not be found),<br>

Examples/Additional Application Layer Example/Scheduled messages/BOT/main_obv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def get_data(ch_id):
235235
return None
236236

237237

238-
def main():
238+
async def main():
239239
"""
240240
~ main ~
241241
@Param: void

Examples/DirectMESSAGE/main_send_string.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
data="First message", # Data you want to sent to the function (Can be of types : str, embed, file, list of types to the left
1919
# or function that returns any of above types(or returns None if you don't have any data to send yet),
2020
# where if you pass a function you need to use the framework.FUNCTION decorator on top of it ).
21-
channel_ids=[123456789], # List of ids of all the channels you want this message to be sent into
2221
mode="send", # "send" will send a new message every time, "edit" will edit the previous message, "clear-send" will delete
2322
# the previous message and then send a new one
2423
start_now=True # Start sending now (True) or wait until period

0 commit comments

Comments
 (0)