def send_dinoimages(sender_psid, meal): if meal.images: # image = random.choice([image for image in meal.images]) image = random.choice(list(meal.images)) Response(sender_psid, image=image.url).send() Response(sender_psid, f"Photo by: {image.sender.full_name}").send() else: Response(sender_psid, "No snazzy pics :(").send()
def handle_addcrush(sender_psid, received_message, me): # Check if we have more than 5 crushes already if len(me.crushes) >= 5: Response(sender_psid, "You can't have more than 5 crushes!").send() # End the conversation me.conversation = None me.save() return "OK" msg_text = received_message['text'] _, confidence, myCrush = models.Sender.fuzzySearch( msg_text) # pylint: disable=unused-variable me.add_crush(myCrush) r = Response(sender_psid, f"Added {myCrush.full_name} to crush list") r.add_reply(Reply("Add another Crush", payload="ADDCRUSH")) r.send() if int(sender_psid) in [crush.crushee.psid for crush in myCrush.crushes]: # You are the crush of your crush. It's a match! msg = (f"Congrats! {myCrush.full_name} is crushing on you!" + " Matchmaker Baxtabot is here to match! You now have a date at" + f" {random.choice(DATE_LOCATIONS)} at {random.choice(range(1, 6))}pm tomorrow." + " Clear you calendar - this is your chance πππ") Response(sender_psid, msg).send() Response(myCrush.psid, msg).send() return 'OK'
def handle_dinowrong(sender_psid, received_message, me): print('The dino menu is wrong, should be', received_message) meal = functions.getCurrentDino() meal.description = received_message['text'] meal.save() response = Response(sender_psid) response.text = handle_dino_message(sender_psid, response, 'dino') response.send() return 'Fixed!'
def handle_removecrush(sender_psid, received_message, me): msg_text = received_message['text'] _, confidence, myCrush = models.Sender.fuzzySearch( msg_text) # pylint: disable=unused-variable for aCrush in me.crushes: if aCrush.crushee.psid == myCrush.psid: Response( sender_psid, f"Removed {aCrush.crushee.full_name} from crush list" ).send() aCrush.delete_instance() Response(sender_psid, "Done!").send()
def handle_dinoimage(sender_psid, received_message): if "attachments" in received_message and received_message["attachments"][0]: dino = functions.getCurrentDino() sender = ( models.Sender.select().where(models.Sender.psid == sender_psid).get() ) img = models.MealImg.create( meal=dino.id, url=received_message["attachments"][0]["payload"]["url"], sender=sender.id, ) Response(sender_psid, image=img.url).send() Response(sender_psid, "What a stunning shot!").send() else: Response(sender_psid, "You need to send me an image!").send()
def groupMessage(psids, text): ''' Sends a message to a group of people ''' print("GROUP MESSAGE", "'" + text + "'") for psid in psids: print(" psid:", psid) try: Response(psid, text=text).send(timeout=0.01) except requests.exceptions.ReadTimeout: pass
def handlePostback(sender_psid, received_postback, msg): """ Handles a postback request to the webhook and determines what functionality / response to call """ payload = received_postback["payload"] print("RECEIVED POSTBACK: ", received_postback) response = Response(sender_psid) if payload == "goodvote": response.text = "Sounds like a nice meal!" functions.makeDinoVote("goodvote") elif payload == "badvote": response.text = "Too bad it was gross :(" functions.makeDinoVote("badvote") elif payload == "ADDCRUSH": start_conversation(sender_psid, "ADDCRUSH") response.text = "Enter your crush name:" elif payload == "REMOVECRUSH": start_conversation(sender_psid, "REMOVECRUSH") response.text = "Enter the crush name to remove:" elif payload == "DINOIMAGE": start_conversation(sender_psid, "DINOIMAGE") response.text = "Send me a photo of dino!" elif payload == 'DINOWRONG': start_conversation(sender_psid, 'DINOWRONG') response.text = 'What is the dino meal actually?' else: # response.text = "[DEBUG] Received postback for some reason..." handleMessage(sender_psid, msg) return "OK" response.send() return "OK"
def handle_message(sender_psid, webhook_event): if ("quick_reply" in webhook_event["message"] and "payload" in webhook_event["message"]["quick_reply"]): print("Got payload!") return message.handlePostback( sender_psid, webhook_event["message"]["quick_reply"], webhook_event["message"]["text"], ) if "text" in webhook_event["message"]: return message.handleMessage(sender_psid, webhook_event["message"]["text"]) return Response( sender_psid, text= f"I can't deal with whatever shit you just sent me. Go complain to {OFFICERS} about it", ).send()
def handle_calendar_message(sender_psid): ''' Sends the calendar Return value: - "Here is this week's calendar!" || "Here is this week's calendar!" Side effects: - Sends an image with the calendar ''' eventAsset = functions.getWeekEvents() if eventAsset: Response(sender_psid, image=eventAsset).send() return "Here is this week's calendar!" text = "I couldn't send the weekly calendar! Please update me!!" groupMessage(OFFICER_PSIDS, text) return "Here is this week's calendar!"
def handle_post(request): print("SOMEONE SENT MESSAGE!") body = request.json print(body) if body["object"] == "page": # check it is from a page subscription # there may be multiple entries if it is batched for entry in body["entry"]: # get the message webhook_event = entry["messaging"][0] # get the sender PSID sender_psid = None sender_psid = webhook_event["sender"]["id"] sender = message.check_user_exists(sender_psid) if not sender: # error happened and we could not resolve the identity of the sender return "" if sender.conversation and "message" in webhook_event: return message.handleConversation(sender_psid, webhook_event["message"], sender.conversation) if "postback" in webhook_event: return handle_postback(sender_psid, webhook_event) if "message" in webhook_event: return handle_message(sender_psid, webhook_event) return Response( sender_psid, text= f"I can't deal with whatever shit you just sent me. Go complain to {OFFICERS} about it", ).send() else: # send error print("Something went shit") return "Not Okay"
def handleMessage(sender_psid, received_message): """ Handles a plain message request and determines what to do with it By word matching the content and sender_psid """ received_message = received_message.lower() response = Response(sender_psid) print(sender_psid) if "psid" in received_message: Response(sender_psid, text=str(sender_psid)).send() elif ( "dinopoll" in received_message or "dino like" in received_message or "dino good" in received_message ): response.text = handle_dinopoll_message(response) elif ( "what's on" in received_message or "whatβs on" in received_message or "what is on" in received_message or "event" in received_message or "calendar" in received_message ): response.text = handle_calendar_message(sender_psid) elif 'dino is wrong' in received_message: response.text = handle_dinowrong_message(sender_psid, response) elif "nudes" in received_message or "noods" in received_message: # response.asset = "270145943837548" url = 'https://indomie.com.au/wp-content/uploads/2020/03/migorengjumbo-new.png' Response(sender_psid, image=url).send() elif ( "dino is shit" in received_message or "dino is bad" in received_message or "dino is good" in received_message or "dinovote" in received_message or "vote" in received_message ): response.text = handle_dinovote_message(response) elif is_dino_message(received_message): response.text = handle_dino_message( sender_psid, response, received_message) # Response(sender_psid, text='Arc Board elections are currently underway. If you want someone to vote for, Nick Patrikeos who helps maintain me is running. Type "arc board" for more info!').send() elif "snazzy pic" in received_message: meal = functions.getCurrentDino() if meal is not None and meal.images: image = random.choice(list(meal.images)) Response(sender_psid, image=image.url).send() Response(sender_psid, f"Photo by: {image.sender.full_name}").send() else: Response(sender_psid, "No snazzy pics :(").send() elif 'am i a ressiexd' in received_message: pass elif 'order me a late meal' in received_message: response.text = handle_latemeal_message(sender_psid, received_message) elif "room is" in received_message: response.text = handle_getroom_message(sender_psid, received_message) elif "crush list" in received_message: response.text = handle_crushlist_message(sender_psid, response) else: reply = bot.reply(str(sender_psid), received_message) response.text = str(reply) if sender_psid == "cmd": return response.payload print("sent back:") pprint(response.payload) response.send() return "OK"