<commit_before>#-*- coding: utf-8 -*-
"""
quotes.py - Willie Quote Module
Original author: Meicceli
Licensed under the GNU Lesser General Public License Version 3 (or greater at your wish).
"""
from willie.module import commands, rate, example
from random import choice
from urllib import quote as conv
from urllib import unquote as unconv


def setup(bot):
    if bot.db and not bot.db.preferences.has_columns('quotes'):
        bot.db.preferences.add_columns(['quotes'])


@commands('aq', 'addquote')
@example(".addquote <Meicceli> embolalia can't code")
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!")


@commands('q', 'quote')
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'))


@commands('dq', 'delquote')
@rate(300)
@example('.delquote 3')
def quote_del(bot, trigger):
    """Deletes a quote from the database."""

    del_key = trigger.group(2)

    # 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 if-bit allows only me (meicceli) to delete all the quotes, but
    # allows others to delete one quote per 60 seconds (rate is 60)
    if del_key == "all" and trigger.nick.lower() == "markisking":
        bot.db.preferences.update(trigger.sender, {'quotes': ""})
        bot.reply("All quotes deleted!")
        return
    elif del_key.find(":") != -1 and trigger.nick.lower() == "markisking":
        uus_lista = "|".join(quote_list[:int(del_key[0]) - 1]) + "|"
        bot.db.preferences.update(trigger.sender, {'quotes': uus_lista})
        bot.reply("Deleted quotes, starting from " + str(int(del_key[0])))
        return
    elif del_key == "all" and trigger.nick.lower() != "markisking":
        bot.reply("You don't have the permission to do that! Ask Markisking")
        return
    else:
        pass

    # deletes the item by index shown in the beginning of every quote (for
    # example "5: quote" could be deleted with .delquote 5)
    del quote_list[int(del_key[0]) - 1]

    # This bit makes sure that there won't be any "||" found, which would mess
    # up the splitting in .quote (there would be empty strings in the
    # quote_list)
    modified_list = ""
    for i in quote_list:
        modified_list += i + "|"
    if modified_list.find('||') != 1:
        modified_list = modified_list.replace('||', '|')

    # updates the list with the quote removed
    bot.db.preferences.update(trigger.sender, {'quotes': modified_list})
    bot.reply("Quote deleted!")


@commands('sq', 'squote', 'searchquote')
@example('.sq 3, string1 string2')
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<commit_msg>made suggested changes and added help<commit_after>#-*- coding: utf-8 -*-
"""
quotes.py - Willie Quote Module
Original author: Meicceli
Licensed under the GNU Lesser General Public License Version 3 (or greater at your wish).
"""
from willie.module import commands, rate, example
from random import choice
from urllib import quote as conv
from urllib import unquote as unconv


def setup(bot):
    if bot.db and not bot.db.preferences.has_columns('quotes'):
        bot.db.preferences.add_columns(['quotes'])


@commands('aq', 'addquote')
@example(".addquote <Meicceli> embolalia can't code")
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!")


@commands('q', 'quote')
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'))


@commands('dq', 'delquote')
@rate(300)
@example('.delquote 3')
def quote_del(bot, trigger):
    """Deletes a quote from the database."""

    del_key = trigger.group(2)

    # 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 if-bit allows only me (meicceli) to delete all the quotes, but
    # allows others to delete one quote per 60 seconds (rate is 60)
    if del_key == "all" and trigger.admin:
        bot.db.preferences.update(trigger.sender, {'quotes': ""})
        bot.reply("All quotes deleted!")
        return
    elif del_key.find(":") != -1 and trigger.admin:
        uus_lista = "|".join(quote_list[:int(del_key[0]) - 1]) + "|"
        bot.db.preferences.update(trigger.sender, {'quotes': uus_lista})
        bot.reply("Deleted quotes, starting from " + str(int(del_key[0])))
        return
    elif del_key == "all" and trigger.admin:
        bot.reply("You don't have the permission to do that! Ask an admin!")
        return
    else:
        pass

    # deletes the item by index shown in the beginning of every quote (for
    # example "5: quote" could be deleted with .delquote 5)
    del quote_list[int(del_key[0]) - 1]

    # This bit makes sure that there won't be any "||" found, which would mess
    # up the splitting in .quote (there would be empty strings in the
    # quote_list)
    modified_list = ""
    for i in quote_list:
        modified_list += i + "|"
    if modified_list.find('||') != 1:
        modified_list = modified_list.replace('||', '|')

    # updates the list with the quote removed
    bot.db.preferences.update(trigger.sender, {'quotes': modified_list})
    bot.reply("Quote deleted!")


@commands('sq', 'squote', 'searchquote')
@example('.sq 3, string1 string2')
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
{'fraction_non_alphanumeric': 0.1244971842316975, 'fraction_numerical': 0.012268704746580853, 'mean_word_length': 2.9339398734177213, 'pattern_counts': {'":': 11, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4167098', 'n_tokens_mistral': 3148, 'n_tokens_neox': 3007, 'n_words': 1028}