Initial version of Telegram admin bot
This commit is contained in:
17
locks.py
Normal file
17
locks.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from pathlib import Path
|
||||
import time
|
||||
|
||||
LOCK_DIR = Path("/var/run/tg-bot")
|
||||
LOCK_DIR.mkdir(exist_ok=True)
|
||||
|
||||
def acquire(name: str) -> bool:
|
||||
path = LOCK_DIR / f"{name}.lock"
|
||||
if path.exists():
|
||||
return False
|
||||
path.write_text(str(time.time()))
|
||||
return True
|
||||
|
||||
def release(name: str):
|
||||
path = LOCK_DIR / f"{name}.lock"
|
||||
if path.exists():
|
||||
path.unlink()
|
||||
Reference in New Issue
Block a user