static void Main(string[] args) { bool isConnected = false; while (isConnected != true) { try { Console.WriteLine("Enter the bot's username:"******"Enter the Twitch token:"); string TwitchToken = Console.ReadLine(); Console.WriteLine("Enter the channel you want to join:"); string ChannelName = Console.ReadLine(); Console.WriteLine("Enter the full path to the Python executable"); string pyPath = @Console.ReadLine(); pyCalc calc = new pyCalc(); calc.tcpProcessStart(pyPath); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect("127.0.0.1", 5005); Bot bot = new Bot(); bot.Connect(BotUsername, TwitchToken, ChannelName, pyPath, socket, calc); isConnected = true; Console.ReadLine(); } catch { Console.WriteLine("Invalid credentials."); Console.ReadKey(); Console.Clear(); } } }
private void onMessageReceieved(object sender, OnMessageReceivedArgs e, string pyLocation, Socket socket, pyCalc calc) { double unintelligibleProbability = calc.tcpUnintelligibilityProbability(e.ChatMessage.Message, socket); isFirst = false; MessageVector msgVector = new MessageVector(); MessageVectorGenerator msgGen = new MessageVectorGenerator(); msgVector = msgGen.messageVector(e.ChatMessage, unintelligibleProbability); int prediction = calc.predict(pyLocation, msgVector); if (prediction == 1) { client.SendMessage(e.ChatMessage.Channel, string.Format("stop, {0}", e.ChatMessage.DisplayName)); } }
public void Connect(string BotUsername, string TwitchToken, string ChannelName, string pyLocation, Socket socket, pyCalc calc) { ConnectionCredentials credentials = new ConnectionCredentials(BotUsername, TwitchToken); Console.WriteLine("Connecting..."); client = new TwitchClient(); client.Initialize(credentials, ChannelName); client.OnMessageReceived += (sender1, e1) => onMessageReceieved(sender1, e1, pyLocation, socket, calc); client.OnConnected += (sender2, e2) => onConnected(sender2, e2, ChannelName); client.Connect(); }