upgrade: abuse recall on dedicated boards, junk-title and traffic-noise filters, single-instance bot lock

This commit is contained in:
ENI
2026-10-26 16:28:18 +03:00
parent 077694f9e4
commit 1c32a5c630
2 changed files with 44 additions and 0 deletions

View File

@@ -589,5 +589,34 @@ def run_forever():
time.sleep(0.3)
def _single_instance():
"""Один процесс на токен: второй инстанс выходит, иначе TelegramConflictError и бот молчит."""
import os, sys, time, tempfile
path = os.path.join(tempfile.gettempdir(), "omni_bot.lock")
try:
if os.path.exists(path):
age = time.time() - os.path.getmtime(path)
try:
pid = int((open(path, encoding="utf-8").read() or "0").strip() or 0)
except ValueError:
pid = 0
if pid and age < 6 * 3600:
alive = False
try:
import psutil
alive = psutil.pid_exists(pid) and "omni" in " ".join(psutil.Process(pid).cmdline() or [])
except Exception:
alive = False
if alive:
print("уже запущен pid %s - выхожу" % pid, flush=True)
sys.exit(0)
open(path, "w", encoding="utf-8").write(str(os.getpid()))
os.utime(path, None)
except Exception as e:
print("lock skip", e, flush=True)
if __name__ == "__main__":
_single_instance()
run_forever()