Example #1
0
def nearby_bus_stop(bot, update):
    """message send for Command: nearby"""
    botan.track(BOTAN_TOKEN, update.message.chat.id, update.message, '/nearby')
    location_keyboard = KeyboardButton(text="send_location", request_location=True)
    reply_markup = ReplyKeyboardMarkup([[location_keyboard]], resize_keyboard=True,
    one_time_keyboard=True)
    bot.send_message(chat_id=update.message.chat.id, text="Please tell me where you are.",
    reply_markup=reply_markup)
Example #2
0
def emoji_meaning(bot, update):
    """message send for Command: emoji"""
    botan.track(BOTAN_TOKEN, update.message.chat.id, update.message, '/emoji')
    msg = 'Let me tell you what each emoji means ah. \n\n'
    msg += EMOJICODE.smile() + ' - This one means got seats in bus ah. \n'
    msg += EMOJICODE.sweating() + ' - This one means no seats liao. So need to stand ah. \n'
    msg += EMOJICODE.angry() + ' - This one is the worst ah. No seats and no place to stand. '
    msg += 'Wait for next bus ba. \n'
    msg += EMOJICODE.wheelchair() + ' - This one means the bus is wheelchair accessible one.'
    bot.send_message(chat_id=update.message.chat.id, text=msg)
Example #3
0
def inline_button(bot, update):
    """Inline button message handling"""
    callback = update.callback_query
    data_arr = callback.data.split()
    bus = Bus()   
    if data_arr[0] == 'refresh':
        if len(data_arr) == 2:
            botan.track(BOTAN_TOKEN, callback.message.chat.id, callback, 'inline-btn-refresh-all')
            msg = bus.get_bus_arrival_msg(data_arr[1])
            reply_markup = bus_arrival_markup(data_arr[1])
        else:
            botan.track(BOTAN_TOKEN, callback.message.chat.id, callback, 'inline-btn-refresh-single')
            msg = bus.get_bus_arrival_msg(data_arr[1], data_arr[2])
            reply_markup = bus_arrival_markup(data_arr[1] + ' ' + data_arr[2])
        bot.editMessageText(chat_id=callback.message.chat.id,
        message_id=callback.message.message_id, text=msg,
        parse_mode='Markdown', reply_markup=reply_markup)
        bot.answerCallbackQuery(callback_query_id=callback.id,
        text='Bus timing updated')
    elif data_arr[0] == 'inline-mode-refresh':
        msg = bus.get_bus_arrival_msg(data_arr[1])
        reply_markup = bus_arrival_inline_markup(data_arr[1])
        bot.editMessageText(inline_message_id =callback.inline_message_id, text=msg,
        parse_mode='Markdown', reply_markup=reply_markup)
        bot.answerCallbackQuery(callback_query_id=callback.id,
        text='Bus timing updated')
    elif data_arr[0] == 'streetview':
        streetview = StreetView()
        bus_stop_detail = bus.get_bus_stop_detail(data_arr[1])
        if bus_stop_detail is not None:
            botan.track(BOTAN_TOKEN, callback.message.chat.id, callback, 'inline-btn-streetview')
            latlng = streetview.get_lat_lng_str(bus_stop_detail)
            streetview_img_url = streetview.form_street_view_img_url(latlng)
            bot.send_photo(chat_id=callback.message.chat.id,
            photo=streetview_img_url, caption=bus_stop_detail['name'])
            bot.answerCallbackQuery(callback_query_id=callback.id,
            text='Bus stop photo shown')
        else:
            botan.track(BOTAN_TOKEN, callback.message.chat.id, callback, 'inline-btn-streetview-not-found')
            bot.send_message(chat_id=callback.message.chat.id,
            message_id=callback.message.message_id, text='Bus stop not found leh.') 
            bot.answerCallbackQuery(callback_query_id=callback.id,
            text='No bus stop photo found')
    elif data_arr[0] == 'nearby':
        botan.track(BOTAN_TOKEN, callback.message.chat.id, callback, 'inline-btn-nearby')
        msg = bus.get_bus_arrival_msg(data_arr[1])
        reply_markup = bus_arrival_markup(data_arr[1])
        bot.send_message(chat_id=callback.message.chat.id, message_id=callback.message.message_id, 
        text=msg, parse_mode='Markdown', reply_markup=reply_markup)
        bot.answerCallbackQuery(callback_query_id=callback.id,
        text='Bus timing shown')    
Example #4
0
def bus_info(bot, update):
    """message send for Command: businfo"""
    split_arr = update.message.text.split()
    bus_info = BusInfo()
    if len(split_arr) == 2:
        botan.track(BOTAN_TOKEN, update.message.chat.id, update.message, '/businfo bus')
        msg = bus_info.get_bus_info_msg(split_arr[1])
        bot.send_message(chat_id=update.message.chat.id, text=msg, parse_mode='Markdown')
    else:
        botan.track(BOTAN_TOKEN, update.message.chat.id, update.message, '/businfo')
        msg = 'Tell me the bus no in this format ah. \n\n'
        msg += '*Format* : \n- /businfo <bus no>\n\n'
        msg += '*Example* : \n- /businfo 50 \n- /businfo 163'
        bot.send_message(chat_id=update.message.chat.id, text=msg, parse_mode='Markdown')
Example #5
0
def get_help(bot, update):
    """message send for Command: help"""
    botan.track(BOTAN_TOKEN, update.message.chat.id, update.message, '/help')
    msg = 'Let me show you the *command list* ah \n\n'
    msg += '/busstop - Show bus arrival info' + EMOJICODE.busstop() + EMOJICODE.info() + '\n'
    msg += '/nearby - Show nearby bus stops '+ EMOJICODE.busstop() + '\n'
    msg += '/businfo - Show bus info' + EMOJICODE.bus() + EMOJICODE.info() + '\n'
    msg += '/emoji - Show emoji meaning ' +  EMOJICODE.smile() +'\n'
    msg += '/mrtmap - Show MRT map ' +  EMOJICODE.station() +'\n'
    msg += '/grabpromo - Show grab promotions \n'
    msg += '/uberpromo - Show uber promotions \n'
    msg += '/close - Close reply keyboard' + EMOJICODE.keyboard() +'\n'
    msg += '/help - Show help list' +  EMOJICODE.sos() +'\n'
    msg += '/start - To start from beginning\n'
    bot.send_message(chat_id=update.message.chat.id, text=msg, parse_mode='Markdown')
Example #6
0
def location(bot, update):
    """message send for location callback"""
    botan.track(BOTAN_TOKEN, update.message.chat.id, update.message, 'location-callback')
    lat = update.message.location.latitude
    lng = update.message.location.longitude
    nearby = Nearby()
    nearest_3_list = nearby.get_nearest_three_bus_stops(lat,lng)
    msg = nearby.get_nearby_cmd_msg(nearest_3_list)
    button_list = [
        [InlineKeyboardButton(EMOJICODE.busstop() + ' ' + nearest_3_list[0]['no'],
        callback_data='nearby ' + nearest_3_list[0]['no'])],
        [InlineKeyboardButton(EMOJICODE.busstop() + ' ' + nearest_3_list[1]['no'],
        callback_data='nearby ' + nearest_3_list[1]['no'])],
        [InlineKeyboardButton(EMOJICODE.busstop() + ' ' + nearest_3_list[2]['no'],
        callback_data='nearby ' + nearest_3_list[2]['no'])]
    ]
    reply_markup = InlineKeyboardMarkup(button_list)
    bot.send_message(chat_id=update.message.chat.id, text=msg, parse_mode='Markdown',
    reply_markup=reply_markup)
Example #7
0
def bus_stop(bot, update):
    """message send for Command: busstop"""
    split_arr = update.message.text.split()
    bus = Bus()
    if len(split_arr) == 2:
        botan.track(BOTAN_TOKEN, update.message.chat.id, update.message, '/busstop all')
        msg = bus.get_bus_arrival_msg(split_arr[1])
        reply_markup = bus_arrival_markup(split_arr[1])
        bot.send_message(chat_id=update.message.chat.id, text=msg, parse_mode='Markdown',
        reply_markup=reply_markup)
    elif len(split_arr) == 3:
        botan.track(BOTAN_TOKEN, update.message.chat.id, update.message, '/busstop single')
        msg = bus.get_bus_arrival_msg(split_arr[1], split_arr[2])
        reply_markup = bus_arrival_markup(split_arr[1] + ' ' + split_arr[2])
        bot.send_message(chat_id=update.message.chat.id, text=msg, parse_mode='Markdown',
        reply_markup=reply_markup)
    else:
        botan.track(BOTAN_TOKEN, update.message.chat.id, update.message, '/busstop')
        msg = 'Tell me the bus stop no in this format ah. \n\n'
        msg += '*Format* : \n- /busstop <bus stop no> <bus no> (optional) \n\n'
        msg += '*Example* : \n- /busstop 67329 \n- /busstop 67329 163 \n\n'
        msg += 'You can also send me a inline query by typing @sgtravelkakibot followed '
        msg += 'by the bus stop name or code.'
        reply_markup = InlineKeyboardMarkup([
            [InlineKeyboardButton("Try inline query", switch_inline_query_current_chat='67321')]
        ])
        bot.send_message(chat_id=update.message.chat.id, text=msg, parse_mode='Markdown',
        reply_markup=reply_markup)
Example #8
0
def getlocation(bot, update):
    usr = update.message.from_user
    location = update.message.location
    if usr.id in CMD:
        geolocator = Nominatim()
        latiLong = str(location.latitude) + "," + str(location.longitude)
        try:
            loc = geolocator.reverse(latiLong).address
        except Exception:
            loc = ""
        reply_msg = "The {} location set to:\n"
        uber_msg = 'All set! Just click <a href="{}">HERE</a> to open the Uber app.'
        if CMD[usr.id] == CMDS[0]:  # /setpickup
            link = UBER_URL + "p={}".format(
                str(location.latitude) + "," + str(location.longitude))
            update.message.reply_text(uber_msg.format(link),
                                      parse_mode=ParseMode.HTML,
                                      reply_markup=ReplyKeyboardHide())
            if loc:
                update.message.reply_text(reply_msg.format('pickup') + loc)
            try:
                botan.track(BOTAN_TOKEN, update.message.from_user.id,
                            {0: 'set pickup'}, 'set pickup')
            except Exception as e:
                logger.exception(e)
        elif CMD[usr.id] == CMDS[1]:  # /setdropoff
            link = UBER_URL + "d={}".format(
                str(location.latitude) + "," + str(location.longitude))
            update.message.reply_text(uber_msg.format(link),
                                      parse_mode=ParseMode.HTML,
                                      reply_markup=ReplyKeyboardHide())
            if loc:
                update.message.reply_text(reply_msg.format('dropoff') + loc)
            try:
                botan.track(BOTAN_TOKEN, update.message.from_user.id,
                            {0: 'set dropoff'}, 'set dropoff')
            except Exception as e:
                logger.exception(e)
        elif CMD[usr.id] == CMDS[2]:  # /setpickanddrop
            if usr.id in PICK:
                try:
                    loc2 = geolocator.reverse(PICK[usr.id]).address
                except Exception:
                    loc2 = ""
                link = UBER_URL + "p={}&d={}".format(
                    PICK[usr.id],
                    str(location.latitude) + "," + str(location.longitude))
                del PICK[usr.id]
                update.message.reply_text(uber_msg.format(link),
                                          parse_mode=ParseMode.HTML,
                                          reply_markup=ReplyKeyboardHide())
                if loc and loc2:
                    update.message.reply_text(
                        reply_msg.format('pickup') + loc2 +
                        "\n\nAnd dropoff location set to:\n" + loc)
                try:
                    botan.track(BOTAN_TOKEN, update.message.from_user.id,
                                {0: 'set pickup and dropoff'},
                                'set pickup and dropoff')
                except Exception as e:
                    logger.exception(e)
            else:
                PICK[usr.id] = latiLong
                if loc:
                    update.message.reply_text(reply_msg.format('pickup') + loc)
                update.message.reply_text(
                    "Now send me the dropoff location or simply select 'Current Location' from the menu. Or /cancel to cancel."
                )
                return LOCATION
        else:
            update.message.reply_text(
                "Something went wrong, please try again.")
    else:
        update.message.reply_text("Something went wrong, please try again.")

    return MAIN
Example #9
0
def start(bot, update):
    """message send for Command: start"""
    botan.track(BOTAN_TOKEN, update.message.chat.id, update.message, '/start')
    msg = 'Whats up'+ EMOJICODE.sunglasses() +', what do you want me to do for you ah?'
    bot.send_message(chat_id=update.message.chat.id, text=msg)
Example #10
0
def handle_error(bot, update, error):
    """message send for when error occurs"""
    botan.track(BOTAN_TOKEN, update.message.chat.id, update.message, 'error')
    LOGGER.warn('Update "%s" caused error "%s"' % (update, error))
Example #11
0
def echo(bot, update):
    """message send for user input"""
    botan.track(BOTAN_TOKEN, update.message.chat.id, update.message, 'echo')
    bot.send_message(chat_id=update.message.chat.id, 
    text="I'm still not smart enough to understand what you are saying ah.")
Example #12
0
def close_command(bot, update):
    """message send for Command: close"""
    botan.track(BOTAN_TOKEN, update.message.chat.id, update.message, '/close')
    bot.send_message(chat_id=update.message.chat.id, text="Okay close liao.", reply_markup=ReplyKeyboardRemove())
Example #13
0
def mrt_map(bot, update):
    """message send for Command: mrtmap"""
    botan.track(BOTAN_TOKEN, update.message.chat.id, update.message, '/mrtmap')
    msg = '*MRT map*\n\n'
    msg += 'Click [here](https://goo.gl/xqRlx7)'
    bot.send_message(chat_id=update.message.chat.id, text=msg, parse_mode='Markdown')