Skip to content

Commit 37e950c

Browse files
committed
Added a botaction to open a new conversation
1 parent f56ee63 commit 37e950c

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

backend/PyMatcha/utils/bot_actions.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
from chatterbot.trainers import ChatterBotCorpusTrainer
77
from PyMatcha import redis
88
from PyMatcha.models.like import Like
9+
from PyMatcha.models.message import Message
910
from PyMatcha.models.user import User
1011
from PyMatcha.models.view import View
1112
from PyMatcha.utils.recommendations import create_user_recommendations
1213
from PyMatcha.utils.static import BACKEND_ROOT
14+
from PyMatcha.utils.static import BOT_CONV_OPENERS
1315

14-
# TODO: message new conversation, respond to unread message, send a new message in already started conversation
16+
# TODO: respond to unread message, send a new message in already started conversation
1517

1618

17-
def bot_response(bot_name, user_input):
19+
def _bot_response(bot_name, user_input):
1820
logging.debug(f"Starting chatbot with name {bot_name}")
1921
chatbot = ChatBot(
2022
bot_name,
@@ -43,7 +45,7 @@ def _get_recommendations(bot_user: User):
4345
return json.loads(recommendations)
4446

4547

46-
def bot_like(bot_user: User, is_superlike: bool):
48+
def botaction_like(bot_user: User, is_superlike: bool):
4749
recommendations = _get_recommendations(bot_user)
4850
liked_ids = [like.liked_id for like in bot_user.get_likes_sent()]
4951
for user in recommendations:
@@ -53,13 +55,31 @@ def bot_like(bot_user: User, is_superlike: bool):
5355
Like.create(liker_id=bot_user.id, liked_id=user_to_like["id"], is_superlike=is_superlike)
5456

5557

56-
def bot_unlike(bot_user: User):
58+
def botaction_unlike(bot_user: User):
5759
liked_ids = [like.liked_id for like in bot_user.get_likes_sent()]
5860
id_to_unlike = choice(liked_ids)
5961
Like.get_multi(liker_id=bot_user.id, liked_id=id_to_unlike).delete()
6062

6163

62-
def bot_view(bot_user: User):
64+
def botaction_view(bot_user: User):
6365
recommendations = _get_recommendations(bot_user)
6466
user_to_view = choice(recommendations)
6567
View.create(profile_id=user_to_view["id"], viewer_id=bot_user.id)
68+
69+
70+
def botaction_message_new_conversation(bot_user: User):
71+
matches = bot_user.get_matches()
72+
unopened_matches = []
73+
for match in matches:
74+
msg_1 = Message.get_multi(from_id=match.user_1, to_id=match.user_2)
75+
msg_2 = Message.get_multi(from_id=match.user_2, to_id=match.user_1)
76+
if not msg_1 and not msg_2:
77+
unopened_matches.append(match)
78+
match_to_open_conv = choice(unopened_matches)
79+
80+
if match_to_open_conv.user_1 == bot_user.id:
81+
other_user = match_to_open_conv.user_2
82+
else:
83+
other_user = match_to_open_conv.user_1
84+
85+
Message.create(from_id=bot_user.id, to_id=other_user, content=choice(BOT_CONV_OPENERS))

backend/PyMatcha/utils/static.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@
3333

3434
IMGUR_CLIENT_ID = os.getenv("IMGUR_CLIENT_ID")
3535
IMGUR_CLIENT_SECRET = os.getenv("IMGUR_CLIENT_SECRET")
36+
37+
BOT_CONV_OPENERS = [
38+
"Hey baby, are you a microwave? Cause mmmmmmmmmmmmmmmmm",
39+
"How much does a polar bear weigh?",
40+
"Hi sexy",
41+
"Hello cutie",
42+
"Heyoooo",
43+
]

0 commit comments

Comments
 (0)