main function tweaks

This commit is contained in:
2025-09-17 21:19:28 +02:00
parent b652dc748c
commit 3c5fafadaa

51
main.py
View File

@@ -44,27 +44,31 @@ def get_message(type: str) -> dict[str, int]:
return messages["unknown"]
def send_notification(message: dict[str, int]) -> None:
def create_embed(message: str) -> dict:
"""
Send a notification to the Discord webhook as an embed.
Create a Discord embed message.
"""
msg = get_message(message)
embed = {
"title": "Notification",
"description": msg["text"],
"color": msg["color"],
"timestamp": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
"footer": {
"text": "THC - Toke Hash Coordinated"
}
}
return embed
Args:
message (dict[str, int]): The message to send.
def send_notification(message: str) -> None:
"""
Send a notification to the Discord webhook.
"""
if not WEBHOOK_URL:
logging.error("WEBHOOK_URL not set")
return
embed = {
"title": "Notification",
"description": message["text"],
"color": message["color"],
"timestamp": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
"footer": {
"text": "Discord Webhook App"
}
}
embed = create_embed(message)
data = {"embeds": [embed]}
try:
response = requests.post(WEBHOOK_URL, json=data, timeout=10)
@@ -79,26 +83,19 @@ def send_notification(message: dict[str, int]) -> None:
logging.error(f"Error sending notification: {e}")
def test_notification() -> None:
"""
Send a test notification to verify the webhook.
"""
send_notification(get_message("test"))
def main() -> None:
"""
Main function to run the scheduler.
"""
# Schedule notifications
schedule.every().hour.at(":15").do(send_notification, get_message("reminder"))
schedule.every().hour.at(":20").do(send_notification, get_message("notification"))
schedule.every().hour.at(":45").do(send_notification, get_message("reminder"))
schedule.every().hour.at(":50").do(send_notification, get_message("halftime"))
schedule.every().hour.at(":15").do(send_notification, "reminder")
schedule.every().hour.at(":20").do(send_notification, "notification")
schedule.every().hour.at(":45").do(send_notification, "reminder")
schedule.every().hour.at(":50").do(send_notification, "halftime")
logging.info("Scheduler started.")
# Test the notification on startup
test_notification()
send_notification("test")
try:
while True: