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;
- using System.Net.Sockets;
- using System.IO;
- using System.Threading;
- using System.Text.RegularExpressions;
- using System.Runtime.InteropServices;
- using System.Media;
- using System.Diagnostics;
- using TwitchCSharp.Clients;
- using TwitchCSharp.Models;
- namespace TestBot
- {
- public partial class Form1 : Form
- {
- #region Variables
- private static string TwitchClientID = "";
- private static string userName = "";
- private static string password = "";
- TwitchReadOnlyClient APIClient = new TwitchReadOnlyClient(TwitchClientID);
- IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, userName, password);
- NetworkStream serverStream = default(NetworkStream);
- string readData = "";
- Thread chatThread;
- List<string> BannedWords = new List<string> {/*Banned words here in quotes*/};
- bool commandSpamFilter = false;
- #endregion
- #region Form
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- irc.joinRoom("bylimbo_");
- chatThread = new Thread(getMessage);
- chatThread.Start();
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- irc.leaveRoom();
- serverStream.Dispose();
- Environment.Exit(0);
- }
- #endregion
- 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 e)
- {
- }
- }
- }
- private void msg() //This is where everything is dealt with in chat, commands, automatic timeouts, etc.
- {
- if (this.InvokeRequired) this.Invoke(new MethodInvoker(msg));
- else
- {
- string[] separator = new string[] { "#bylimbo_ :" };
- 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 (BannedWordFilters(userName, message)) return;
- if (message[0] == '!') commands(userName, message);
- chatBox.Text = chatBox.Text + userName + " : " + message + Environment.NewLine;
- int num = chatBox.Lines.Count();
- if (chatBox.Lines.Count() > 501)
- {
- var foos = new List<string>(chatBox.Lines);
- foos.RemoveAt(0);
- chatBox.Lines = foos.ToArray();
- }
- }
- if (readData.Contains("PING"))
- {
- irc.PingResponse();
- }
- }
- }
- private void commands(string userName, string message)
- {
- string command = message.Split(new[] { ' ', '!' }, StringSplitOptions.None)[1]; //!command
- switch (command.ToLower())
- {
- #region Schedule
- case "schedule":
- irc.sendChatMessage("My Schedule is Tuesday, Wednesday & Saturday 7:30PM - 10:30PM PST ");
- break;
- #endregion
- #region Dropped
- case "dropped":
- irc.sendChatMessage("PJSalt KAPOW BibleThump BibleThump");
- break;
- #endregion
- #region Hype
- case "hype":
- irc.sendChatMessage("KAPOW CurseLit KAPOW CurseLit KAPOW CurseLit KAPOW CurseLit");
- break;
- #endregion
- #region UpTime
- case "uptime":
- irc.sendChatMessage("");
- break;
- #endregion
- #region Default
- default:
- irc.sendChatMessage("That is not a command");
- break;
- #endregion
- }
- }
- private bool BannedWordFilters(string username, string message)
- {
- foreach (string word in BannedWords)
- {
- if (message.Contains(word))
- {
- string command = "/timeout " + userName + " 10";
- irc.sendChatMessage(command);
- irc.sendChatMessage(userName + " have been timed out for using a banned word.");
- return true;
- }
- }
- return false;
- }
- private void chatBox_TextChanged(object sender, EventArgs e)
- {
- chatBox.SelectionStart = chatBox.Text.Length;
- chatBox.ScrollToCaret();
- }
- private void SendButton_Click(object sender, EventArgs e)
- {
- irc.sendChatMessage(BotChatBot.Text);
- BotChatBot.Clear();
- }
- private void BotChatBot_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == Convert.ToChar(Keys.Return))
- {
- irc.sendChatMessage(BotChatBot.Text);
- BotChatBot.Clear();
- }
- }
- }
- class IrcClient
- {
- private string userName;
- private string channel;
- public TcpClient tcpClient;
- private StreamReader inputStream;
- private StreamWriter outputStream;
- public IrcClient(string ip, int port, string userName, string password)
- {
- tcpClient = new TcpClient(ip, port);
- inputStream = new StreamReader(tcpClient.GetStream());
- outputStream = new StreamWriter(tcpClient.GetStream());
- outputStream.WriteLine("PASS " + password);
- outputStream.WriteLine("NICK " + userName);
- outputStream.WriteLine("USER " + userName + " 8 * :" + userName);
- outputStream.WriteLine("CAP REQ :twitch.tv/membership");
- outputStream.WriteLine("CAP REQ :twitch.tv/commands");
- outputStream.Flush();
- }
- public void joinRoom(string channel)
- {
- this.channel = channel;
- outputStream.WriteLine("JOIN #" + channel);
- outputStream.Flush();
- }
- public void leaveRoom()
- {
- outputStream.Close();
- inputStream.Close();
- }
- public void sendIrcMessage(string message)
- {
- outputStream.WriteLine(message);
- outputStream.Flush();
- }
- public void sendChatMessage(string message)
- {
- sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel + " :" + message);
- }
- public void PingResponse()
- {
- sendIrcMessage("PONG tmi.twitch.tv\r\n");
- }
- public string readMessage()
- {
- string message = "";
- message = inputStream.ReadLine();
- return message;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement