<commit_before>from .. import irc, var, ini
from ..tools import is_identified
import re

# Require identification with NickServ to send messages.
def ident (f):
    def check (user, channel, word):
        if is_identified(user):
            f(user, channel, word)
        else:
            irc.msg(channel, "{}: Identify with NickServ first.".format(user))
    return check

# Insert a message monitor to look for user activity.
def ins_monitor (message):
    user = message.split("!")[0][1:]
    try:
        event = msg.split(' ')[1]
    except IndexError:
        event = ''
    
    if event in ["JOIN", "PRIVMSG"]:
        send_messages(user)

# Fill commands dictionary.
def ins_command ():
    var.commands["tell"] = type("command", (object,), {})()
    var.commands["tell"].method = leave_message
    var.commands["tell"].aliases = [".tell", ".msg"]
    var.commands["tell"].usage = ["{} user message - Leave a message to user."]
    
    var.commands["listtell"] = type("command", (object,), {})()
    var.commands["listtell"].method = list_messages
    var.commands["listtell"].aliases = [".listtell", ".ltell", ".listtells", ".showtells"]
    var.commands["listtell"].usage = ["{} - Check if you have any messages and show them."]

# Fill a space for the messages database.
def ins_db ():
    var.data["messages"] = ini.fill_dict("messages.ini", "Messages")
    
    # Turning list of strings into a list of tuples.
    for user in var.data["messages"]:
        msg_list = [(msg.split(" ~ ")[0], msg.split(" ~ ", 1)[1]) for msg in var.data["messages"][user]]
        var.data["messages"][user] = msg_list

# Leave a message to someone.
def leave_message (user, channel, word):
    # It needs a nickname and a message.
    if len(word) < 3:
        irc.msg(channel, "{}: Wrong syntax. Check .help".format(user))
        return
    
    target = word[1]
    message = " ".join(word[2:])
    
    # Check if target is a valid nickname.
        if not re.match("[a-zA-Z\[\]\\`_\^\{\|\}][a-zA-Z0-9\[\]\\`_\^\{\|\}]", target):
            irc.msg(channel, "{} is not a valid nickname.".format(target))
            return
    
    # Check for repeated messages.
    if target in var.data["messages"]:
        if (user, message) in var.data["messages"][target]:
            irc.msg(channel, "{}: You already left this message.".format(user))
            return
    
    # Create an empty list for users not in the database.
    if target not in var.data["messages"]:
        var.data["messages"][target] = []
    
    # Append tuple and add to ini.
    var.data["messages"][target].append((user, message))
    ini.add_to_ini("Messages", target, "{} ~ {}".format(user, message), "messages.ini")
<commit_msg>Fixed indenting.<commit_after>from .. import irc, var, ini
from ..tools import is_identified
import re

# Require identification with NickServ to send messages.
def ident (f):
    def check (user, channel, word):
        if is_identified(user):
            f(user, channel, word)
        else:
            irc.msg(channel, "{}: Identify with NickServ first.".format(user))
    return check

# Insert a message monitor to look for user activity.
def ins_monitor (message):
    user = message.split("!")[0][1:]
    try:
        event = msg.split(' ')[1]
    except IndexError:
        event = ''
    
    if event in ["JOIN", "PRIVMSG"]:
        send_messages(user)

# Fill commands dictionary.
def ins_command ():
    var.commands["tell"] = type("command", (object,), {})()
    var.commands["tell"].method = leave_message
    var.commands["tell"].aliases = [".tell", ".msg"]
    var.commands["tell"].usage = ["{} user message - Leave a message to user."]
    
    var.commands["listtell"] = type("command", (object,), {})()
    var.commands["listtell"].method = list_messages
    var.commands["listtell"].aliases = [".listtell", ".ltell", ".listtells", ".showtells"]
    var.commands["listtell"].usage = ["{} - Check if you have any messages and show them."]

# Fill a space for the messages database.
def ins_db ():
    var.data["messages"] = ini.fill_dict("messages.ini", "Messages")
    
    # Turning list of strings into a list of tuples.
    for user in var.data["messages"]:
        msg_list = [(msg.split(" ~ ")[0], msg.split(" ~ ", 1)[1]) for msg in var.data["messages"][user]]
        var.data["messages"][user] = msg_list

# Leave a message to someone.
def leave_message (user, channel, word):
    # It needs a nickname and a message.
    if len(word) < 3:
        irc.msg(channel, "{}: Wrong syntax. Check .help".format(user))
        return
    
    target = word[1]
    message = " ".join(word[2:])
    
    # Check if target is a valid nickname.
    if not re.match("[a-zA-Z\[\]\\`_\^\{\|\}][a-zA-Z0-9\[\]\\`_\^\{\|\}]", target):
        irc.msg(channel, "{} is not a valid nickname.".format(target))
        return
    
    # Check for repeated messages.
    if target in var.data["messages"]:
        if (user, message) in var.data["messages"][target]:
            irc.msg(channel, "{}: You already left this message.".format(user))
            return
    
    # Create an empty list for users not in the database.
    if target not in var.data["messages"]:
        var.data["messages"][target] = []
    
    # Append tuple and add to ini.
    var.data["messages"][target].append((user, message))
    ini.add_to_ini("Messages", target, "{} ~ {}".format(user, message), "messages.ini")

{'fraction_non_alphanumeric': 0.1698392164110146, 'fraction_numerical': 0.004065791905377934, 'mean_word_length': 2.819336626676076, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4489096', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1670, 'n_words': 481}