This repository was archived by the owner on Apr 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBetterLog.py
More file actions
84 lines (52 loc) · 1.79 KB
/
Copy pathBetterLog.py
File metadata and controls
84 lines (52 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import threading
import eel
from Packet import Packet, Message
PRETTY_PRINT = False
CALLBACK = None
@eel.expose
def log_text(text: str):
if not PRETTY_PRINT:
# Call a JavaScript function to add the message to the log
eel.add_log_message(text)
@eel.expose
def log_outgoing(text: str):
if not PRETTY_PRINT:
# Call a JavaScript function to add the message to the log
eel.add_outgoing_message(text)
@eel.expose
def log_incoming(text: str):
if not PRETTY_PRINT:
# Call a JavaScript function to add the message to the log
eel.add_incoming_message(text)
@eel.expose
def log_message_text(text: str, sender: str, isself: bool = False):
if PRETTY_PRINT:
eel.add_message_text(text, sender, isself)
@eel.expose
def submit_message(text):
try:
CALLBACK(text)
except:
log_text('MESSAGE COULD NOT BE SENT')
# Initialize Eel with your HTML file
eel.init('web')
# Start the Eel application
thread = threading.Thread(target=eel.start, args=('log.html',))
thread.daemon = True
thread.start()
def log_packet_received(packet: Packet):
log_incoming(packet.__str__())
def log_message_received(message: Message):
log_incoming(message.__str__())
def log_packet_sent(packet: Packet):
log_outgoing(packet.__str__())
def log_message_sent(message: Message):
log_outgoing(message.__str__())
def log_packet_sent_bytes(packet: bytes):
log_packet_sent(Packet.from_bytes(packet))
def log_failed_packet_send_bytes(packet: bytes, e: Exception):
log_failed_packet_send(Packet.from_bytes(packet), e)
def log_failed_message_send(message: Message):
log_outgoing(f"FAILED TO SEND\n{message.__str__()}")
def log_failed_packet_send(packet: Packet, e: Exception):
log_outgoing(f"FAILED TO SEND\n{packet.__str__()}\n{e}")