grpc
This commit is contained in:
25
daemons/updater.py
Normal file
25
daemons/updater.py
Normal 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'])
|
||||
Reference in New Issue
Block a user