<commit_before>﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using AdiIRCAPI; // Include the API

namespace StripSystem
{
    public class Filter : IPlugin // Reference this is a plugin
    {
        IPluginHost _myHost = null;
        ITools _myTools = null;

        public string Description => "Filters join/part messages.";

        public string Author => "Xesyto";

        public string Name => "Join-Part Filter";

        public string Version => "3";

        public string Email => "";

        public IPluginHost Host
        {
            get { return _myHost; }
            set { _myHost = value; }
        }

        public ITools Tools
        {
            get { return _myTools; }
            set { _myTools = value; }
        }

        private Dictionary<string, UserData> userDatabase;
        private string ColourCode = "8"; //ascii char 3 is included at the start of this string but not clearly visible in VS Editor

        public Filter()
        {
            userDatabase = new Dictionary<string, UserData>();
        }

        public void Initialize()
        {
            // This is called when the plugin is loaded
            // Suscribe to delegates here
            _myHost.OnJoin += myHost_OnJoin;
            _myHost.OnPart += myHost_OnPart;
            _myHost.OnQuit += myHost_OnQuit;            
            _myHost.OnMessage += myHost_OnMessage;
            _myHost.OnNick += myHost_OnNick;
            _myHost.OnMode += myHost_OnMode;
        }

        private void myHost_OnMode(IServer server, IChannel channel, IUser user, string mode, out EatData Return)
        {
            if (user == null || string.IsNullOrEmpty(user.Ident))
            {
                Return = EatData.EatNone;
                return;
            }

            Return = EatData.EatText;
            var userKey = server.Network + channel.Name + user.Ident + user.Host;

            if (!userDatabase.ContainsKey(userKey)) return;

            var userData = userDatabase[userKey];
            if (userData.TalkedRecently())
            {
                Return = EatData.EatNone;
            }
        }

        private void myHost_OnNick(IServer server, IUser user, string newNick, out EatData Return)
        {
            Return = EatData.EatText;

            foreach (IChannel channel in server.GetChannels)<commit_msg>Fixed a bug with Mode changes being shown.<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using AdiIRCAPI; // Include the API

namespace StripSystem
{
    public class Filter : IPlugin // Reference this is a plugin
    {
        IPluginHost _myHost = null;
        ITools _myTools = null;

        public string Description => "Filters join/part messages.";

        public string Author => "Xesyto";

        public string Name => "Join-Part Filter";

        public string Version => "3";

        public string Email => "";

        public IPluginHost Host
        {
            get { return _myHost; }
            set { _myHost = value; }
        }

        public ITools Tools
        {
            get { return _myTools; }
            set { _myTools = value; }
        }

        private Dictionary<string, UserData> userDatabase;
        private string ColourCode = "8"; //ascii char 3 is included at the start of this string but not clearly visible in VS Editor

        public Filter()
        {
            userDatabase = new Dictionary<string, UserData>();
        }

        public void Initialize()
        {
            // This is called when the plugin is loaded
            // Suscribe to delegates here
            _myHost.OnJoin += myHost_OnJoin;
            _myHost.OnPart += myHost_OnPart;
            _myHost.OnQuit += myHost_OnQuit;            
            _myHost.OnMessage += myHost_OnMessage;
            _myHost.OnNick += myHost_OnNick;
            _myHost.OnMode += myHost_OnMode;
        }

        private void myHost_OnMode(IServer server, IChannel channel, IUser user, string mode, out EatData Return)
        {
            if (string.IsNullOrEmpty(user?.Ident))
            {
                var modeRegex = @"\+. (\w+)";
                var modeResult = Regex.Match(mode, modeRegex);

                string userName;

                if (modeResult.Success)
                {
                    userName = modeResult.Groups[1].ToString();
                }
                else
                {
                    Return = EatData.EatNone;
                    return;
                }

                foreach (IUser channelUser in channel.GetUsers)
                {
                    if (channelUser.Nick == userName)
                    {
                        user = channelUser;
                    }
                }

                if (string.IsNullOrEmpty(user?.Ident))
                {
                    Return = EatData.EatNone;
                    return;
                }
            }

            Return = EatData.EatText;
            var userKey = server.Network + channel.Name + user.Ident + user.Host;

            if (!userDatabase.ContainsKey(userKey)) return;

            var userData = userDatabase[userKey];
            if (userData.TalkedRecently())
            {
                Return = EatData.EatNone;
            }
        }

        private void myHost_OnNick(IServer server, IUser user, string newNick, out EatData Return)
        {
            Return = EatData.EatText;

            foreach (IChannel channel in server.GetChannels)
{'fraction_non_alphanumeric': 0.07997143877186719, 'fraction_numerical': 0.0012495537308104248, 'mean_word_length': 1.5398912058023573, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '1265722', 'n_tokens_mistral': 1514, 'n_tokens_neox': 1406, 'n_words': 403}