Added a ping/pong function from the bot to the server to ensure connection

This commit is contained in:
ComputerTech312 2024-02-27 12:17:48 +01:00
parent 9ef2904018
commit 03d84e0f86
3 changed files with 11 additions and 1 deletions

BIN
.\data\database.db Normal file

Binary file not shown.

3
.gitignore vendored
View file

@ -4,4 +4,5 @@ logs
test.json
elitebot
.idea
venv
venv
test.yaml

View file

@ -156,12 +156,21 @@ class Bot:
self.connected = False
return
async def send_ping(self):
while True:
await asyncio.sleep(60)
await self.ircsend(f'PING :{self.config["Connection"].get("Hostname")}')
async def start(self):
ping_task = None
while True:
if not self.connected:
try:
await self.connect()
self.connected = True
# Start the ping task after the bot has connected
if ping_task is None or ping_task.done():
ping_task = asyncio.create_task(self.send_ping())
except Exception as e:
self.logger.error(f'Connection error: {e}')
await asyncio.sleep(60)