diff --git a/.deploy/deploy-dev.yaml b/.deploy/deploy-dev.yaml index a054377..3753443 100644 --- a/.deploy/deploy-dev.yaml +++ b/.deploy/deploy-dev.yaml @@ -3,29 +3,12 @@ version: "3.4" services: - poll: - image: mathwave/sprint-repo:ruz-bot - environment: - STAGE: "development" - TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV - networks: - - queues-development - command: poll - deploy: - mode: replicated - restart_policy: - condition: any - update_config: - parallelism: 1 - order: start-first - worker: image: mathwave/sprint-repo:ruz-bot environment: MONGO_HOST: "mongo.develop.sprinthub.ru" STAGE: "development" MONGO_PASSWORD: $MONGO_PASSWORD_DEV - PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN networks: - queues-development - configurator @@ -38,22 +21,6 @@ services: parallelism: 1 order: start-first - mailbox: - image: mathwave/sprint-repo:ruz-bot - environment: - STAGE: "development" - TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV - networks: - - queues-development - command: mailbox - deploy: - mode: replicated - restart_policy: - condition: any - update_config: - parallelism: 1 - order: start-first - fetch: image: mathwave/sprint-repo:ruz-bot environment: diff --git a/.gitea/workflows/deploy-dev.yaml b/.gitea/workflows/deploy-dev.yaml index 98d72ea..271fc04 100644 --- a/.gitea/workflows/deploy-dev.yaml +++ b/.gitea/workflows/deploy-dev.yaml @@ -41,5 +41,4 @@ jobs: env: TELEGRAM_TOKEN_DEV: ${{ secrets.TELEGRAM_TOKEN_DEV }} MONGO_PASSWORD_DEV: ${{ secrets.MONGO_PASSWORD_DEV }} - PLATFORM_SECURITY_TOKEN: ${{ secrets.PLATFORM_SECURITY_TOKEN }} run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-dev.yaml ruz-bot-development diff --git a/daemons/mailbox.py b/daemons/mailbox.py deleted file mode 100644 index c8a5e3c..0000000 --- a/daemons/mailbox.py +++ /dev/null @@ -1,31 +0,0 @@ -import telebot -import os - -from daemons import base -from utils import queues - - -class Daemon(base.Daemon, queues.TasksHandlerMixin): - def __init__(self): - super().__init__() - self.bot = telebot.TeleBot(os.getenv("TELEGRAM_TOKEN")) - - @property - def queue_name(self): - return 'ruz_bot_mailbox' - - def execute(self): - self.poll() - - def process(self, payload): - body = { - 'chat_id': payload['chat_id'], - 'text': payload['text'], - } - reply_markup = payload.get('reply_markup') - if reply_markup: - body['reply_markup'] = reply_markup - try: - self.bot.send_message(**body, parse_mode='Markdown') - except Exception as exc: - print('Error', str(exc)) diff --git a/daemons/notify.py b/daemons/notify.py index 5aefc34..0a992e1 100644 --- a/daemons/notify.py +++ b/daemons/notify.py @@ -25,7 +25,7 @@ def process(): ans += f"🧑‍🏫 {(lesson['lecturer'] or 'Неизвестно')}\n" if lesson.get('link', None): ans += f"🔗 {lesson['link']}" - queues.set_task('ruz_bot_mailbox', {'text': f"Через {user['notify_minutes']} минут у тебя занятие!\n" + ans, 'chat_id': user["chat_id"]}, 1) + queues.set_task('botalka_mailbox', {'project': 'ruz-bot', 'name': 'telegram-bot', 'body': {'text': f"Через {user['notify_minutes']} минут у тебя занятие!\n" + ans, 'chat_id': user["chat_id"]}}, 1) mongo.lessons_collection.update_one({"_id": lesson['_id']}, {"$set": {"notified": True}}) time_now = datetime.datetime.now() for user in mongo.users_collection.find({"next_daily_notify_time": {"$lte": time_now}}): @@ -40,7 +40,7 @@ def process(): else: text = ruz.schedule_builder(lessons) try: - queues.set_task('ruz_bot_mailbox', {'text': f"Уведомляю о занятиях! Твое расписание на {'сегодня' if user.get('daily_notify_today', True) else 'завтра'}:\n" + text, 'chat_id': user["chat_id"]}, 1) + queues.set_task('botalka_mailbox', {'project': 'ruz-bot', 'name': 'telegram-bot', 'body': {'text': f"Уведомляю о занятиях! Твое расписание на {'сегодня' if user.get('daily_notify_today', True) else 'завтра'}:\n" + text, 'chat_id': user["chat_id"]}}, 1) except: pass mongo.users_collection.update_one( @@ -72,7 +72,7 @@ def process(): else: mess += "12 часов" mess += "!\n\nТвоя первая пара:\n\n" + ans - queues.set_task('ruz_bot_mailbox', {'text': mess, 'chat_id': user["chat_id"]}, 1) + queues.set_task('botalka_mailbox', {'project': 'ruz-bot', 'name': 'telegram-bot', 'body': {'text': mess, 'chat_id': user["chat_id"]}}, 1) start_of_day = datetime.datetime(year=time_now.year, month=time_now.month, day=time_now.day) mongo.lessons_collection.update_many({"begin": {"$gte": start_of_day, "$lt": (start_of_day + datetime.timedelta(days=1))}, "user_email": user["email"]}, {"$set": {"notified_today": True}}) break diff --git a/daemons/poll.py b/daemons/poll.py deleted file mode 100644 index 9980628..0000000 --- a/daemons/poll.py +++ /dev/null @@ -1,15 +0,0 @@ -import os -import telebot - -from daemons import base -from telebot import types -from utils import queues - - -class Daemon(base.Daemon): - def execute(self): - bot = telebot.TeleBot(os.getenv("TELEGRAM_TOKEN")) - @bot.message_handler() - def do_action(message: types.Message): - queues.set_task('ruz_bot_worker', message.json, 1) - bot.polling() diff --git a/helpers/answer.py b/helpers/answer.py index f93814a..a7f5743 100644 --- a/helpers/answer.py +++ b/helpers/answer.py @@ -77,7 +77,7 @@ class Answer: body = {'text': text, 'chat_id': self.user['chat_id']} if reply_markup: body['reply_markup'] = reply_markup.to_json() - queues.set_task('ruz_bot_mailbox', body, 1) + queues.set_task('botalka_mailbox', {'project': 'ruz-bot', 'name': 'telegram-bot', 'body': body}, 1) def set_state(self, state: str): self.user['state'] = state