<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dbot.Client;
using Dbot.Common;
using Dbot.CommonModels;
using Dbot.Data;
using Dbot.Processor;
using Dbot.Utility;
using Tweetinvi;
using Tweetinvi.Core.Credentials;
using Tweetinvi.Core.Interfaces;
using Message = Dbot.CommonModels.Message;

namespace Dbot.Main {
  public class PrimaryLogic {
    private readonly IClient _client = new WebSocketListenerClient(PrivateConstants.BotWebsocketAuth);
    //private readonly IClient _client = new WebSocketListenerClient();
    private readonly MessageProcessor _messageProcessor;
    private bool _exit;

    public PrimaryLogic() {
      _messageProcessor = new MessageProcessor(_client);
    }

    public void Run() {
      InitializeDatastore.Run();
      Auth.SetCredentials(new TwitterCredentials(PrivateConstants.TwitterConsumerKey, PrivateConstants.TwitterConsumerSecret, PrivateConstants.TwitterAccessToken, PrivateConstants.TwitterAccessTokenSecret));
      var stream = Stream.CreateUserStream();
      stream.TweetCreatedByFriend += (sender, args) => TweetDetected(args.Tweet);
      stream.StartStreamAsync();

      PeriodicTask.Run(() => Tools.LiveStatus(), TimeSpan.FromMinutes(2));
      Tools.LiveStatus();
      PeriodicTask.Run(InitializeDatastore.UpdateEmotes, TimeSpan.FromMinutes(5));

      _client.Run(_messageProcessor);
      Console.CancelKeyPress += Console_CancelKeyPress;
      //http://stackoverflow.com/questions/14255655/tpl-dataflow-producerconsumer-pattern
      //http://msdn.microsoft.com/en-us/library/hh228601(v=vs.110).aspx

      while (!_exit) {
        //Process.GetCurrentProcess().WaitForExit(); // If you ever have to get rid of the while(true)
        var input = Console.ReadLine();
        if (!string.IsNullOrEmpty(input)) {
          if (input == "exit") {
            _exit = true;
          } else if (input[0] == '~') {
            _client.Send(new PublicMessage(input.Substring(1)));
          } else if (input[0] == '!') {
            _client.Forward(new PublicMessage("SYSTEM CONSOLE", input) { IsMod = true });
          }
        }
      }
      Exit();
    }

    public async Task<IList<string>> TestRun(IEnumerable<PublicMessage> testInput) {
      InitializeDatastore.Run();
      var testClient = new TestClient();
      return await testClient.Run(new MessageProcessor(testClient), testInput);
    }

    private void TweetDetected(ITweet tweet) {
      _messageProcessor.Sender.Post(new ModPublicMessage("twitter.com/steven_bonnell just tweeted: \n" + Tools.TweetPrettier(tweet)));
    }

    private void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) {
      Exit();
    }

    private void Exit() {
      Datastore.Terminate();
    }
  }
}<commit_msg>Dropped the newline in new tweets.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dbot.Client;
using Dbot.Common;
using Dbot.CommonModels;
using Dbot.Data;
using Dbot.Processor;
using Dbot.Utility;
using Tweetinvi;
using Tweetinvi.Core.Credentials;
using Tweetinvi.Core.Interfaces;
using Message = Dbot.CommonModels.Message;

namespace Dbot.Main {
  public class PrimaryLogic {
    private readonly IClient _client = new WebSocketListenerClient(PrivateConstants.BotWebsocketAuth);
    //private readonly IClient _client = new WebSocketListenerClient();
    private readonly MessageProcessor _messageProcessor;
    private bool _exit;

    public PrimaryLogic() {
      _messageProcessor = new MessageProcessor(_client);
    }

    public void Run() {
      InitializeDatastore.Run();
      Auth.SetCredentials(new TwitterCredentials(PrivateConstants.TwitterConsumerKey, PrivateConstants.TwitterConsumerSecret, PrivateConstants.TwitterAccessToken, PrivateConstants.TwitterAccessTokenSecret));
      var stream = Stream.CreateUserStream();
      stream.TweetCreatedByFriend += (sender, args) => TweetDetected(args.Tweet);
      stream.StartStreamAsync();

      PeriodicTask.Run(() => Tools.LiveStatus(), TimeSpan.FromMinutes(2));
      Tools.LiveStatus();
      PeriodicTask.Run(InitializeDatastore.UpdateEmotes, TimeSpan.FromMinutes(5));

      _client.Run(_messageProcessor);
      Console.CancelKeyPress += Console_CancelKeyPress;
      //http://stackoverflow.com/questions/14255655/tpl-dataflow-producerconsumer-pattern
      //http://msdn.microsoft.com/en-us/library/hh228601(v=vs.110).aspx

      while (!_exit) {
        //Process.GetCurrentProcess().WaitForExit(); // If you ever have to get rid of the while(true)
        var input = Console.ReadLine();
        if (!string.IsNullOrEmpty(input)) {
          if (input == "exit") {
            _exit = true;
          } else if (input[0] == '~') {
            _client.Send(new PublicMessage(input.Substring(1)));
          } else if (input[0] == '!') {
            _client.Forward(new PublicMessage("SYSTEM CONSOLE", input) { IsMod = true });
          }
        }
      }
      Exit();
    }

    public async Task<IList<string>> TestRun(IEnumerable<PublicMessage> testInput) {
      InitializeDatastore.Run();
      var testClient = new TestClient();
      return await testClient.Run(new MessageProcessor(testClient), testInput);
    }

    private void TweetDetected(ITweet tweet) {
      _messageProcessor.Sender.Post(new ModPublicMessage("twitter.com/steven_bonnell just tweeted: " + Tools.TweetPrettier(tweet)));
    }

    private void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) {
      Exit();
    }

    private void Exit() {
      Datastore.Terminate();
    }
  }
}
{'fraction_non_alphanumeric': 0.11258161284630316, 'fraction_numerical': 0.007764249161814011, 'mean_word_length': 3.6156351791530943, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '889971', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1617, 'n_words': 328}