<commit_before>using ChatSharp.Events;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace ChatSharp.Handlers
{
    internal static class ChannelHandlers
    {
        public static void HandleJoin(IrcClient client, IrcMessage message)
        {
            var channel = client.Channels.GetOrAdd(message.Parameters[0]);
            var user = client.Users.GetOrAdd(message.Prefix);

            if (channel != null)
            {
                if (!user.Channels.Contains(channel))
                    user.Channels.Add(channel);

                client.OnUserJoinedChannel(new ChannelUserEventArgs(channel, new IrcUser(message.Prefix)));
            }
        }

        public static void HandleGetTopic(IrcClient client, IrcMessage message)
        {
            var channel = client.Channels.GetOrAdd(message.Parameters[1]);
            var old = channel._Topic;
            channel._Topic = message.Parameters[2];
            client.OnChannelTopicReceived(new ChannelTopicEventArgs(channel, old, channel._Topic));
        }

        public static void HandleGetEmptyTopic(IrcClient client, IrcMessage message)
        {
            var channel = client.Channels.GetOrAdd(message.Parameters[1]);
            var old = channel._Topic;
            channel._Topic = message.Parameters[2];
            client.OnChannelTopicReceived(new ChannelTopicEventArgs(channel, old, channel._Topic));
        }

        public static void HandlePart(IrcClient client, IrcMessage message)
        {
            if (!client.Channels.Contains(message.Parameters[0]))
                return; // we aren't in this channel, ignore

            var user = client.Users.Get(message.Prefix);
            var channel = client.Channels[message.Parameters[0]];

            if (user.Channels.Contains(channel))
                user.Channels.Remove(channel);
            client.OnUserPartedChannel(new ChannelUserEventArgs(client.Channels[message.Parameters[0]],
                new IrcUser(message.Prefix)));
        }

        public static void HandleUserListPart(IrcClient client, IrcMessage message)
        {
            var channel = client.Channels[message.Parameters[2]];
            var users = message.Parameters[3].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nick in users)
            {
                if (string.IsNullOrWhiteSpace(nick))
                    continue;
                var mode = client.ServerInfo.GetModeForPrefix(nick[0]);
                if (mode == null)
                {
                    var user = client.Users.GetOrAdd(nick);
                    if (!user.Channels.Contains(channel))
                        user.Channels.Add(channel);
                    if (!user.ChannelModes.ContainsKey(channel))
                        user.ChannelModes.Add(channel, null);
                    else<commit_msg>Remove user channel modes when they part the channel<commit_after>using ChatSharp.Events;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace ChatSharp.Handlers
{
    internal static class ChannelHandlers
    {
        public static void HandleJoin(IrcClient client, IrcMessage message)
        {
            var channel = client.Channels.GetOrAdd(message.Parameters[0]);
            var user = client.Users.GetOrAdd(message.Prefix);

            if (channel != null)
            {
                if (!user.Channels.Contains(channel))
                    user.Channels.Add(channel);

                client.OnUserJoinedChannel(new ChannelUserEventArgs(channel, new IrcUser(message.Prefix)));
            }
        }

        public static void HandleGetTopic(IrcClient client, IrcMessage message)
        {
            var channel = client.Channels.GetOrAdd(message.Parameters[1]);
            var old = channel._Topic;
            channel._Topic = message.Parameters[2];
            client.OnChannelTopicReceived(new ChannelTopicEventArgs(channel, old, channel._Topic));
        }

        public static void HandleGetEmptyTopic(IrcClient client, IrcMessage message)
        {
            var channel = client.Channels.GetOrAdd(message.Parameters[1]);
            var old = channel._Topic;
            channel._Topic = message.Parameters[2];
            client.OnChannelTopicReceived(new ChannelTopicEventArgs(channel, old, channel._Topic));
        }

        public static void HandlePart(IrcClient client, IrcMessage message)
        {
            if (!client.Channels.Contains(message.Parameters[0]))
                return; // we aren't in this channel, ignore

            var user = client.Users.Get(message.Prefix);
            var channel = client.Channels[message.Parameters[0]];

            if (user.Channels.Contains(channel))
                user.Channels.Remove(channel);
            if (user.ChannelModes.ContainsKey(channel))
                user.ChannelModes.Remove(channel);

            client.OnUserPartedChannel(new ChannelUserEventArgs(channel, user));
        }

        public static void HandleUserListPart(IrcClient client, IrcMessage message)
        {
            var channel = client.Channels[message.Parameters[2]];
            var users = message.Parameters[3].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nick in users)
            {
                if (string.IsNullOrWhiteSpace(nick))
                    continue;
                var mode = client.ServerInfo.GetModeForPrefix(nick[0]);
                if (mode == null)
                {
                    var user = client.Users.GetOrAdd(nick);
                    if (!user.Channels.Contains(channel))
                        user.Channels.Add(channel);
                    if (!user.ChannelModes.ContainsKey(channel))
                        user.ChannelModes.Add(channel, null);
                    else
{'fraction_non_alphanumeric': 0.09268375488032592, 'fraction_numerical': 0.0035647598030894585, 'mean_word_length': 2.0449612403100774, 'pattern_counts': {'":': 0, '<': 3, '<?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': '113060', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1431, 'n_words': 299}