Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- 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;
- using System.Net.Sockets;
- using System.IO;
- using System.Threading;
- using System.Text.RegularExpressions;
- using System.Runtime.InteropServices;
- using System.Media;
- using System.Diagnostics;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- #region variables
- public static string userName = "zexobot";
- public static string password = "oauth:DansGame";
- private static IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, userName, password);
- NetworkStream serverStream = default(NetworkStream);
- Thread chatThread;
- IniFile Pointsini = new IniFile(@"C:\Users\Tanner_\Documents\Visual Studio 2015\Projects\ExoBot\ExoBot\Points.ini");
- string readData = "";
- string scrambledWord = "";
- string word = "";
- string url = "https://decapi.me/twitch/uptime?channel=zexodiousz";
- string result = null;
- string viewercount = "https://tmi.twitch.tv/group/user/zexodiousz/chatters";
- Thread oThread = new Thread(new ThreadStart(Broadcast));
- #endregion
- #region form open, close, stuff
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- /*while (irc == null)
- {
- try
- {
- IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, userName, password);*/
- irc.joinRoom("zexodiousz");
- chatThread = new Thread(getMessage);
- chatThread.Start();
- /*}
- catch (Exception x)
- {
- var message = "Could not connect to the irc channel. Reconnect?";
- var title = "Error";
- var result = MessageBox.Show(message, title, MessageBoxButtons.YesNo);
- switch (result)
- {
- case DialogResult.Yes:
- MessageBox.Show("Reconnecting");
- break;
- case DialogResult.No:
- Application.Exit();
- break;
- }
- }
- }*/
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- irc.leaveRoom();
- serverStream.Dispose();
- Environment.Exit(0);
- }
- private void getMessage()
- {
- serverStream = irc.tcpClient.GetStream();
- int buffsize = 0;
- byte[] inStream = new byte[10025];
- buffsize = irc.tcpClient.ReceiveBufferSize;
- while (true)
- {
- try
- {
- readData = irc.readMessage();
- msg();
- }
- catch (Exception)
- {
- }
- }
- }
- private void msg()
- {
- if (this.InvokeRequired) this.Invoke(new MethodInvoker(msg));
- else
- {
- string[] separator = new string[] { "#zexodiousz :" };
- string[] singlesep = new string[] { ":", "!" };
- if (readData.Contains("PRIVMSG"))
- {
- string username = readData.Split(singlesep, StringSplitOptions.None)[1];
- string message = readData.Split(separator, StringSplitOptions.None)[1];
- if (message[0] == '!') commands(username, message);
- ChatBox.Text = ChatBox.Text + username + "> " + message + Environment.NewLine;
- int num = ChatBox.Lines.Count();
- if (ChatBox.Lines.Count() > 301)
- {
- var foos = new List<string>(ChatBox.Lines);
- foos.RemoveAt(0);
- ChatBox.Lines = foos.ToArray();
- }
- }
- }
- }
- private void richTextBox1_TextChanged(object sender, EventArgs e)
- {
- ChatBox.SelectionStart = ChatBox.Text.Length;
- ChatBox.ScrollToCaret();
- }
- private void richTextBox1_TextChanged_1(object sender, EventArgs e)
- {
- }
- private void label2_Click(object sender, EventArgs e)
- {
- }
- private void OriginalWord_TextChanged(object sender, EventArgs e)
- {
- }
- private void ScrambledText_TextChanged(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- irc.sendChatMessage(BotChatBox.Text);
- BotChatBox.Clear();
- }
- private void BotChatBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == Convert.ToChar(Keys.Return))
- {
- irc.sendChatMessage(BotChatBox.Text);
- BotChatBox.Clear();
- }
- }
- private void broadcastContact_Click(object sender, EventArgs e)
- {
- irc.sendChatMessage("You can contact me through snapchat: will_miles11, Twitter: @zexodious, or even on youtube: https://youtube.com/zExodious");
- }
- private void ABContact_CheckedChanged(object sender, EventArgs e)
- {
- if (checked(true) && !oThread.IsAlive)
- {
- oThread.Start();
- }
- else if (unchecked(true) && oThread.IsAlive)
- {
- oThread.Abort();
- oThread.Join();
- oThread = new Thread(new ThreadStart(Broadcast));
- }
- }
- private void shuffleButton_Click(object sender, EventArgs e)
- {
- Scramble();
- irc.sendChatMessage("Unscramble this word to win 10 points. usage: !guess [word] > " + scrambledWord + " <");
- OriginalWord.Text = word;
- ScrambledText.Text = scrambledWord;
- }
- private void ABShuffle_CheckedChanged(object sender, EventArgs e)
- {
- //THIS IS ONLY IF THIS STOPS WORKING MessageBox.Show("This Is Not Yet Available. Please Use !Shuffle or Click The Shuffle Button");
- //irc.sendChatMessage("Unscramble this word to win 10 points. usage: !guess [word] > " + scrambledWord + " <");
- //Thread.Sleep(300000);
- }
- private static void Broadcast()
- {
- while (true)
- {
- irc.sendChatMessage("You can contact me through snapchat: will_miles11, Twitter: @zexodious, or even on youtube: https://youtube.com/zExodious");
- Thread.Sleep(300000);
- }
- }
- private void AddPoints(string username, double points)
- {
- double finalnumber = 0;
- try
- {
- string[] separator = new string[] { @"\r\n" };
- username = username.Trim().ToLower();
- string pointsofuser = Pointsini.IniReadValue("#zexodiousz." + username, "Points");
- double numberofpoints = double.Parse(pointsofuser);
- finalnumber = Convert.ToDouble(numberofpoints + points);
- if (finalnumber > 0) Pointsini.IniWriteValue("#zexodiousz." + username, "Points", finalnumber.ToString());
- if (finalnumber <= 0) Pointsini.IniWriteValue("#zexodiousz." + username, "Points", "0");
- }
- catch (Exception)
- {
- if (points > 0) Pointsini.IniWriteValue("#zexodiousz." + username, "Points", points.ToString());
- }
- }
- public void Scramble()
- {
- string[] words = { "home", "food", "game", "rest", "jazz", "joke", "maze", "mojo", "lazy", "zinc", "fuze", "fuse", "juke", "jack", "buzz", "lick", "sick", "path", "snap", "pond", "poor", "rich", "rick", "plan", "team", "cast", "help", "when", "view", "edit", "more", "file", "lore", "sore", "boar", "core", "door", "same", "came", "tame", "lame", "lane", "lack", "data", "lamp", "land", "last", "form", "math", "mast", "code", "toad", "node", "list", "cyst", "wish", "kiss", "miss", "lisp", "fish", "snip", "snap", "crack", "stop", "crop", "drop", "blop", "slop", "mope", "soap", "cope", "coke", "nope", "loop", "soup", "poop", "crap", "crab", "whip", "cream", "shop", "wimp", "limp", "pimp", "wisk", "pint", "tisk", "mite", "dust", "bugs", "hype", "wipe", "tool", "cart", "lite", "shot", "ship", "shin", "chan", "spam", "cram", "spun", "spat", "spit", "unit", "over", "wolf", "fall", "flag", "corn", "worn", "card", "port", "died", "memo", "hole", "coal", "toll", "roll" };
- int WORD_SIZE = 4;
- // Define some 4-letter words to be scrambled.
- // Define two arrays equal to the number of letters in each word.
- double[] keys = new double[WORD_SIZE];
- string[] letters = new string[WORD_SIZE];
- // Initialize the random number generator.
- Random rnd = new Random();
- //119
- word = words[rnd.Next(119)];
- for (int ctr = 0; ctr < word.Length; ctr++)
- {
- // Populate the array of keys with random numbers.
- keys[ctr] = rnd.NextDouble();
- // Assign a letter to the array of letters.
- letters[ctr] = word[ctr].ToString();
- }
- // Sort the array.
- Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default);
- // Display the scrambled word.
- scrambledWord = String.Concat(letters[0], letters[1],
- letters[2], letters[3]);
- }
- private void button2_Click(object sender, EventArgs e)
- {
- ChatBox.Clear();
- }
- private void richTextBox1_TextChanged_2(object sender, EventArgs e)
- {
- return;
- }
- private void button2_Click_1(object sender, EventArgs e)
- {
- string modnames = "";
- string viewernames = "";
- Viewercount(ref modnames, ref viewernames, false);
- richTextBox1.Text = "Moderators :" + modnames + "\n\n" + "Viewers :" + viewernames;
- }
- private void Viewercount(ref string modnames, ref string viewernames, bool sn = true)
- {
- WebClient viewerclient = new WebClient();
- result = viewerclient.DownloadString(viewercount);
- System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex("\"moderators\": \\[[^\\]]*\\]", RegexOptions.Singleline);
- if (re.IsMatch(result))
- {
- string raw = re.Match(result).Value;
- string rawnames = raw.Split('[')[1];
- string[] names = rawnames.Split(',');
- string namestring = "";
- foreach (string name in names)
- {
- namestring += (name + ", ");
- if (sn) namestring = namestring.Replace("\n", "");
- namestring = namestring.Replace("\"", "");
- }
- namestring = namestring.Split(']')[0];
- if (string.IsNullOrWhiteSpace(namestring)) namestring = "no moderators present";
- modnames = namestring;
- }
- re = new System.Text.RegularExpressions.Regex("\"viewers\": \\[[^\\]]*\\]", RegexOptions.Singleline);
- if (re.IsMatch(result))
- {
- string raw = re.Match(result).Value;
- string rawnames = raw.Split('[')[1];
- string[] names = rawnames.Split(',');
- string namestring = "";
- foreach (string name in names)
- {
- namestring += (name + ", ");
- if (sn) namestring = namestring.Replace("\n", "");
- namestring = namestring.Replace("\"", "");
- }
- namestring = namestring.Split(']')[0];
- if (string.IsNullOrWhiteSpace(namestring)) namestring = "no viewers present";
- viewernames = namestring;
- }
- }
- #endregion
- private void commands(string username, string message)
- {
- string command = message.Split(new[] { ' ', '!' }, StringSplitOptions.None)[1];
- switch (command.ToLower())
- {
- case "help":
- irc.sendChatMessage("@" + username + " Commands: !sr, !points, !uptime, !points, !guess, !fire, !rules, !contact");
- break;
- case "reward":
- if (username == "zexodiousz" || username == "swazzleman")
- {
- string recipient = message.Split(new string[] { " " }, StringSplitOptions.None)[1];
- //if (recipient == username) break;
- if (recipient[0] == '@')
- {
- recipient = recipient.Split(new[] { '@' }, StringSplitOptions.None)[1];
- }
- string pointstotransferstring = message.Split(new string[] { " " }, StringSplitOptions.None)[2];
- double pointstotransfer = 0;
- bool validnumber = double.TryParse(pointstotransferstring.Split(new[] { ' ' }, StringSplitOptions.None)[0], out pointstotransfer);
- if (!validnumber) break;
- if (pointstotransfer > 0)
- {
- AddPoints(recipient, pointstotransfer);
- irc.sendChatMessage("Points sent!");
- }
- }
- break;
- case "unreward":
- if (username == "zexodiousz" || username == "swazzleman")
- {
- string recipient = message.Split(new string[] { " " }, StringSplitOptions.None)[1];
- //if (recipient == username) break;
- if (recipient[0] == '@')
- {
- recipient = recipient.Split(new[] { '@' }, StringSplitOptions.None)[1];
- }
- string pointstotransferstring = message.Split(new string[] { " " }, StringSplitOptions.None)[2];
- double pointstotransfer = 0;
- bool validnumber = double.TryParse(pointstotransferstring.Split(new[] { ' ' }, StringSplitOptions.None)[0], out pointstotransfer);
- if (!validnumber) break;
- if (pointstotransfer > 0)
- {
- AddPoints(recipient, -pointstotransfer);
- irc.sendChatMessage("Points removed!");
- }
- }
- break;
- case "points":
- string yourpoints = Pointsini.IniReadValue("#zexodiousz." + username, "Points");
- if (yourpoints == "")
- {
- irc.sendChatMessage("Your points are 0, @" + username);
- }
- else
- {
- irc.sendChatMessage("Your points are " + yourpoints + ", @" + username);
- }
- break;
- case "shuffle":
- if (username == "swazzleman" || username == "zexodiousz")
- {
- Scramble();
- irc.sendChatMessage("Unscramble this word to win 10 points. usage: !guess [word] > " + scrambledWord + " <");
- OriginalWord.Text = word;
- ScrambledText.Text = scrambledWord;
- }
- break;
- case "guess":
- string guess = message.Split(new string[] { " " }, StringSplitOptions.None)[1];
- if (guess == word)
- {
- irc.sendChatMessage("Congratulations! You get 10 points!");
- AddPoints(username, 10);
- }
- else
- {
- irc.sendChatMessage("Too bad, try again!");
- }
- break;
- case "fire":
- irc.sendChatMessage("CurseLit CurseLit CurseLit CurseLit CurseLit CurseLit CurseLit ");
- break;
- case "rules":
- irc.sendChatMessage("Rules: Unscramble the word before anyone else. If you guess correctly you get 10 points! You guess by doing !guess [word]. Good luck!");
- break;
- default:
- break;
- case "contact":
- irc.sendChatMessage("You can contact me through snapchat: will_miles11, Twitter: @zexodious, or even on youtube: https://youtube.com/zExodious");
- break;
- case "uptime":
- WebClient client = new WebClient();
- result = client.DownloadString(url);
- if (result != null)
- {
- irc.sendChatMessage(result);
- }
- else
- {
- irc.sendChatMessage("Something went wrong");
- }
- break;
- case "viewers":
- string modnames = "";
- string viewernames = "";
- Viewercount(ref modnames, ref viewernames);
- irc.sendChatMessage("Moderators: " + modnames);
- irc.sendChatMessage("Viewers: " + viewernames);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement