<commit_before>﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tphx.StreamChatSharp
{
    /// <summary>
    /// Data for a chat channel.
    /// </summary>
    public class ChatChannel
    {
        /// <summary>
        /// Constructs a new chat channel.
        /// </summary>
        /// <param name="channelName">Name of the channel</param>
        public ChatChannel(string channelName)
        { 
            this.Users = new ConcurrentDictionary<string, ChatUser>();
            this.ChannelName = channelName;
        }

        /// <summary>
        /// Name of the channel.
        /// </summary>
        public string ChannelName { get; set; }

        /// <summary>
        /// Users that are currently in the channel.
        /// </summary>
        public ConcurrentDictionary<string, ChatUser> Users { get; private set; }

        /// <summary>
        /// Lanaguage that is selected when broadcaster mode is enabled. English by default.
        /// </summary>
        public string BroadcasterLanguage { get; set; }

        /// <summary>
        /// Whether or not R9K mode is enabled.
        /// </summary>
        public bool R9KModeEnabled { get; set;  }

        /// <summary>
        /// Whether or not slow mode is enabled.
        /// </summary>
        public bool SlowModeEnabled { get; set; }

        /// <summary>
        /// The amount of seconds users must wait between meessages when slowmode is enabled.
        /// </summary>
        public int SlowModeInterval { get; set; }

        /// <summary>
        /// Whether or not subscribers only mode is enabled.
        /// </summary>
        public bool SubscribersOnlyModeEnabled { get; set; }

        /// <summary>
        /// Processes a chat message.
        /// </summary>
        /// <param name="chatMessage">Message to process.</param>
        internal void ProcessChatMessage(ChatMessage chatMessage)
        {
            switch(chatMessage.Source)
            {
                case "tmi":
                    SetRoomState(chatMessage.Tags);
                    break;
                case "jtv":
                    SetUserMode(chatMessage.Target, chatMessage.Message);
                    break;
                default:
                    this.Users.AddOrUpdate(chatMessage.Source, new ChatUser(chatMessage.Source, chatMessage.ChannelName),
                        (key, oldValue) => oldValue);
                    this.Users[chatMessage.Source].ProcessChatMessage(chatMessage);
                    break;
            }
        }

        private void SetUserMode(string user, string mode)
        {
            if (!String.IsNullOrWhiteSpace(user))
            {
                this.Users.AddOrUpdate(user, new ChatUser(user, this.ChannelName), (key, oldValue) => oldValue);
                this.Users[user].IsModerator = String.Equals(mode, "+o", StringComparison.OrdinalIgnoreCase);
            }
        }

        private void SetRoomState(string roomStates)
        {<commit_msg>Fixed a bug with mode adding users to user lists.<commit_after>﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tphx.StreamChatSharp
{
    /// <summary>
    /// Data for a chat channel.
    /// </summary>
    public class ChatChannel
    {
        /// <summary>
        /// Constructs a new chat channel.
        /// </summary>
        /// <param name="channelName">Name of the channel</param>
        public ChatChannel(string channelName)
        { 
            this.Users = new ConcurrentDictionary<string, ChatUser>();
            this.ChannelName = channelName;
        }

        /// <summary>
        /// Name of the channel.
        /// </summary>
        public string ChannelName { get; set; }

        /// <summary>
        /// Users that are currently in the channel.
        /// </summary>
        public ConcurrentDictionary<string, ChatUser> Users { get; private set; }

        /// <summary>
        /// Lanaguage that is selected when broadcaster mode is enabled. English by default.
        /// </summary>
        public string BroadcasterLanguage { get; set; }

        /// <summary>
        /// Whether or not R9K mode is enabled.
        /// </summary>
        public bool R9KModeEnabled { get; set;  }

        /// <summary>
        /// Whether or not slow mode is enabled.
        /// </summary>
        public bool SlowModeEnabled { get; set; }

        /// <summary>
        /// The amount of seconds users must wait between meessages when slowmode is enabled.
        /// </summary>
        public int SlowModeInterval { get; set; }

        /// <summary>
        /// Whether or not subscribers only mode is enabled.
        /// </summary>
        public bool SubscribersOnlyModeEnabled { get; set; }

        /// <summary>
        /// Processes a chat message.
        /// </summary>
        /// <param name="chatMessage">Message to process.</param>
        internal void ProcessChatMessage(ChatMessage chatMessage)
        {
            switch(chatMessage.Source)
            {
                case "tmi":
                    SetRoomState(chatMessage.Tags);
                    break;
                case "jtv":
                    SetUserMode(chatMessage.Target, chatMessage.Message);
                    break;
                default:
                    this.Users.AddOrUpdate(chatMessage.Source, new ChatUser(chatMessage.Source, chatMessage.ChannelName),
                        (key, oldValue) => oldValue);
                    this.Users[chatMessage.Source].ProcessChatMessage(chatMessage);
                    break;
            }
        }

        private void SetUserMode(string user, string mode)
        {
            if (this.Users.ContainsKey(user))
            {
                this.Users[user].IsModerator = String.Equals(mode, "+o", StringComparison.OrdinalIgnoreCase);
            }
        }

        private void SetRoomState(string roomStates)
        {
{'fraction_non_alphanumeric': 0.10958680385431978, 'fraction_numerical': 0.0006532745386248571, 'mean_word_length': 1.624946420917274, 'pattern_counts': {'":': 4, '<': 55, '<?xml version=': 0, '>': 58, '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': '4660830', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1497, 'n_words': 424}