got bored added still-alive ping and active goober instances connected to goober-central

This commit is contained in:
WhatDidYouExpect 2025-07-01 20:26:48 +02:00
parent bcb1046b9d
commit a8c520002e
4 changed files with 30 additions and 3 deletions

View file

@ -1,4 +1,6 @@
{ {
"error_fetching_active_users": "Error fetching active users: {error}",
"error_sending_alive_ping": "Error sending alive ping: {error}",
"already_started": "I've already started! I'm not updating...", "already_started": "I've already started! I'm not updating...",
"please_restart": "Please Restart goober!", "please_restart": "Please Restart goober!",
"local_ahead": "Local {remote}/{branch} is ahead and/or up to par. Not Updating...", "local_ahead": "Local {remote}/{branch} is ahead and/or up to par. Not Updating...",

View file

@ -1,4 +1,6 @@
{ {
"error fetching_active_users": "Errore nel recupero degli utenti attivi:",
"error_sending_alive_ping": "Errore nell'invio di aliveping:",
"already_started": "Sono già avviato! Non aggiorno...", "already_started": "Sono già avviato! Non aggiorno...",
"please_restart": "Riavvia goober!", "please_restart": "Riavvia goober!",
"local_ahead": "Il ramo locale {remote}/{branch} è aggiornato o avanti. Nessun aggiornamento...", "local_ahead": "Il ramo locale {remote}/{branch} è aggiornato o avanti. Nessun aggiornamento...",

27
bot.py
View file

@ -8,6 +8,7 @@ import subprocess
import tempfile import tempfile
import shutil import shutil
import uuid import uuid
import asyncio
from modules.globalvars import * from modules.globalvars import *
from modules.prestartchecks import start_checks from modules.prestartchecks import start_checks
@ -74,6 +75,25 @@ if not markov_model:
generated_sentences = set() generated_sentences = set()
used_words = set() used_words = set()
async def fetch_active_users():
try:
response = requests.get(f"{VERSION_URL}/active-users")
if response.status_code == 200:
return response.text.strip()
else:
return "?"
except Exception as e:
print(f"{RED}{get_translation(LOCALE, 'error_fetching_active_users')}{RESET} {e}")
return "?"
async def send_alive_ping_periodically():
while True:
try:
requests.post(f"{VERSION_URL}/aliveping", json={"name": NAME})
except Exception as e:
print(f"{RED}{get_translation(LOCALE, 'error_sending_alive_ping')}{RESET} {e}")
await asyncio.sleep(60)
# Event: Called when the bot is ready # Event: Called when the bot is ready
@bot.event @bot.event
async def on_ready(): async def on_ready():
@ -83,15 +103,18 @@ async def on_ready():
folder_name = "cogs" folder_name = "cogs"
if launched == True: if launched == True:
return return
# create folder logic only existed to prevent errors from upgrading from older versions of goober, now got nuked because its been like a billion versions since then
await load_cogs_from_folder(bot) await load_cogs_from_folder(bot)
try: try:
synced = await bot.tree.sync() synced = await bot.tree.sync()
print(f"{GREEN}{get_translation(LOCALE, 'synced_commands')} {len(synced)} {get_translation(LOCALE, 'synced_commands2')} {RESET}") print(f"{GREEN}{get_translation(LOCALE, 'synced_commands')} {len(synced)} {get_translation(LOCALE, 'synced_commands2')} {RESET}")
slash_commands_enabled = True slash_commands_enabled = True
ping_server() # ping_server from modules/central.py ping_server() # ping_server from modules/central.py
# --- Mostra utenti attivi ---
active_users = await fetch_active_users()
print(f"{GREEN}Utenti attivi: {active_users}{RESET}")
print(f"{GREEN}{get_translation(LOCALE, 'started').format(name=NAME)}{RESET}") print(f"{GREEN}{get_translation(LOCALE, 'started').format(name=NAME)}{RESET}")
# --- Avvia il task periodico ---
bot.loop.create_task(send_alive_ping_periodically())
except discord.errors.Forbidden as perm_error: except discord.errors.Forbidden as perm_error:
print(f"{RED}Permission error while syncing commands: {perm_error}{RESET}") print(f"{RED}Permission error while syncing commands: {perm_error}{RESET}")
print(f"{RED}Make sure the bot has the 'applications.commands' scope and is invited with the correct permissions.{RESET}") print(f"{RED}Make sure the bot has the 'applications.commands' scope and is invited with the correct permissions.{RESET}")

View file

@ -39,5 +39,5 @@ arch = platform.machine()
slash_commands_enabled = False slash_commands_enabled = False
launched = False launched = False
latest_version = "0.0.0" latest_version = "0.0.0"
local_version = "1.0.5" local_version = "1.0.6"
os.environ['gooberlocal_version'] = local_version os.environ['gooberlocal_version'] = local_version