<commit_before>﻿/**
* <description>
*     Monitors for swearing
* </description>
*
* <configuration>
*
* </configuration>
*
* <commands>
*     mmbot swearjar - shows the swear stats of users
* </commands>
* 
* <author>
*     dkarzon
* </author>
*/

var robot = Require<Robot>();

robot.Respond("swearjar", msg =>
{
    var swearBrain = robot.Brain.Get<List<SwearUser>>("swearbot").Result ?? new List<SwearUser>();

    foreach (var s in swearBrain)
    {
        if (s.Swears == null) continue;

        msg.Send(string.Format("{0} has sworn {1} times!", s.User, s.Swears.Count));
    }
});

robot.Hear(@".*(fuck|shit|cock|crap)(\s|$)", (msg) => 
{
    //Someone said a swear!
    var theSwear = msg.Match[1];
    var userName = msg.Message.User.Name;

    //load the swears from the Brain
    var swearBrain = robot.Brain.Get<List<SwearUser>>("swearbot").Result ?? new List<SwearUser>();

    var swearUser = swearBrain.FirstOrDefault(s => s.User == userName);
    if (swearUser == null)
    {
        swearUser = new SwearUser { User = userName };
        swearBrain.Add(swearUser);
    }
    if (swearUser.Swears == null)
    {
        swearUser.Swears = new List<SwearStat>();
    }
    swearUser.Swears.Add(new SwearStat{Swear = theSwear, Date = DateTime.Now});

    robot.Brain.Set("swearbot", swearBrain);

    msg.Send("SWEAR JAR!");
});

public class SwearStat<commit_msg>Some better regex2<commit_after>﻿/**
* <description>
*     Monitors for swearing
* </description>
*
* <configuration>
*
* </configuration>
*
* <commands>
*     mmbot swearjar - shows the swear stats of users
* </commands>
* 
* <author>
*     dkarzon
* </author>
*/

var robot = Require<Robot>();

robot.Respond("swearjar", msg =>
{
    var swearBrain = robot.Brain.Get<List<SwearUser>>("swearbot").Result ?? new List<SwearUser>();

    foreach (var s in swearBrain)
    {
        if (s.Swears == null) continue;

        msg.Send(string.Format("{0} has sworn {1} times!", s.User, s.Swears.Count));
    }
});

robot.Hear(@".*(\s|^)(fuck|shit|cock|crap)(\s|$)", (msg) => 
{
    //Someone said a swear!
    var theSwear = msg.Match[1];
    var userName = msg.Message.User.Name;

    //load the swears from the Brain
    var swearBrain = robot.Brain.Get<List<SwearUser>>("swearbot").Result ?? new List<SwearUser>();

    var swearUser = swearBrain.FirstOrDefault(s => s.User == userName);
    if (swearUser == null)
    {
        swearUser = new SwearUser { User = userName };
        swearBrain.Add(swearUser);
    }
    if (swearUser.Swears == null)
    {
        swearUser.Swears = new List<SwearStat>();
    }
    swearUser.Swears.Add(new SwearStat{Swear = theSwear, Date = DateTime.Now});

    robot.Brain.Set("swearbot", swearBrain);

    msg.Send("SWEAR JAR!");
});

public class SwearStat
{'fraction_non_alphanumeric': 0.1712946267580238, 'fraction_numerical': 0.0025243418680129825, 'mean_word_length': 3.1526946107784433, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 41, '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': '7024716', 'n_tokens_mistral': 1010, 'n_tokens_neox': 995, 'n_words': 205}