11import datetime
22import json
3- import random
4- import time
53from math import ceil
64
75from PyMatcha import celery
86from PyMatcha import redis
97from PyMatcha .models .message import Message
108from PyMatcha .models .user import User
119from PyMatcha .utils .bot_actions import _prepare_chatbot
10+ from PyMatcha .utils .bot_actions import decide_bot_action
1211from PyMatcha .utils .recommendations import create_user_recommendations
1312
14- # from PyMatcha.utils.bot_actions import decide_bot_action
15-
1613BASE_HEAT_SCORE = 30
1714LIKES_MULTIPLIER = 2
1815SUPERLIKES_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