Пример #1
0
def finger_in_command(bot, update, args, is_reply=False):
    chat_id = update.message.chat_id
    logger.info("Finger on %s" % chat_id)

    if not Pineapple.is_open(chat_id):
        logger.info("Pineapple not open")
        send_message(bot, chat_id, MESSAGE.NOT_YET_OPEN)
        return

    user_name = get_full_name(update.message.from_user)
    pineapple = Pineapple.get(chat_id)

    if len(args) == 2 and "".join(args) == "domeio":  # Easter Egg
        pineapple.middle_finger(user_name)
        message = pineapple.get_short_fingers_list_message()
    else:
        try:
            pineapple.finger_in(user_name)
            Pineapple.update(chat_id, pineapple)
            message = pineapple.get_short_fingers_list_message()
        except Finger.FingersLimitReached:
            message = MESSAGE.NO_MORE_FINGERS_IN_HAND

    if is_reply:
        message_id = update.message.message_id
    else:
        message_id = None
    send_message(bot, chat_id, message, reply_to_message_id=message_id, reply_markup=ReplyKeyboardHide(selective=True))
Пример #2
0
def message_handler(bot, update):
    """Check if is a finger in or out"""
    text = update.message.text
    logger.info("Reply on %s: %s" % (str(update.message.chat_id), text.encode('utf-8')))
    if text_equals_emoji(text, EMOJI.FINGER):
        finger_in_command(bot, update, [], is_reply=True)
    elif text_equals_emoji(text, EMOJI.FINGER_DOWN):
        finger_out_command(bot, update, is_reply=True)
Пример #3
0
def main():
    graph.delete_all()
    logger.info(" + Creating shows")
    create_shows()
    logger.info(" - Finished Creating shows")

    #logger.info("Creating popular shows")
    #create_popular_shows()
    #logger.info(" - Finished Creating popular shows")
    """
Пример #4
0
    def run(self):
        try:
            start_time = datetime.utcnow()
            logger.info("+ Running services")

            provider = NadavProvider()
            provider.run()

            logger.info("- Running services, elapsed time:[{0}]".format(datetime.utcnow() - start_time))
        except Exception, e:
            logger.exception(e)
Пример #5
0
def who_command(bot, update):
    chat_id = update.message.chat_id
    logger.info("Getting fingers on %s" % chat_id)

    if not Pineapple.is_open(chat_id):
        logger.info("Pineapple not open")
        send_message(bot, chat_id, MESSAGE.NOT_YET_OPEN)
        return

    message = Pineapple.get(chat_id).get_fingers_list_message()
    send_message(bot, chat_id, message)
Пример #6
0
def close_pineapple_command(bot, update):
    chat_id = update.message.chat_id
    logger.info("Close pineapple on %s" % chat_id)

    if not Pineapple.is_open(chat_id):
        logger.info("Pineapple already closed")
        send_message(bot, chat_id, MESSAGE.NOT_YET_OPEN)
        return

    message = Pineapple.get(chat_id).get_close_message()
    Pineapple.close(chat_id)
    send_message(bot, chat_id, message, reply_markup=ReplyKeyboardHide())
Пример #7
0
def finger_out_command(bot, update, is_reply=False):
    chat_id = update.message.chat_id
    logger.info("Getting fingers on %s" % chat_id)

    if not Pineapple.is_open(chat_id):
        logger.info("Pineapple not open")
        send_message(bot, chat_id, MESSAGE.NOT_YET_OPEN)
        return

    user_name = get_full_name(update.message.from_user)
    pineapple = Pineapple.get(chat_id)
    pineapple.finger_out(user_name)
    Pineapple.update(chat_id, pineapple)

    message = pineapple.get_short_fingers_list_message()

    if is_reply:
        message_id = update.message.message_id
    else:
        message_id = None
    send_message(bot, chat_id, message, reply_to_message_id=message_id, reply_markup=ReplyKeyboardHide(selective=True))
Пример #8
0
def open_pineapple_command(bot, update, args):
    chat_id = update.message.chat_id
    logger.info("Opening pineapple on %s" % chat_id)

    if len(args) == 0:
        logger.info("Not enough arguments")
        send_message(bot, chat_id, MESSAGE.USAGE_OPEN)
        return

    if Pineapple.is_open(chat_id):
        logger.info("Pineapple already open")
        send_message(bot, chat_id, MESSAGE.ALREADY_OPEN.format(
            Pineapple.get(chat_id).get_open_message()))
        return

    owner_name = get_full_name(update.message.from_user)
    Pineapple.open(chat_id, ' '.join(args), owner_name)
    message = Pineapple.get(chat_id).get_open_message()
    keyboard = create_pineapple_reply_keyboard()
    send_message(bot, chat_id, message, reply_markup=keyboard)
Пример #9
0

@ws.route('/websocket')
def web_socket_echo(ws):
    try:
        logger.warning("/websocket")
        while True:
            msg = ws.receive()
            if msg is not None:
                ws.send(msg)
            else:
                return
    except Exception, e:
        logger.exception(e)
        response = Response(response=None, status=200)
        return response


@ws.route('/echo')
def echo(ws):
    while True:
        message = ws.receive()
        ws.send(message)


########################################################################################################################
if __name__ == "__main__":
    logger.info("Starting application!")
    app.run(host='0.0.0.0')
    #, gevent=1000
Пример #10
0
    return render_template('websocket_test.html')


@ws.route('/websocket')
def web_socket_echo(ws):
    try:
        logger.warning("/websocket")
        while True:
            msg = ws.receive()
            if msg is not None:
                ws.send(msg)
            else:
                return
    except Exception, e:
        logger.exception(e)
        response = Response(response=None, status=200)
        return response

@ws.route('/echo')
def echo(ws):
    while True:
        message = ws.receive()
        ws.send(message)


########################################################################################################################
if __name__ == "__main__":
    logger.info("Starting application!")
    app.run(host='0.0.0.0')
    #, gevent=1000