SHARE
TWEET

Untitled

a guest May 22nd, 2017 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Net.Sockets;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using TwitchCSharp.Clients;
  14.  
  15. namespace WindowsFormsApp1
  16. {
  17.     public partial class Form1 : Form
  18.     {
  19.         #region Variables
  20.  
  21.         private static string TwitchClientID = "id here";
  22.         private static string userName = "bylimboTest";
  23.         private static string password = "oauth here";
  24.  
  25.         TwitchReadOnlyClient APIClient = new TwitchReadOnlyClient(TwitchClientID);
  26.  
  27.  
  28.         IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, userName, password);
  29.         NetworkStream serverStream = default(NetworkStream);
  30.         string readData = "";
  31.         Thread chatThread;
  32.  
  33.         List<string> BannedWords = new List<string> {"word" /*Banned words here*/};
  34.         //IniFile PointsIni = new IniFile(@"C:\Users\jacob\Documents\visual studio 2017\Projects\TestBot\TestBot\Points.ini");
  35.  
  36.         #endregion
  37.  
  38.  
  39.         public Form1()
  40.         {
  41.             InitializeComponent();
  42.             ViewListUpdate();
  43.         }
  44.  
  45.         private void Form1_Load(object sender, EventArgs e)
  46.         {
  47.             irc.joinRoom("bylimbo_");
  48.             chatThread = new Thread(getMessage);
  49.             chatThread.Start();
  50.             ViewBoxTimer.Start();
  51.             ViewBoxTimer_Tick(null, null);
  52.         }
  53.  
  54.         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  55.         {
  56.             irc.leaveRoom();
  57.             serverStream.Dispose();
  58.             Environment.Exit(0);
  59.         }
  60.  
  61.         private void getMessage()
  62.         {
  63.             serverStream = irc.tcpClient.GetStream();
  64.             int buffsize = 0;
  65.             byte[] inStream = new byte[10025];
  66.             buffsize = irc.tcpClient.ReceiveBufferSize;
  67.             while (true)
  68.             {
  69.                 try
  70.                 {
  71.                     readData = irc.readMessage();
  72.                     msg();
  73.                 }
  74.                 catch (Exception e)
  75.                 {
  76.                 }
  77.             }
  78.         }
  79.  
  80.         private void msg() //This is where everything is dealt with in chat, commands, automatic timeouts, etc.
  81.         {
  82.             if (this.InvokeRequired) this.Invoke(new MethodInvoker(msg));
  83.             else
  84.             {
  85.                 string[] separator = new string[] {"#bylimbo_ :"};
  86.                 string[] singlesep = new string[] {":", "!"};
  87.  
  88.  
  89.                 if (readData.Contains("PRIVMSG"))
  90.                 {
  91.                     string userName = readData.Split(singlesep, StringSplitOptions.None)[1];
  92.                     string message = readData.Split(separator, StringSplitOptions.None)[1];
  93.  
  94.                     if (BannedWordFilters(userName, message)) return;
  95.  
  96.                     if (message[0] == '!') commands(userName, message);
  97.  
  98.                     chatBox.Text = chatBox.Text + userName + " : " + message + Environment.NewLine;
  99.                 }
  100.  
  101.                 if (readData.Contains("PING"))
  102.                 {
  103.                     irc.PingResponse();
  104.                 }
  105.             }
  106.         }
  107.  
  108.         private void commands(string userName, string message)
  109.         {
  110.             string command = message.Split(new[] {' ', '!'}, StringSplitOptions.None)[1]; //!command
  111.  
  112.             switch (command.ToLower())
  113.             {
  114.                 case "commisions":
  115.                     irc.sendChatMessage(
  116.                         "For a quote on a commision, vist my website: http://staticgrasscreations.com/commission.html");
  117.                     break;
  118.  
  119.  
  120.                 case "schedule":
  121.                     irc.sendChatMessage("My Schedule is Tuesday, Wednesday & Saturday 7:30PM - 10:30PM PST ");
  122.                     break;
  123.                 default:
  124.                     irc.sendChatMessage("That is not a command");
  125.                     break;
  126.             }
  127.         }
  128.  
  129.         private bool BannedWordFilters(string username, string message)
  130.         {
  131.             foreach (string word in BannedWords)
  132.             {
  133.                 if (message.Contains(word))
  134.                 {
  135.                     string command = "/timeout " + userName + " 10";
  136.                     irc.sendChatMessage(command);
  137.                     irc.sendChatMessage(userName + " have been timed out for using a banned word.");
  138.                     return true;
  139.                 }
  140.             }
  141.             return false;
  142.         }
  143.  
  144.         private void ViewBoxTimer_Tick(object sender, EventArgs e)
  145.         {
  146.             ViewListUpdate();
  147.         }
  148.  
  149.         private void ViewListUpdate()
  150.         {
  151.             ViewerBox.Items.Clear();
  152.             var dataClient = new TwitchTmiClient();
  153.             var chatters = dataClient.GetChannelViewers("gosu");
  154.             chatBox.Text += "Checking the viewer list...";
  155.  
  156.             foreach (string admin in chatters.Chatters.Admins)
  157.             {
  158.                 ViewerBox.Items.Add(admin + Environment.NewLine);
  159.             }
  160.  
  161.             foreach (string staff in chatters.Chatters.Staff)
  162.             {
  163.                 ViewerBox.Items.Add(staff + Environment.NewLine);
  164.             }
  165.  
  166.             foreach (string globalmod in chatters.Chatters.GlobalMods)
  167.             {
  168.                 ViewerBox.Items.Add(globalmod + Environment.NewLine);
  169.             }
  170.  
  171.             foreach (string moderator in chatters.Chatters.Moderators)
  172.             {
  173.                 ViewerBox.Items.Add(moderator + Environment.NewLine);
  174.             }
  175.  
  176.             foreach (string viewers in chatters.Chatters.Viewers)
  177.             {
  178.                 ViewerBox.Items.Add(viewers + Environment.NewLine);
  179.             }
  180.         }
  181.     }
  182.  
  183.     class IrcClient
  184.     {
  185.         private string userName;
  186.         private string channel;
  187.  
  188.         public TcpClient tcpClient;
  189.         private StreamReader inputStream;
  190.         private StreamWriter outputStream;
  191.  
  192.         public IrcClient(string ip, int port, string userName, string password)
  193.         {
  194.             tcpClient = new TcpClient(ip, port);
  195.             inputStream = new StreamReader(tcpClient.GetStream());
  196.             outputStream = new StreamWriter(tcpClient.GetStream());
  197.  
  198.             outputStream.WriteLine("PASS " + password);
  199.             outputStream.WriteLine("NICK " + userName);
  200.             outputStream.WriteLine("USER " + userName + " 8 * :" + userName);
  201.             outputStream.WriteLine("CAP REQ :twitch.tv/membership");
  202.             outputStream.WriteLine("CAP REQ :twitch.tv/commands");
  203.             outputStream.Flush();
  204.         }
  205.  
  206.         public void joinRoom(string channel)
  207.         {
  208.             this.channel = channel;
  209.             outputStream.WriteLine("JOIN #" + channel);
  210.             outputStream.Flush();
  211.         }
  212.  
  213.         public void leaveRoom()
  214.         {
  215.             outputStream.Close();
  216.             inputStream.Close();
  217.         }
  218.  
  219.         public void sendIrcMessage(string message)
  220.         {
  221.             outputStream.WriteLine(message);
  222.             outputStream.Flush();
  223.         }
  224.  
  225.         public void sendChatMessage(string message)
  226.         {
  227.             sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel +
  228.                            " :" + message);
  229.         }
  230.  
  231.         public void PingResponse()
  232.         {
  233.             sendIrcMessage("PONG tmi.twitch.tv\r\n");
  234.         }
  235.  
  236.         public string readMessage()
  237.         {
  238.             string message = "";
  239.             message = inputStream.ReadLine();
  240.             return message;
  241.         }
  242.     }
  243. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top