pizda-bot/daemons/updater.py
emmatveev 5b9c1a18b7
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
grpc
2024-12-08 21:12:32 +03:00

26 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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'])