11import datetime
22import json
3+ import random
4+ import time
35from math import ceil
46
57from PyMatcha import celery
68from PyMatcha import redis
79from PyMatcha .models .message import Message
810from PyMatcha .models .user import User
9- from PyMatcha .utils .bot_actions import decide_bot_action
11+ from PyMatcha .utils .bot_actions import _prepare_chatbot
1012from PyMatcha .utils .recommendations import create_user_recommendations
1113
14+ # from PyMatcha.utils.bot_actions import decide_bot_action
1215
1316BASE_HEAT_SCORE = 30
1417LIKES_MULTIPLIER = 2
@@ -30,7 +33,7 @@ def setup_periodic_tasks(sender, **kwargs):
3033 sender .add_periodic_task (
3134 600 , calc_search_min_max .s (), name = "Update Minimum and Maximum scores and ages for search every 10 minutes"
3235 )
33- sender .add_periodic_task (10 , random_bot_action .s (), name = "Bots will do random actions" )
36+ # sender.add_periodic_task(10, random_bot_action.s(), name="Bots will do random actions")
3437
3538
3639@celery .task
@@ -146,8 +149,21 @@ def take_random_users_online():
146149 return "Successfully set 250 users online"
147150
148151
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"
157+
158+
149159@celery .task
150- def random_bot_action ():
151- for user in User .select_random_multis (10 , is_bot = True , is_online = True ):
152- decide_bot_action (user )
153- return "Done 10 random actions"
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 )
163+ bot_user = User .get (id = bot_id )
164+ from_user = User .get (id = from_id )
165+ message = Message .get (id = message_id )
166+ chatbot = _prepare_chatbot (bot_user .username )
167+ reply = chatbot .get_response (message .content )
168+ bot_user .send_message (from_user .id , reply )
169+ return f"Bot { bot_id } successfully replied to { from_id } "
0 commit comments