Compare commits

...

18 Commits

Author SHA1 Message Date
e970eecb24 Merge pull request 'fix' (#10) from master into dev
Reviewed-on: #10
2024-11-30 15:10:53 +03:00
3a19bdfdd5 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 4s
Deploy Dev / Push (pull_request) Successful in 9s
Deploy Dev / Deploy dev (pull_request) Successful in 8s
Deploy Prod / Build (pull_request) Successful in 4s
Deploy Prod / Push (pull_request) Successful in 9s
Deploy Prod / Deploy prod (pull_request) Successful in 6s
2024-11-30 15:10:40 +03:00
4b261543ed Merge pull request 'fix' (#9) from master into dev
Reviewed-on: #9
2024-11-30 15:08:25 +03:00
243b9e8c9c fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 8s
Deploy Dev / Deploy dev (pull_request) Successful in 7s
2024-11-30 15:08:09 +03:00
9990e18982 Merge pull request 'fix' (#8) from master into dev
Reviewed-on: #8
2024-11-30 15:06:38 +03:00
120b23a885 fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 4s
Deploy Dev / Push (pull_request) Successful in 7s
Deploy Dev / Deploy dev (pull_request) Successful in 8s
2024-11-30 15:05:43 +03:00
1cc4e9ee2d Merge pull request 'master' (#7) from master into dev
Reviewed-on: #7
2024-11-30 14:45:08 +03:00
c51d151bdc fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 8s
Deploy Dev / Deploy dev (pull_request) Successful in 7s
2024-11-30 14:44:48 +03:00
a042a033a6 fix 2024-11-30 14:23:01 +03:00
2d7a04bc7f Merge pull request 'fix' (#6) from master into dev
Reviewed-on: #6
2024-11-30 13:15:58 +03:00
c759cacf9c fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 6s
Deploy Dev / Push (pull_request) Successful in 7s
Deploy Dev / Deploy dev (pull_request) Successful in 8s
2024-11-30 13:15:36 +03:00
e131826519 Merge branch 'dev' of https://gitea.sprinthub.ru/self/roulette-bot into dev 2024-11-30 13:14:24 +03:00
8161954db9 fix 2024-11-30 13:14:05 +03:00
f49413b7d7 fix 2024-11-30 13:08:18 +03:00
3241b25d25 Merge pull request 'fix' (#5) from master into dev
Reviewed-on: #5
2024-11-30 12:48:54 +03:00
ef3cee477c fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 7s
Deploy Dev / Deploy dev (pull_request) Successful in 7s
2024-11-30 12:48:36 +03:00
696f1cb2ed Merge pull request 'fix' (#4) from master into dev
Reviewed-on: #4
2024-11-30 12:46:42 +03:00
ebeef5c15f fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 8s
Deploy Dev / Deploy dev (pull_request) Successful in 8s
2024-11-30 12:46:22 +03:00
3 changed files with 43 additions and 10 deletions

View File

@@ -8,6 +8,9 @@ services:
environment: environment:
MONGO_HOST: "mongo.develop.sprinthub.ru" MONGO_HOST: "mongo.develop.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV MONGO_PASSWORD: $MONGO_PASSWORD_DEV
STAGE: "development"
networks:
- queues-development
deploy: deploy:
mode: replicated mode: replicated
restart_policy: restart_policy:
@@ -15,3 +18,7 @@ services:
update_config: update_config:
parallelism: 1 parallelism: 1
order: start-first order: start-first
networks:
queues-development:
external: true

View File

@@ -8,6 +8,9 @@ services:
environment: environment:
MONGO_HOST: "mongo.sprinthub.ru" MONGO_HOST: "mongo.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD MONGO_PASSWORD: $MONGO_PASSWORD_PROD
STAGE: "production"
networks:
- queues
deploy: deploy:
mode: replicated mode: replicated
restart_policy: restart_policy:
@@ -15,3 +18,7 @@ services:
update_config: update_config:
parallelism: 1 parallelism: 1
order: start-first order: start-first
networks:
queues:
external: true

39
bot.py
View File

@@ -6,6 +6,10 @@ from tools.queues import TasksHandlerMixin, set_task
class Core(TasksHandlerMixin): class Core(TasksHandlerMixin):
@property
def queue_name(self):
return 'roulette_bot_worker'
def process(self, payload): def process(self, payload):
message: Message = Message.de_json(json.dumps(payload)) message: Message = Message.de_json(json.dumps(payload))
self.message = message self.message = message
@@ -59,24 +63,39 @@ class Core(TasksHandlerMixin):
def handle_state_search(self): def handle_state_search(self):
self.send_message('🤖 Поиски собеседника продолжаются') self.send_message('🤖 Поиски собеседника продолжаются')
def send_message(self, text, chat_id=None, reply_markup=None, remove_keyboard=True, method='send_message', **kwargs): def send_message(self, text, chat_id=None, reply_markup=None, remove_keyboard=True):
if not text:
return
if reply_markup is None and remove_keyboard: if reply_markup is None and remove_keyboard:
reply_markup = ReplyKeyboardRemove() reply_markup = ReplyKeyboardRemove()
body = { body = {
'chat_id': chat_id or self.chat_id, 'chat_id': chat_id or self.chat_id,
'text': text,
} }
if text:
body['text'] = text
if reply_markup: if reply_markup:
body['reply_markup'] = reply_markup.to_json() body['reply_markup'] = reply_markup.to_json()
body.update(kwargs) set_task(
'botalka_mailbox',
{
'project': 'roulette-bot',
'name': 'telegram-bot',
'method': 'send_message',
'body': body,
},
1,
)
def send(self, chat_id, method, **kwargs):
set_task( set_task(
'botalka_mailbox', 'botalka_mailbox',
{ {
'project': 'roulette-bot', 'project': 'roulette-bot',
'name': 'telegram-bot', 'name': 'telegram-bot',
'method': method, 'method': method,
'body': body, 'body': {
'chat_id': chat_id,
**kwargs,
},
}, },
1, 1,
) )
@@ -94,15 +113,15 @@ class Core(TasksHandlerMixin):
current_dialog = mongo.get_current_dialog(self.chat_id) current_dialog = mongo.get_current_dialog(self.chat_id)
chat_to_send = current_dialog['chat_id_2'] if current_dialog['chat_id_1'] == self.chat_id else current_dialog['chat_id_1'] chat_to_send = current_dialog['chat_id_2'] if current_dialog['chat_id_1'] == self.chat_id else current_dialog['chat_id_1']
if self.message.photo: if self.message.photo:
self.send_message(None, chat_to_send, method='send_photo', photo=self.message.photo[-1].file_id) self.send(chat_to_send, 'send_photo', photo=self.message.photo[-1].file_id)
if self.message.sticker: if self.message.sticker:
self.send_message(None, chat_to_send, method='send_sticker', data=self.message.sticker.file_id) self.send(chat_to_send, 'send_data', data=self.message.sticker.file_id, data_type='sticker')
if self.message.voice: if self.message.voice:
self.send_message(None, chat_to_send, method='send_voice', voice=self.message.voice.file_id) self.send(chat_to_send, 'send_voice', voice=self.message.voice.file_id)
if self.message.video_note: if self.message.video_note:
self.send_message(None, chat_to_send, method='send_video_note', data=self.message.video_note.file_id) self.send(chat_to_send, 'send_video_note', data=self.message.video_note.file_id)
if self.message.animation: if self.message.animation:
self.send_message(None, chat_to_send, method='send_animation', animation=self.message.animation.file_id) self.send(chat_to_send, 'send_animation', data=self.message.animation.file_id)
self.send_message(self.message_text, chat_to_send) self.send_message(self.message_text, chat_to_send)
def start_new_dialog(self, chat_ids): def start_new_dialog(self, chat_ids):