Ejemplo n.º 1
0
def process_interrupts(customer, text):
    """
    Processes user input for global, or user-specific process_interrupts
    that would preclude sending a message to the user.
    NONE should be treated as no relevant interrupts, so messaging can proceed
    empty string should be treated as a no-response to the user
    """
    if customer and customer.get('stop', None):
        return ""

    if settings.Config.DO_NOT_DISTURB and customer and not customer.get('override', None):
        phone_number = customer['phone_number'].get('S', '')

        if "corgi" in text.lower() and not customer.get('wants_uptime_notification', None):
            message = render_template('txt/do_not_disturb_acknowledged.txt')
            emoji_customer.add_metadata(phone_number, 'wants_uptime_notification', 'true')
            return create_response(message)

        if customer.get('showed_disable_prompt', None):
            return ""

        emoji_customer.add_metadata(phone_number, 'showed_disable_prompt', 'true')
        message = render_template('txt/do_not_disturb.txt')
        return create_response(message)

    return None
Ejemplo n.º 2
0
def generate_freeloader_response(customer):
    phone_number = customer['phone_number'].get('S', '')
    if customer.get('showed_payment_prompt', None):
        return ""
    emoji_customer.add_metadata(phone_number, 'showed_payment_prompt', 'true')
    message = render_template('txt/pay_us_please.txt',
                              site_url=settings.Config.SITE_URL,
                              payment_url='/stripe',
                              phone_number=phone_number)
    return create_response(message)
Ejemplo n.º 3
0
    def create_reply(self):
        message = ""
        text = self.text
        text = text.strip()
        if text_contains_emoji(text):
            emoji = text
        else:
            emoji = emojis_for_emoticons.get(text, None)
            if not emoji:
                raise RuntimeError("Improperly identified message type")
        # If it's a multi-emoji that we don't track, just grab the first emoji.
        # TODO: abstract out use of `keys()`.
        if len(emoji) > 1 and emoji not in google_spreadsheets.keys():
            emoji = text[0]

            # Check for skin-toned emojis.
            # (This only handles the one-emoji case for now.)
            if not emoji_contains_skin_tone(text) and not emoji_is_numeric(text):
                message = render_template('txt/requested_emoji_does_not_exist.txt',
                                          requested_emoji=text,
                                          fallback_emoji=emoji)

        # Time to grab the filepath for the emoji!
        corgi_urls = api.get(emoji)['results']

        # If that still doesn't work, we'll just grab a random one.
        if not corgi_urls:
            logger.warn("Couldn't find corgi for {}. Using random one.".format(
                        emoji))

            while not corgi_urls:
                results = api.get()
                emoji, corgi_urls = results['emoji'], results['results']
            message = render_template('txt/requested_emoji_does_not_exist.txt',
                                      requested_emoji=text,
                                      fallback_emoji=emoji)

        corgi_url = random.choice(corgi_urls)
        if message == "":
            supplements = get_supplement_messsage(self.phone_number, self.text)
            if supplements:
                message = supplements
        return create_response(message, image_url=corgi_url)
Ejemplo n.º 4
0
 def create_reply(self):
     matched_secret = Secrets.get_secret(self.text)
     if not matched_secret:
         raise RuntimeError("Improperly identified message type")
     return create_response(matched_secret.text, matched_secret.media)