Exemplo n.º 1
0
def parse(msg, platform="GEN", prefix=""):
    msg_list = msg.split(" ")
    if msg_list[0].lower() == prefix + "menu":
        del msg_list[0]
    dining = UCSCDining()
    if dining.verify_name(msg_list[0]):
        college_name = dining.get_college_name(msg_list[0])
        meal_name = msg_list[len(msg_list) - 1]
        text = get_menu(dining, college_name, meal=meal_name)
    else:
        print(platform + "-err: " + msg)
        #text="Sorry, I don't know what college that is!"
        return None
    return text
Exemplo n.º 2
0
def parse(msg):
    msg_list = msg.split(" ")
    if msg_list[0].lower() == "/menu":
        del msg_list[0]
    dining = UCSCDining()
    if dining.verify_name(msg_list[0]):
        college_name = dining.get_college_name(msg_list[0])
        meal_name = msg_list[len(msg_list) - 1]
        text = DiningBot.get_menu(dining, college_name, meal=meal_name)
        bot.send_message(chat_id=update.message.chat_id, text=text)
    else:
        print("FB-err: " + msg)
        bot.send_message(chat_id=update.message.chat_id,
                         text="Sorry, I don't know what college that is!")
Exemplo n.º 3
0
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == client.user:
        return

    if message.content.startswith('!menu') or message.content.startswith(
            '!search'):
        print(str(message.author) + " sent message: " + str(message.content))
        DiningBot.store_from(str(message.author), 'discord_users.txt')

    if message.content.lower().startswith(
            '!start') or message.content.startswith('!help'):
        msg = DiningBot.help(platform="Discord", prefix="!")
        #await client.send_message(message.channel, msg)
        await message.channel.send(msg)
    elif message.content.lower().startswith('!about'):
        msg = DiningBot.about(platform="Discord")
        #await client.send_message(message.channel, msg)
        await message.channel.send(msg)
    elif message.content.lower().startswith('!menu'):
        msg = DiningBot.parse(message.content, platform="DC", prefix="!")
        if not msg:
            #await client.send_message(message.channel, "I'm not sure what college that is!")
            await message.channel.send("I'm not sure what college that is!")
        else:
            #await client.send_message(message.channel, msg)
            await message.channel.send(msg)
    elif message.content.lower().startswith('!search'):
        #msg = DiningBot.parse(message.content, platform="DC", prefix="!")
        msg = message.content
        msg_list = msg.split(" ")
        del msg_list[0]
        dining = UCSCDining()
        meal = ""
        meal_id = dining.get_desired_meal(msg_list[len(msg_list) - 1])
        print(meal_id)
        if not meal_id == -1:
            meal = msg_list[len(msg_list) - 1]
            del msg_list[len(msg_list) - 1]
        msg_str = ""
        for x in msg_list:
            msg_str += x + " "
        msg_str = msg_str[:-1]
        send_msg = DiningBot.search(msg_str, meal=meal)
        if send_msg == "":
            send_msg = "That's not being served!"
        #bot.send_message(chat_id=update.message.chat_id, text=)
        #await client.send_message(message.channel, send_msg)
        await message.channel.send(send_msg)
Exemplo n.º 4
0
def search(keyword, meal=""):
    dining = UCSCDining()
    cowell = get_menu(dining, "cowell", meal)
    crown = get_menu(dining, "crown", meal)
    cn = get_menu(dining, "c9", meal)
    porter = get_menu(dining, "porter", meal)
    rcc = get_menu(dining, "rcc", meal)

    if "Dining Hall Closed!" in cowell:
        cowell = ""
    if "Dining Hall Closed!" in crown:
        crown = ""
    if "Dining Hall Closed!" in cn:
        cn = ""
    if "Dining Hall Closed!" in porter:
        porter = ""
    if "Dining Hall Closed!" in rcc:
        rcc = ""

    cowell = find_items(cowell, "cowell", keyword)
    crown = find_items(crown, "crown", keyword)
    cn = find_items(cn, "c9", keyword)
    porter = find_items(porter, "porter", keyword)
    rcc = find_items(rcc, "rcc", keyword)

    to_return = ""

    if not cowell == "":
        to_return += cowell
        pass
    if not crown == "":
        if not to_return == "":
            to_return += "\n"
        to_return += crown
        pass
    if not cn == "":
        if not to_return == "":
            to_return += "\n"
        to_return += cn
        pass
    if not porter == "":
        if not to_return == "":
            to_return += "\n"
        to_return += porter
        pass
    if not rcc == "":
        if not to_return == "":
            to_return += "\n"
        to_return += rcc
        pass

    if not to_return == "":
        if not meal == "":
            to_return = meal + "\n" + to_return
    return to_return
Exemplo n.º 5
0
def parse(bot, update):
    print_msg(update)
    DiningBot.store_from(str(update.message.from_user.username),
                         "telegram_users.txt")
    msg = update.message.text
    if msg.lower() == "hello there":
        bot.send_message(chat_id=update.message.chat_id, text="General Kenobi")
        return
    msg_list = msg.split(" ")
    if msg_list[0].lower() == "/menu" or msg_list[0].lower() == "menu":
        del msg_list[0]
    dining = UCSCDining()
    if dining.verify_name(msg_list[0]):
        college_name = dining.get_college_name(msg_list[0])
        meal_name = msg_list[len(msg_list) - 1]
        text = DiningBot.get_menu(dining, college_name, meal=meal_name)
        bot.send_message(chat_id=update.message.chat_id, text=text)
    else:
        print("TG-err: " + msg)
        bot.send_message(chat_id=update.message.chat_id,
                         text="Sorry, I don't know what college that is!")
Exemplo n.º 6
0
def search(bot, update):
    print_msg(update)
    DiningBot.store_from(str(update.message.from_user.username),
                         "telegram_users.txt")

    msg = update.message.text
    msg_list = msg.split(" ")
    del msg_list[0]
    dining = UCSCDining()
    meal = ""
    meal_id = dining.get_desired_meal(msg_list[len(msg_list) - 1])
    print(meal_id)
    if not meal_id == -1:
        meal = msg_list[len(msg_list) - 1]
        del msg_list[len(msg_list) - 1]
    msg_str = ""
    for x in msg_list:
        msg_str += x + " "
    msg_str = msg_str[:-1]
    send_msg = DiningBot.search(msg_str, meal=meal)
    if send_msg == "":
        send_msg = "That's not being served!"
    bot.send_message(chat_id=update.message.chat_id, text=send_msg)
Exemplo n.º 7
0
def store_from(text, filename):
    dining = UCSCDining()
    f = open(dining.get_path() + filename, 'a+')
    f.write(text)
    f.write('\n')
    f.close()