<commit_before>﻿using System;
using System.Configuration;
using System.Windows.Forms;

namespace SimpleMaid
{
  public partial class frmChatWindow : Form
  {
    public frmChatWindow()
    {
      InitializeComponent();
    }

    private static string userName;
    private static string supportName;
    private static string emptyLine;

    private void frmChatWindow_Load(object sender, EventArgs e)
    {
      string configUserName = ConfigurationManager.AppSettings["ChatUserName"];

      userName = (Variables.KeywordDefault == configUserName) ? Environment.UserName : configUserName;
      supportName = resources.SupportName;
      emptyLine = $"{userName}: ";

      this.Text = $"{Application.ProductName}: {resources.ChatWindowTitle}";
      letterBody.Text = emptyLine;
      btnSendLetter.Text = resources.btnSendLetter_Text;
      btnBidFarewell.Text = resources.btnBidFarewell_Text;

      letterBody.Enabled = true;
      btnSendLetter.Enabled = true;
      btnBidFarewell.Enabled = true;

      updateCursor();
    }

    private void frmChatWindow_FormClosing(object sender, FormClosingEventArgs e)
    {
      e.Cancel = true;
      Program.ChatboxExit = true;
    }


    private static bool letterBodyFreeze = true;

    private void tmrSpikeAssistance_Tick(object sender, EventArgs e)
    {
      if (Program.ChatboxExit)
        this.Dispose();

      // TODO: Remove this workaround (staying on top)
      this.TopMost = true;

      if (Program.SupportChatMessage != null)
      {
        if (String.Empty == letterBody.Text || !letterBody.Lines[letterBody.Lines.Length - 1].StartsWith(emptyLine))
        {
          letterBody.Text += $"{supportName}: {Program.SupportChatMessage}\n{emptyLine}";
        }
        else
        {
          letterBody.Text += $"\n{supportName}: {Program.SupportChatMessage}\n";
          letterBody.Text += letterBody.Lines[letterBody.Lines.Length - 3];
          deleteLine(letterBody.Lines.Length - 3);
        }
        Program.SupportChatMessage = null;

        updateCursor();
      }

      if (Program.ChatCommand != null)
      {
        // enable btnHelpingHoof, then start blinking
      }
    }

    private void deleteLine(int aLine)
    {
      int startIndex = letterBody.GetFirstCharIndexFromLine(aLine);
      int count = letterBody.Lines[aLine].Length;

      // Eat new line chars
      if (aLine < letterBody.Lines.Length - 1)
      {
        count += letterBody.GetFirstCharIndexFromLine(aLine + 1) -
            ((startIndex + count - 1) + 1);
      }

      letterBody.Text = letterBody.Text.Remove(startIndex, count);
    }

    private void updateCursor()
    {
      this.Activate();
      letterBody.SelectionStart = letterBody.Text.Length;
      letterBody.Focus();
    }

    private void btnSendLetter_Click(object sender, EventArgs e)
    {
      string currentLine = letterBody.Lines[letterBody.Lines.Length - 1];

      Program.UserChatMessage = currentLine.Remove(0, emptyLine.Length);

      if (currentLine.TrimEnd() != emptyLine.TrimEnd())
        letterBody.Text += $"\n{emptyLine}";

      updateCursor();
    }

    private void letterBody_KeyDown(object sender, KeyEventArgs e)
    {
      if (e.KeyCode == Keys.Enter)
      {
        e.SuppressKeyPress = true;
        btnSendLetter.PerformClick();
      }
    }

    private void letterBody_MouseEnter(object sender, EventArgs e)
    {
      this.Activate();
    }

    private void btnBidFarewell_Click(object sender, EventArgs e)
    {
      this.Close();
    }

    private void btnHelpingHoof_Click(object sender, EventArgs e)
    {
      // Program.cs
      // executeCmdCommand - easy
      // anyCommand - hard (generalize "Parsing command" from "Await commands" region)
    }
  }
}<commit_msg>Don't allow user to erase their nickname or something<commit_after>﻿using System;
using System.Configuration;
using System.Windows.Forms;

namespace SimpleMaid
{
  public partial class frmChatWindow : Form
  {
    public frmChatWindow()
    {
      InitializeComponent();
    }

    private static string userName;
    private static string supportName;
    private static string emptyLine;

    private void frmChatWindow_Load(object sender, EventArgs e)
    {
      string configUserName = ConfigurationManager.AppSettings["ChatUserName"];

      userName = (Variables.KeywordDefault == configUserName) ? Environment.UserName : configUserName;
      supportName = resources.SupportName;
      emptyLine = $"{userName}: ";

      this.Text = $"{Application.ProductName}: {resources.ChatWindowTitle}";
      letterBody.Text = emptyLine;
      btnSendLetter.Text = resources.btnSendLetter_Text;
      btnBidFarewell.Text = resources.btnBidFarewell_Text;

      letterBody.Enabled = true;
      btnSendLetter.Enabled = true;
      btnBidFarewell.Enabled = true;

      updateCursor();
    }

    private void frmChatWindow_FormClosing(object sender, FormClosingEventArgs e)
    {
      e.Cancel = true;
      Program.ChatboxExit = true;
    }


    // TODO: Visibility change when deactivated
    private void tmrSpikeAssistance_Tick(object sender, EventArgs e)
    {
      if (Program.ChatboxExit)
        this.Dispose();

      // TODO: Remove this workaround (staying on top)
      this.TopMost = true;

      if (Program.SupportChatMessage != null)
      {
        if (String.Empty == letterBody.Text || !letterBody.Lines[letterBody.Lines.Length - 1].StartsWith(emptyLine))
        {
          letterBody.Text += $"{supportName}: {Program.SupportChatMessage}\n{emptyLine}";
        }
        else
        {
          letterBody.Text += $"\n{supportName}: {Program.SupportChatMessage}\n";
          letterBody.Text += letterBody.Lines[letterBody.Lines.Length - 3];
          deleteLine(letterBody.Lines.Length - 3);
        }
        Program.SupportChatMessage = null;

        updateCursor();
      }

      if (Program.ChatCommand != null)
      {
        // enable btnHelpingHoof, then start blinking
      }
    }


    private void deleteLine(int aLine)
    {
      int startIndex = letterBody.GetFirstCharIndexFromLine(aLine);
      int count = letterBody.Lines[aLine].Length;

      // Eat new line chars
      if (aLine < letterBody.Lines.Length - 1)
      {
        count += letterBody.GetFirstCharIndexFromLine(aLine + 1) -
            ((startIndex + count - 1) + 1);
      }

      letterBody.Text = letterBody.Text.Remove(startIndex, count);
    }

    private void updateCursor()
    {
      this.Activate();
      letterBody.SelectionStart = letterBody.Text.Length;
      letterBody.Focus();
    }


    private void btnSendLetter_Click(object sender, EventArgs e)
    {
      string currentLine = letterBody.Lines[letterBody.Lines.Length - 1];

      Program.UserChatMessage = currentLine.Remove(0, emptyLine.Length);

      if (currentLine.TrimEnd() != emptyLine.TrimEnd())
        letterBody.Text += $"\n{emptyLine}";

      updateCursor();
    }

    private void btnBidFarewell_Click(object sender, EventArgs e)
    {
      this.Close();
    }

    private void btnHelpingHoof_Click(object sender, EventArgs e)
    {
      // Program.cs
      // executeCmdCommand - easy
      // anyCommand - hard (generalize "Parsing command" from "Await commands" region)
    }


    private static int charsCount = 0;

    private void letterBody_KeyDown(object sender, KeyEventArgs e)
    {
      if (e.KeyCode == Keys.Enter)
      {
        e.SuppressKeyPress = true;
        btnSendLetter.PerformClick();

        charsCount = 0;
      }
      else
      {
        if (e.KeyCode != Keys.Back)
        {
          charsCount++;
        }
        else
        {
          if (charsCount - 1 >= 0)
            charsCount--;
          else
            e.SuppressKeyPress = true;
        }
      }
    }

    private void letterBody_MouseEnter(object sender, EventArgs e)
    {
      this.Activate();
    }
  }
}
{'fraction_non_alphanumeric': 0.10212117363139846, 'fraction_numerical': 0.0027943604725009525, 'mean_word_length': 2.484070796460177, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '329740', 'n_tokens_mistral': 2356, 'n_tokens_neox': 2248, 'n_words': 477}