This commit is contained in:
emmatveev 2024-03-07 19:58:02 +03:00
parent b6c0be0d00
commit 7c730cd831
4 changed files with 61 additions and 0 deletions

View File

@ -20,6 +20,23 @@ services:
parallelism: 1
order: start-first
updater:
image: mathwave/sprint-repo:pizda-bot
command: updater
environment:
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
MONGO_HOST: "mongo.develop.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
STAGE: "development"
deploy:
mode: replicated
restart_policy:
condition: any
update_config:
parallelism: 1
order: start-first
pizda-bot-nginx:
image: mathwave/sprint-repo:pizda-bot
command: api

View File

@ -20,6 +20,23 @@ services:
parallelism: 1
order: start-first
updater:
image: mathwave/sprint-repo:pizda-bot
command: updater
environment:
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_PROD
MONGO_HOST: "mongo.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
STAGE: "production"
deploy:
mode: replicated
restart_policy:
condition: any
update_config:
parallelism: 1
order: start-first
pizda-bot-nginx:
image: mathwave/sprint-repo:pizda-bot
command: api

View File

@ -1,3 +1,4 @@
import datetime
import os
import sys
from random import randrange, choice
@ -68,6 +69,8 @@ def do_action(message: Message):
bot.reply_to(message, choice(get_replies()))
return
info = get_chat_info(message.chat.id)
if client.get_config('updater')['enabled']:
set_values(message.chat.id, last_time_updated=datetime.datetime.now())
if message.text == '#debug' and client.is_staff(telegram_id=message.from_user.id):
bot.send_message(message.chat.id, f'chat id: {message.chat.id}\n'
f'probability: {info["probability"]}')
@ -97,6 +100,9 @@ def do_action(message: Message):
arg = sys.argv[-1]
if arg == 'bot':
bot.polling()
elif arg == 'updater':
from updater import update
update()
else:
from api import app
app.run(host="0.0.0.0", port=1238)

21
updater.py Normal file
View File

@ -0,0 +1,21 @@
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 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)
bot.send_message(chat['chat_id'], f"Как говорится, кто молчит - тот трансвестит, а трансвестит сегодня - @{user['username']}")
sleep(client.get_config('updater')['seconds_delay'])