<commit_before>from .. import ini, var, irc
from ..tools import is_identified, is_number
from ..tools import trim, nsfw_check

# Fill command dictionary.
def ins_command ():
    var.commands["desktop"] = type("command", (object,), {})()
    var.commands["desktop"].method = read
    var.commands["desktop"].aliases = [
        ".desktop",
        ".dtop",
        ".dekstop"
    ]
    var.commands["desktop"].usage = [
        "{} - See your desktop list.",
        "{} n - See nth desktop in your list.",
        "{} user - See user's desktop list.",
        "{} user n - See user's nth desktop.",
        " ",
        "{} -add url1 url2 ... - Add a list of urls to your desktop list.",
        "You can also use -a instead of -add.",
        " ",
        "{} -remove n1,n2,... - Remove a list of indexes from your list.",
        "You can also use -rm instead of -remove.",
        "{} -rm * will remove all of your saved desktops.",
        " ",
        "{} -replace n url - Replace your nth desktop with url.",
        "You can also use -re instead of -replace."
    ]

# This command will need NickServ auth sometimes.
def ident (f):
    def check (user, channel, word):
        try:
            if word[1] in [
                "-a", "-add",
                "-rm", "-remove",
                "-re", "-replace"
            ] and not is_identified(user):
                irc.msg(channel, "{}: Identify with NickServ first.".format(user))
            else:
                f(user, channel, word)
        except IndexError:
            f(user, channel, word)
    return check

# Parsing the content received.
def read (user, channel, word):
    
    if len(word) < 3:
        list_urls(user, channel, word)
    elif word[1] in ["-a", "-add"]:
        add_url(user, channel, word)
    elif word[1] in ["-rm", "--rm"]:
        delete_url(user, channel, word)
    elif word[1] in ["-re", "-replace"]:
        replace_url(user, channel, word)
    else:
        list_urls(user, channel, word)

# List saved desktops. Can accept username and/or a number as parameter.
def list_urls (user, channel, word):
    target, number = False, False
    
    if len(word) == 1:
        target = user
    elif len(word) == 2:
        target = word[1] if not is_number(word[1]) else user
        number = word[1] if is_number(word[1]) else False
    elif len(word) == 3:
        target = word[1]
        number = word[2]
    
    for nick in var.desktops:
        if target.lower() == nick.lower():
            target = nick
    
    # Throw a message if the target isn't in the desktop database.
    if target not in var.desktops:
        err_msg = "You don't" if target == user else "{} doesn't".format(target)
        irc.msg(channel, "{} have any desktops saved.".format(err_msg))
        return
    
    # Check if the received number is a valid integer.
    if (not is_number(number)) or ((int(number) if number else 1) < 1):
        irc.msg(channel, "{}: Invalid number.".format(user))
        return
        
    if number:
        # Turning number into a numeric value.
        number = int(number) - 1
        
        if number >= len(var.desktops[target]):
            err_msg = "You don't" if target == user else "{} doesn't".format(target)
            irc.msg(channel, "{} have that many desktops.".format(err_msg))
        else:
            line = "[{}] ".format("\x034NSFW\x0f" if "!" in var.desktops[target][number] else number+1)
            line += "{} [{}]".format(var.desktops[target][number].strip("!"), target)
            irc.msg(channel, line)<commit_msg>Fixed handling sentences with more than 3 words.<commit_after>from .. import ini, var, irc
from ..tools import is_identified, is_number
from ..tools import trim, nsfw_check

# Fill command dictionary.
def ins_command ():
    var.commands["desktop"] = type("command", (object,), {})()
    var.commands["desktop"].method = read
    var.commands["desktop"].aliases = [
        ".desktop",
        ".dtop",
        ".dekstop"
    ]
    var.commands["desktop"].usage = [
        "{} - See your desktop list.",
        "{} n - See nth desktop in your list.",
        "{} user - See user's desktop list.",
        "{} user n - See user's nth desktop.",
        " ",
        "{} -add url1 url2 ... - Add a list of urls to your desktop list.",
        "You can also use -a instead of -add.",
        " ",
        "{} -remove n1,n2,... - Remove a list of indexes from your list.",
        "You can also use -rm instead of -remove.",
        "{} -rm * will remove all of your saved desktops.",
        " ",
        "{} -replace n url - Replace your nth desktop with url.",
        "You can also use -re instead of -replace."
    ]

# This command will need NickServ auth sometimes.
def ident (f):
    def check (user, channel, word):
        try:
            if word[1] in [
                "-a", "-add",
                "-rm", "-remove",
                "-re", "-replace"
            ] and not is_identified(user):
                irc.msg(channel, "{}: Identify with NickServ first.".format(user))
            else:
                f(user, channel, word)
        except IndexError:
            f(user, channel, word)
    return check

# Parsing the content received.
def read (user, channel, word):
    
    if len(word) < 3:
        list_urls(user, channel, word)
    elif word[1] in ["-a", "-add"]:
        add_url(user, channel, word)
    elif word[1] in ["-rm", "--rm"]:
        delete_url(user, channel, word)
    elif word[1] in ["-re", "-replace"]:
        replace_url(user, channel, word)
    else:
        list_urls(user, channel, word)

# List saved desktops. Can accept username and/or a number as parameter.
def list_urls (user, channel, word):
    target, number = False, False
    
    if len(word) == 1:
        target = user
    elif len(word) == 2:
        target = word[1] if not is_number(word[1]) else user
        number = word[1] if is_number(word[1]) else False
    elif len(word) >= 3:
        target = word[1]
        number = word[2]
    
    for nick in var.desktops:
        if target.lower() == nick.lower():
            target = nick
    
    # Throw a message if the target isn't in the desktop database.
    if target not in var.desktops:
        err_msg = "You don't" if target == user else "{} doesn't".format(target)
        irc.msg(channel, "{} have any desktops saved.".format(err_msg))
        return
    
    # Check if the received number is a valid integer.
    if (not is_number(number)) or ((int(number) if number else 1) < 1):
        irc.msg(channel, "{}: Invalid number.".format(user))
        return
        
    if number:
        # Turning number into a numeric value.
        number = int(number) - 1
        
        if number >= len(var.desktops[target]):
            err_msg = "You don't" if target == user else "{} doesn't".format(target)
            irc.msg(channel, "{} have that many desktops.".format(err_msg))
        else:
            line = "[{}] ".format("\x034NSFW\x0f" if "!" in var.desktops[target][number] else number+1)
            line += "{} [{}]".format(var.desktops[target][number].strip("!"), target)
            irc.msg(channel, line)
{'fraction_non_alphanumeric': 0.14373515854169577, 'fraction_numerical': 0.007403268612934767, 'mean_word_length': 2.0326132994493857, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, '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': '3850424', 'n_tokens_mistral': 2233, 'n_tokens_neox': 2154, 'n_words': 710}