Skip to content

Commit 5ca1ca8

Browse files
committed
Fixed bot reply action
1 parent 9957c41 commit 5ca1ca8

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed

backend/PyMatcha/routes/api/messages.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ def send_message():
8989
)
9090

9191
if to_user.is_bot:
92-
bot_respond_to_message.delay(bot_id=to_user.id, from_id=current_user.id, message_id=new_message.id)
92+
new_message.is_seen = True
93+
new_message.seen_timestamp = datetime.datetime.utcnow()
94+
new_message.save()
95+
bot_respond_to_message.delay(bot_id=to_user.id, from_id=current_user.id, message_content=content)
9396

9497
return SuccessOutputMessage("new_message", new_message.to_dict(), "Message successfully sent to {}.".format(to_uid))
9598

backend/PyMatcha/utils/bot_actions.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,7 @@ def decide_bot_action(bot_user: User):
153153
return
154154

155155
for match in matches:
156-
# if match.user_1 == bot_user.id:
157-
# other_user_id = match.user_2
158-
# else:
159-
# other_user_id = match.user_1
160-
161156
chatbot = _prepare_chatbot(bot_user.username)
162-
163157
message_actions = [
164158
_botaction_respond_to_unread,
165159
_botaction_message_new_conversation,

backend/PyMatcha/utils/tasks.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import datetime
22
import json
3-
import random
4-
import time
53
from math import ceil
64

75
from PyMatcha import celery
86
from PyMatcha import redis
97
from PyMatcha.models.message import Message
108
from PyMatcha.models.user import User
119
from PyMatcha.utils.bot_actions import _prepare_chatbot
10+
from PyMatcha.utils.bot_actions import decide_bot_action
1211
from PyMatcha.utils.recommendations import create_user_recommendations
1312

14-
# from PyMatcha.utils.bot_actions import decide_bot_action
15-
1613
BASE_HEAT_SCORE = 30
1714
LIKES_MULTIPLIER = 2
1815
SUPERLIKES_MULTIPLIER = 10
@@ -33,7 +30,7 @@ def setup_periodic_tasks(sender, **kwargs):
3330
sender.add_periodic_task(
3431
600, calc_search_min_max.s(), name="Update Minimum and Maximum scores and ages for search every 10 minutes"
3532
)
36-
# sender.add_periodic_task(10, random_bot_action.s(), name="Bots will do random actions")
33+
sender.add_periodic_task(10, random_bot_action.s(), name="Bots will do random actions")
3734

3835

3936
@celery.task
@@ -149,26 +146,20 @@ def take_random_users_online():
149146
return "Successfully set 250 users online"
150147

151148

152-
# @celery.task
153-
# def random_bot_action():
154-
# for user in User.select_random_multis(10, is_bot=True, is_online=True):
155-
# decide_bot_action(user)
156-
# return "Done 10 random actions"
149+
@celery.task
150+
def random_bot_action():
151+
for user in User.select_random_multis(1, is_bot=True, is_online=True):
152+
decide_bot_action(user)
153+
return "A bot has done actions"
157154

158155

159156
@celery.task
160-
def bot_respond_to_message(bot_id: int, from_id: int, message_id: int):
161-
delay = random.randint(1, 10)
162-
time.sleep(delay)
157+
def bot_respond_to_message(bot_id: int, from_id: int, message_content: str):
163158
bot_user = User.get(id=bot_id)
164159
from_user = User.get(id=from_id)
165-
message = Message.get(id=message_id)
166-
167-
message.is_seen = True
168-
message.save()
169160

170161
chatbot = _prepare_chatbot(bot_user.username)
171-
reply = chatbot.get_response(message.content)
162+
reply = chatbot.get_response(message_content)
172163
bot_user.send_message(from_user.id, reply.text)
173164

174165
return f"Bot {bot_id} successfully replied to {from_id}"

0 commit comments

Comments
 (0)