<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net.Security;
using System.Threading;
using Newtonsoft.Json;
using _10blib;
namespace _10bClient
{
    public partial class Main : Form
    {
        Connection conn;
        string room = "48557f95";
        Dictionary<string, TabPage> rooms = new Dictionary<string, TabPage>();
        Dictionary<string, dynamic> roomMeta = new Dictionary<string,dynamic>();
        Dictionary<string, List<string>> userList = new Dictionary<string, List<string>>();
        List<string> roomsToJoin = new List<string>(); // Purely for keeping a queue of channels to join from favourites
        public Main(string host, int port, string user, string pass, Connect connForm)
        {
            InitializeComponent();
            connForm.Invoke((Action)(() => { connForm.Close(); }));
            conn = new _10blib.Connection(host, port, user, pass);
            conn.ReadString(ReadCall);
        }

        void ReadCall(IAsyncResult ar)
        {
            foreach (_10blib.Payload msg in conn.Payloads)
            {
                if (msg.op == "welcome") conn.Auth(WriteCall);
                this.BeginInvoke((Action)(() =>
                {
                    if (msg.ex.isack == null)
                    {
                        RichTextBox txtRoom;
                        if (msg.rm != null && msg.rm != "" && rooms.ContainsKey(msg.rm))
                            txtRoom = (RichTextBox)rooms[msg.rm].Controls.Find("txtRoom", true).ToList()[0];
                        else
                            txtRoom = txtStatus;

                        DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                        dt = dt.AddMilliseconds(msg.ts).ToLocalTime();
                        if (msg.op == "act" && msg.ex.message != null)
                        {
                            txtRoom.AppendText("[" + dt.ToLongTimeString() + "] ");
                            if (msg.ex.isaction != null && msg.ex.isaction == true) txtRoom.AppendText("* " + msg.sr + " " + msg.ex.message + "\r\n");
                            else txtRoom.AppendText("<" + msg.sr + "> " + msg.ex.message + "\r\n");
                        }
                        else if (msg.op == "join")
                        {
                            txtRoom.AppendText("[" + dt.ToLongTimeString() + "] ");
                            txtRoom.AppendText("* " + msg.sr + " has joined " + roomMeta[msg.rm].name + "\r\n");
                            ListView lst = (ListView)(rooms[msg.rm].Controls.Find("lstUsers", true).ToList()[0]);
                            ListViewItem item = new ListViewItem(msg.sr);
                            item.Name = msg.sr;
                            lst.Items.Add(item);
                            userList[msg.rm].Add(msg.sr);
                        }

                        else if (msg.op == "leave")
                        {
                            txtRoom.AppendText("[" + dt.ToLongTimeString() + "] ");
                            txtRoom.AppendText("[" + dt.ToLongTimeString() + "] ");
                            txtRoom.AppendText("* " + msg.sr + " has left " + roomMeta[msg.rm].name + ".\r\n");
                            ListView lst = (ListView)(rooms[msg.rm].Controls.Find("lstUsers", true).ToList()[0]);
                            lst.Items.Remove(lst.Items.Find(msg.sr, false)[0]);
                        }
                        else if (msg.op == "disconnect")
                        {
                            foreach(KeyValuePair<string, List<string>> keyval in userList)
                            {
                                if(keyval.Value.Contains(msg.sr))
                                {
                                    ListView lst = (ListView)(rooms[keyval.Key].Controls.Find("lstUsers", true).ToList()[0]);
                                    lst.Items.Remove(lst.Items.Find(msg.sr, false).ToList()[0]);
                                    RichTextBox txt = (RichTextBox)rooms[keyval.Key].Controls.Find("txtRoom", true).ToList()[0];
                                    txtRoom.AppendText("[" + dt.ToLongTimeString() + "] ");
                                    txt.AppendText("* " + msg.sr + " has quit.\r\n");
                                }
                            }
                        }
                        else if (msg.op == "meta")
                        {
                            if (msg.rm != null && !roomMeta.ContainsKey(msg.rm))<commit_msg>Print timestamps on quits properly<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net.Security;
using System.Threading;
using Newtonsoft.Json;
using _10blib;
namespace _10bClient
{
    public partial class Main : Form
    {
        Connection conn;
        string room = "48557f95";
        Dictionary<string, TabPage> rooms = new Dictionary<string, TabPage>();
        Dictionary<string, dynamic> roomMeta = new Dictionary<string,dynamic>();
        Dictionary<string, List<string>> userList = new Dictionary<string, List<string>>();
        List<string> roomsToJoin = new List<string>(); // Purely for keeping a queue of channels to join from favourites
        public Main(string host, int port, string user, string pass, Connect connForm)
        {
            InitializeComponent();
            connForm.Invoke((Action)(() => { connForm.Close(); }));
            conn = new _10blib.Connection(host, port, user, pass);
            conn.ReadString(ReadCall);
        }

        void ReadCall(IAsyncResult ar)
        {
            foreach (_10blib.Payload msg in conn.Payloads)
            {
                if (msg.op == "welcome") conn.Auth(WriteCall);
                this.BeginInvoke((Action)(() =>
                {
                    if (msg.ex.isack == null)
                    {
                        RichTextBox txtRoom;
                        if (msg.rm != null && msg.rm != "" && rooms.ContainsKey(msg.rm))
                            txtRoom = (RichTextBox)rooms[msg.rm].Controls.Find("txtRoom", true).ToList()[0];
                        else
                            txtRoom = txtStatus;

                        DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                        dt = dt.AddMilliseconds(msg.ts).ToLocalTime();
                        if (msg.op == "act" && msg.ex.message != null)
                        {
                            txtRoom.AppendText("[" + dt.ToLongTimeString() + "] ");
                            if (msg.ex.isaction != null && msg.ex.isaction == true) txtRoom.AppendText("* " + msg.sr + " " + msg.ex.message + "\r\n");
                            else txtRoom.AppendText("<" + msg.sr + "> " + msg.ex.message + "\r\n");
                        }
                        else if (msg.op == "join")
                        {
                            txtRoom.AppendText("[" + dt.ToLongTimeString() + "] ");
                            txtRoom.AppendText("* " + msg.sr + " has joined " + roomMeta[msg.rm].name + "\r\n");
                            ListView lst = (ListView)(rooms[msg.rm].Controls.Find("lstUsers", true).ToList()[0]);
                            ListViewItem item = new ListViewItem(msg.sr);
                            item.Name = msg.sr;
                            lst.Items.Add(item);
                            userList[msg.rm].Add(msg.sr);
                        }

                        else if (msg.op == "leave")
                        {
                            txtRoom.AppendText("[" + dt.ToLongTimeString() + "] ");
                            txtRoom.AppendText("[" + dt.ToLongTimeString() + "] ");
                            txtRoom.AppendText("* " + msg.sr + " has left " + roomMeta[msg.rm].name + ".\r\n");
                            ListView lst = (ListView)(rooms[msg.rm].Controls.Find("lstUsers", true).ToList()[0]);
                            lst.Items.Remove(lst.Items.Find(msg.sr, false)[0]);
                        }
                        else if (msg.op == "disconnect")
                        {
                            foreach(KeyValuePair<string, List<string>> keyval in userList)
                            {
                                if(keyval.Value.Contains(msg.sr))
                                {

                                    ListView lst = (ListView)(rooms[keyval.Key].Controls.Find("lstUsers", true).ToList()[0]);
                                    lst.Items.Remove(lst.Items.Find(msg.sr, false).ToList()[0]);
                                    RichTextBox txt = (RichTextBox)rooms[keyval.Key].Controls.Find("txtRoom", true).ToList()[0];
                                    txt.AppendText("[" + dt.ToLongTimeString() + "] ");
                                    txt.AppendText("* " + msg.sr + " has quit.\r\n");
                                }
                            }
                        }
                        else if (msg.op == "meta")
                        {
                            if (msg.rm != null && !roomMeta.ContainsKey(msg.rm))
{'fraction_non_alphanumeric': 0.1321276595744681, 'fraction_numerical': 0.006808510638297872, 'mean_word_length': 1.2862354085603114, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2731169', 'n_tokens_mistral': 2488, 'n_tokens_neox': 2368, 'n_words': 465}