Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Net.Sockets;
- using System.IO;
- using System.Timers;
- using System.Text.RegularExpressions;
- using System.Threading;
- namespace Twitch
- {
- public partial class Form1 : Form
- {
- TcpClient tcpclient;
- StreamReader reader;
- StreamWriter writer;
- StreamWriter writerTMI;
- string channel = "nizlmmk";
- Question question = new Question();
- static string[] questions = File.ReadAllLines("questionsDB.txt");
- static Random r = new Random();
- string[] split;
- bool wyrRunning = false;
- public Form1()
- {
- InitializeComponent();
- Reconnect();
- }
- private void Reconnect()
- {
- tcpclient = new TcpClient("irc.chat.twitch.tv", 6667);
- reader = new StreamReader(tcpclient.GetStream());
- writer = new StreamWriter(tcpclient.GetStream());
- var userName = "nizlmmk";
- var nickName = "nizlBOT";
- var password = File.ReadAllText("password.txt");
- writer.WriteLine("PASS " + password + Environment.NewLine
- + "NICK " + nickName + Environment.NewLine
- + "USER " + userName + " 8 * :" + userName);
- writer.WriteLine("CAP REQ :twitch.tv/membership");
- writer.WriteLine("JOIN #nizlmmk");
- writer.Flush();
- }
- void timer1_Tick(object sender, EventArgs e)
- {
- if (!tcpclient.Connected)
- {
- Reconnect();
- }
- if(tcpclient.Available > 0 || reader.Peek() >= 0)
- {
- var message = reader.ReadLine();
- if (message.Contains("PRIVMSG"))
- {
- string fMsg;
- int removeIndex = message.IndexOf('#') - message.IndexOf('!');
- fMsg = message.Remove(message.IndexOf('!'), removeIndex);
- fMsg = fMsg.Remove(fMsg.IndexOf('#'), 8);
- label1.AppendText(fMsg);
- if (message.StartsWith("!"))
- {
- findCommand(message);
- }
- }
- else
- {
- label1.AppendText(message);
- }
- label1.AppendText(Environment.NewLine);
- }
- public void displayResults()
- {
- sendChat("The questions were: ");
- sendChat($"1) {split[0]}");
- sendChat("OR");
- sendChat($"2) {split[1]}");
- sendChat(Convert.ToString(question.getSelected1()) + " Users selected option 1 ");
- sendChat(Convert.ToString(question.getSelected2()) + " Users selected option 2 ");
- question.resetSelected();
- }
- private void findCommand(string message)
- {
- if(message.Contains("!1"))
- {
- question.incSelected1();
- }
- if (message.Contains("!2"))
- {
- question.incSelected2();
- }
- if (message.EndsWith("!wyr"))
- {
- timer2.Enabled = true;
- wyrRunning = true;
- sendQuestion();
- }
- }
- public void sendQuestion()
- {
- string q = questions[r.Next(questions.Length)];
- //sendChat("would you rather?");
- if (Regex.IsMatch(q, @"\sor\s"))
- {
- split = Regex.Split(q, @"\sor\s");
- sendChat($"1) {split[0]}");
- sendChat("OR");
- sendChat($"2) {split[1]}");
- }
- }
- private void sendChat(string toChat)
- {
- writer.WriteLine(":nizlmmk!nizlmmk@nizlmmk.tmi.twitch.tv PRIVMSG #" + channel + " : " + toChat);
- writer.Flush();
- }
- private void sendUser(string user, string toChat)
- {
- writer.WriteLine(":" + user + "!" + user + "@" + user + ".tmi.twitch.tv PRIVMSG #" + channel + " : " + toChat);
- writer.Flush();
- }
- void timer2_Tick(object sender, EventArgs e)
- {
- if(wyrRunning)
- {
- displayResults();
- timer2.Enabled = false;
- wyrRunning = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement