Example #1
0
def quote_search(bot, trigger):
    """Searches quotes. If you want you can use ", " to assign the quote number you'd like to display."""

    args = trigger.group(2)

    # if ", " found, stores the search number into search_number and the query
    # into search_term. If no ", " found, splits search terms with a space
    # (%20)
    if args.find(', ') != -1:
        args = trigger.group(2).split(", ")
        search_term = conv(args[1].encode('utf-8')).split("%20")
        search_number = int(args[0])
    else:
        search_term = conv(trigger.group(2).encode('utf-8')).split("%20")
        search_number = 1

    # gets all the quotes, removes the trailing "|", and then splits the
    # quotes into quote_list
    quote_list = bot.db.preferences.get(trigger.sender,
                                        'quotes')[:-1].split("|")

    # this bit performs the search
    for i in search_term:
        findings = [s for s in quote_list if i in s]

    # if quotes are found, store the quote into output.
    try:
        output = "(" + str(findings.index(findings[search_number - 1]) + 1) + "/" + str(len(findings)) + ") - " + \
            str(quote_list.index(findings[search_number - 1]) + 1) + \
            ": " + findings[search_number - 1]
    except IndexError:
        bot.reply("Nothing found.")
        return
    bot.reply(unconv(output).decode('utf-8'))
Example #2
0
def quote_add(bot, trigger):
    """Adds a quote to a database"""

    # converts the quote to ascii format
    try:
        args = conv(trigger.group(2).encode('utf-8'))
    except AttributeError:
        bot.say("No quote given.")
        return
    orig = ''

    # checks if there are any quotes added and if so, stores them into orig
    try:
        orig = str(bot.db.preferences.get(trigger.sender, 'quotes'))
    except TypeError:
        pass

    # Checks if the quote we're adding is already added.
    if args in orig:
        bot.reply("Quote already added!")
        return

    # generates the new quote string
    # (I%20am%20a%20quote|Me%20too|I%20am%20as%20well|)
    quote = orig + args + '|'

    # adds the quote to the database
    bot.db.preferences.update(trigger.sender, {'quotes': quote})
    bot.reply("Quote added!")
Example #3
0
def quote_add(bot, trigger):
    """Adds a quote to a database"""

    # converts the quote to ascii format
    try:
        args = conv(trigger.group(2).encode("utf-8"))
    except AttributeError:
        bot.say("No quote given.")
        return
    orig = ""

    # checks if there are any quotes added and if so, stores them into orig
    try:
        orig = str(bot.db.preferences.get(trigger.sender, "quotes"))
    except TypeError:
        pass

    # Checks if the quote we're adding is already added.
    if args in orig:
        bot.reply("Quote already added!")
        return

    # generates the new quote string
    # (I%20am%20a%20quote|Me%20too|I%20am%20as%20well|)
    quote = orig + args + "|"

    # adds the quote to the database
    bot.db.preferences.update(trigger.sender, {"quotes": quote})
    bot.reply("Quote added!")
Example #4
0
def quote_search(bot, trigger):
    """Searches quotes. If you want you can use ", " to assign the quote number you'd like to display."""

    args = trigger.group(2)

    # if ", " found, stores the search number into search_number and the query
    # into search_term. If no ", " found, splits search terms with a space
    # (%20)
    if args.find(", ") != -1:
        args = trigger.group(2).split(", ")
        search_term = conv(args[1].encode("utf-8")).split("%20")
        search_number = int(args[0])
    else:
        search_term = conv(trigger.group(2).encode("utf-8")).split("%20")
        search_number = 1

    # gets all the quotes, removes the trailing "|", and then splits the
    # quotes into quote_list
    quote_list = bot.db.preferences.get(trigger.sender, "quotes")[:-1].split("|")

    # this bit performs the search
    for i in search_term:
        findings = [s for s in quote_list if i in s]

    # if quotes are found, store the quote into output.
    try:
        output = (
            "("
            + str(findings.index(findings[search_number - 1]) + 1)
            + "/"
            + str(len(findings))
            + ") - "
            + str(quote_list.index(findings[search_number - 1]) + 1)
            + ": "
            + findings[search_number - 1]
        )
    except IndexError:
        bot.reply("Nothing found.")
        return
    bot.reply(unconv(output).decode("utf-8"))