Example #1
0
def quote_listi(bot, trigger):
    quote_list = bot.db.preferences.get(trigger.sender, "quotes")[:-1].split("|")
    if not trigger.group(2):
        bot.reply("There are " + str(len(quote_list)) + " quotes.")
    else:
        if len(quote_list) > 5:
            for i in bot.db.preferences.get(trigger.sender, "quotes")[:-1].split("|"):
                bot.msg(trigger.nick, unconv(i))
            return
        else:
            for i in bot.db.preferences.get(trigger.sender, "quotes")[:-1].split("|"):
                bot.say(unconv(i))
            return
Example #2
0
def quote_listi(bot, trigger):
    quote_list = bot.db.preferences.get(trigger.sender,
                                        'quotes')[:-1].split("|")
    if not trigger.group(2):
        bot.reply("There are " + str(len(quote_list)) + " quotes.")
    else:
        if len(quote_list) > 5:
            for i in bot.db.preferences.get(trigger.sender,
                                            'quotes')[:-1].split("|"):
                bot.msg(trigger.nick, unconv(i))
            return
        else:
            for i in bot.db.preferences.get(trigger.sender,
                                            'quotes')[:-1].split("|"):
                bot.say(unconv(i))
            return
Example #3
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 #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"))
Example #5
0
def get_conv(bot, trigger):
    """Gets a random quote from the database"""

    # gets all the quotes, removes the trailing "|", and then splits the
    # quotes into quote_list
    try:
        quote_list = bot.db.preferences.get(trigger.sender,
                                            'quotes')[:-1].split("|")
    # checks if there are any quotes
    except TypeError:
        bot.reply("No quotes added!")
        return

    # checks if all the quotes have been deleted
    if len(quote_list) == 1 and quote_list[0] == "":
        bot.reply("No quotes added!")
        return

    # if a quote number is given, this fetches the quote associated with the
    # given number.
    if trigger.group(2):
        try:
            number = int(trigger.group(2))
            output = str(number) + ": " + quote_list[number - 1]
        except ValueError:
            bot.say(u"Must be a number or a string!")
            return
    # if no quote number is given, this picks a quote randomly
    else:
        #(pseudo-)randomly chooses a quote from quote_list
        ans = choice(quote_list)
        # generates the output (7:%20This%20is%20the%20quote)
        output = str(quote_list.index(ans) + 1) + ": " + ans

    # converts the "%20" etc. back into a readable format (7: This is the
    # quote)
    bot.say(unconv(output).decode('utf-8'))
Example #6
0
def get_conv(bot, trigger):
    """Gets a random quote from the database"""

    # gets all the quotes, removes the trailing "|", and then splits the
    # quotes into quote_list
    try:
        quote_list = bot.db.preferences.get(trigger.sender, "quotes")[:-1].split("|")
    # checks if there are any quotes
    except TypeError:
        bot.reply("No quotes added!")
        return

    # checks if all the quotes have been deleted
    if len(quote_list) == 1 and quote_list[0] == "":
        bot.reply("No quotes added!")
        return

    # if a quote number is given, this fetches the quote associated with the
    # given number.
    if trigger.group(2):
        try:
            number = int(trigger.group(2))
            output = str(number) + ": " + quote_list[number - 1]
        except ValueError:
            bot.say(u"Must be a number or a string!")
            return
    # if no quote number is given, this picks a quote randomly
    else:
        # (pseudo-)randomly chooses a quote from quote_list
        ans = choice(quote_list)
        # generates the output (7:%20This%20is%20the%20quote)
        output = str(quote_list.index(ans) + 1) + ": " + ans

    # converts the "%20" etc. back into a readable format (7: This is the
    # quote)
    bot.say(unconv(output).decode("utf-8"))