added modifications

This commit is contained in:
thom2305 2025-04-28 19:40:03 -04:00
parent 0b10c84f90
commit 21ee8b290e
No known key found for this signature in database
GPG Key ID: 0171038FEE1BEF12
4 changed files with 105 additions and 104 deletions

11
bot.py
View File

@ -8,6 +8,7 @@ import logging
import os
import sqlite3
import mysql.connector
import sys
from discord.ext import commands
from mysql.connector import Error
from dotenv import load_dotenv
@ -19,7 +20,7 @@ class ColoredFormatter(logging.Formatter):
"""Adds colors to log levels"""
COLORS = {
'DEBUG': Fore.CYAN,
'INFO': Fore.GREEN,
'INFO': Fore.BLUE,
'WARNING': Fore.YELLOW,
'ERROR': Fore.RED,
'CRITICAL': Fore.RED + Style.BRIGHT
@ -33,10 +34,10 @@ class ColoredFormatter(logging.Formatter):
# Your original config with colors added
logging.basicConfig(
level=logging.INFO,
level=logging.DEBUG,
format='%(levelname)s at %(asctime)s : %(message)s',
datefmt='%H:%M:%S',
handlers=[logging.StreamHandler()]
handlers=[logging.StreamHandler(sys.stderr)]
)
# Apply the colored formatter
@ -110,7 +111,7 @@ class LeaderElection:
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(TIMEOUT)
s.connect((TAILSCALE_IP1, LOCK_PORT))
s.connect((TAILSCALE_IP2, LOCK_PORT))
return True
except (ConnectionRefusedError, socket.timeout, OSError):
return False
@ -130,7 +131,7 @@ def health_check(leader_election):
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(TIMEOUT)
s.connect((TAILSCALE_IP2, LOCK_PORT))
s.connect((TAILSCALE_IP1, LOCK_PORT))
except:
# Lost leadership
#print("Lost leadership")