pizda-bot/updater.py
2024-03-14 20:47:21 +03:00

26 lines
1.2 KiB
Python
Raw 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 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'])