66from chatterbot .trainers import ChatterBotCorpusTrainer
77from PyMatcha import redis
88from PyMatcha .models .like import Like
9+ from PyMatcha .models .message import Message
910from PyMatcha .models .user import User
1011from PyMatcha .models .view import View
1112from PyMatcha .utils .recommendations import create_user_recommendations
1213from 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 ))
0 commit comments