<commit_before>﻿using System;
using System.Collections.Generic;
using System.Threading;
using NLog;
using SignalR.Client.Hubs;

namespace Jabbot.Core.Jabbr
{
    public class JabbrClient : IJabbrClient
    {
        private static Logger Logger = LogManager.GetCurrentClassLogger();
        private HubConnection Connection { get; set; }
        private IHubProxy Proxy { get; set; }
        private List<string> Rooms { get; set; }
        public virtual bool IsConnected { get { return CheckIsConnected(); } }
        public virtual Action<string, string, string> OnReceivePrivateMessage { get; set; }
        public virtual Action<dynamic, string> OnReceiveRoomMessage { get; set; }

        public JabbrClient(string url)
        {
            if (String.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentNullException("url");
            }

            Rooms = new List<string>();
            Connection = new HubConnection(url);
            Proxy = Connection.CreateProxy("chat");
            SubscribeToEvents();
        }

        public virtual bool JoinRoom(string room)
        {
            var success = false;

            if (!Connection.IsActive)
            {
                throw new InvalidOperationException("JabbrClient has not yet been initialized.");
            }

            if (string.IsNullOrWhiteSpace(room))
            {
                throw new ArgumentNullException("room");
            }

            try
            {
                Send(String.Format("/join {0}", room));
                success = true;
            }
            catch(Exception ex)
            {
                Logger.ErrorException("An error occured while joining public room.", ex.GetBaseException());
            }

            return success;
        }

        public virtual bool JoinRoom(string room, string inviteCode)
        {
            var success = false;

            if (!Connection.IsActive)
            {
                throw new InvalidOperationException("JabbrClient has not yet been initialized.");
            }

            if (string.IsNullOrWhiteSpace(room))
            {
                throw new ArgumentNullException("room");
            }

            if (string.IsNullOrWhiteSpace(inviteCode))
            {
                throw new ArgumentNullException("inviteCode");
            }

            try
            {
                Send(String.Format("/join {0} {1}", room, inviteCode));
                success = true;
            }
            catch (Exception ex)
            {
                Logger.ErrorException("An error occured while joining private room.", ex.GetBaseException());
            }

            return success;
        }

        public virtual bool LeaveRoom(string room)
        {
            var success = false;

            if (!Connection.IsActive)
            {
                throw new InvalidOperationException("JabbrClient has not yet been initialized.");
            }

            if (string.IsNullOrWhiteSpace(room))
            {
                throw new ArgumentNullException("room");
            }

            try
            {
                Send(String.Format("/leave {0}", room));
                success = true;
            }
            catch (Exception ex)
            {
                Logger.ErrorException("An error occured while leaving room.", ex.GetBaseException());
            }

            return success;
        }

        public virtual bool Login(string nick, string password)
        {
            return Login(nick, password, null);
        }

        public virtual bool Login(string nick, string password, string gravatarEmail)
        {
            var success = false;

            if (!Connection.IsActive)
            {
                throw new InvalidOperationException("JabbrClient has not yet been initialized.");
            }

            if (string.IsNullOrWhiteSpace(nick))
            {
                throw new ArgumentNullException("nick");
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException("password");
            }

            try
            {
                Send(String.Format("/nick {0} {1}", nick, password));

                if (!string.IsNullOrWhiteSpace(gravatarEmail))
                {
                    Send(String.Format("/gravatar {0}", gravatarEmail));
                }
            }<commit_msg>Fix bug in JabbRClient<commit_after>﻿using System;
using System.Collections.Generic;
using System.Threading;
using NLog;
using SignalR.Client.Hubs;

namespace Jabbot.Core.Jabbr
{
    public class JabbrClient : IJabbrClient
    {
        private static Logger Logger = LogManager.GetCurrentClassLogger();
        private HubConnection Connection { get; set; }
        private IHubProxy Proxy { get; set; }
        private List<string> Rooms { get; set; }
        public virtual bool IsConnected { get { return CheckIsConnected(); } }
        public virtual Action<string, string, string> OnReceivePrivateMessage { get; set; }
        public virtual Action<dynamic, string> OnReceiveRoomMessage { get; set; }

        public JabbrClient(string url)
        {
            if (String.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentNullException("url");
            }

            Rooms = new List<string>();
            Connection = new HubConnection(url);
            Proxy = Connection.CreateProxy("chat");
            SubscribeToEvents();
        }

        public virtual bool JoinRoom(string room)
        {
            var success = false;

            if (!Connection.IsActive)
            {
                throw new InvalidOperationException("JabbrClient has not yet been initialized.");
            }

            if (string.IsNullOrWhiteSpace(room))
            {
                throw new ArgumentNullException("room");
            }

            try
            {
                Send(String.Format("/join {0}", room));
                success = true;
            }
            catch(Exception ex)
            {
                Logger.ErrorException("An error occured while joining public room.", ex.GetBaseException());
            }

            return success;
        }

        public virtual bool JoinRoom(string room, string inviteCode)
        {
            var success = false;

            if (!Connection.IsActive)
            {
                throw new InvalidOperationException("JabbrClient has not yet been initialized.");
            }

            if (string.IsNullOrWhiteSpace(room))
            {
                throw new ArgumentNullException("room");
            }

            if (string.IsNullOrWhiteSpace(inviteCode))
            {
                throw new ArgumentNullException("inviteCode");
            }

            try
            {
                Send(String.Format("/join {0} {1}", room, inviteCode));
                success = true;
            }
            catch (Exception ex)
            {
                Logger.ErrorException("An error occured while joining private room.", ex.GetBaseException());
            }

            return success;
        }

        public virtual bool LeaveRoom(string room)
        {
            var success = false;

            if (!Connection.IsActive)
            {
                throw new InvalidOperationException("JabbrClient has not yet been initialized.");
            }

            if (string.IsNullOrWhiteSpace(room))
            {
                throw new ArgumentNullException("room");
            }

            try
            {
                Send(String.Format("/leave {0}", room));
                success = true;
            }
            catch (Exception ex)
            {
                Logger.ErrorException("An error occured while leaving room.", ex.GetBaseException());
            }

            return success;
        }

        public virtual bool Login(string nick, string password)
        {
            return Login(nick, password, null);
        }

        public virtual bool Login(string nick, string password, string gravatarEmail)
        {
            var success = false;

            if (!Connection.IsActive)
            {
                throw new InvalidOperationException("JabbrClient has not yet been initialized.");
            }

            if (string.IsNullOrWhiteSpace(nick))
            {
                throw new ArgumentNullException("nick");
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException("password");
            }

            try
            {
                Send(String.Format("/nick {0} {1}", nick, password));

                if (!string.IsNullOrWhiteSpace(gravatarEmail))
                {
                    Send(String.Format("/gravatar {0}", gravatarEmail));
                }

                success = true;
            }
{'fraction_non_alphanumeric': 0.0871415770609319, 'fraction_numerical': 0.0015681003584229391, 'mean_word_length': 1.4584251101321586, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7198360', 'n_tokens_mistral': 2113, 'n_tokens_neox': 2015, 'n_words': 529}