You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
589 B
28 lines
589 B
import datetime
|
|
|
|
class Message:
|
|
"""
|
|
Represents a message with timestamp and optional metadata.
|
|
|
|
Usage
|
|
--------------
|
|
mes = Message(
|
|
sender = "Kye",
|
|
content = "message"
|
|
)
|
|
|
|
print(mes)
|
|
"""
|
|
|
|
def __init__(self, sender, content, metadata=None):
|
|
self.timestamp = datetime.datetime.now()
|
|
self.sender = sender
|
|
self.content = content
|
|
self.metadata = metadata or {}
|
|
|
|
def __repr__(self):
|
|
"""
|
|
__repr__ means
|
|
"""
|
|
return f"{self.timestamp} - {self.sender}: {self.content}"
|