grpc
All checks were successful
Deploy Dev / Build (pull_request) Successful in 33s
Deploy Dev / Push (pull_request) Successful in 12s
Deploy Dev / Deploy dev (pull_request) Successful in 23s

This commit is contained in:
2024-12-08 21:12:32 +03:00
parent 4b63faabef
commit 5b9c1a18b7
16 changed files with 67 additions and 106 deletions

25
daemons/updater.py Normal file
View File

@@ -0,0 +1,25 @@
import datetime
import random
from time import sleep
from utils.mongo import mongo
def update():
from main import bot, client
while True:
if client.get_config('updater')['enabled']:
fltr = {"last_time_updated": {"$lte": datetime.datetime.now() - datetime.timedelta(seconds=client.get_config('updater')['seconds_delay'])}}
if not client.get_config('updater')['send_to_single']:
fltr["chat_id"] = {"$lt": 0}
for chat in mongo.chats_collection.find(fltr):
users = list(mongo.counter_collection.find({"chat_id": chat['chat_id'], 'username': {"$ne": None}}))
if not users:
continue
user = random.choice(users)
try:
bot.send_message(chat['chat_id'], f"В этом чате давно не было активности, а как говорится, кто молчит - тот трансвестит, а трансвестит сегодня - @{user['username']}")
except:
pass
mongo.chats_collection.update_one({"chat_id": chat['chat_id']}, {"$set": {"last_time_updated": datetime.datetime.now()}})
sleep(client.get_config('updater')['seconds_delay'])