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