Advertisement
Guest User

Whole code

a guest
May 22nd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Net;
  11. using System.Net.Sockets;
  12. using System.IO;
  13. using System.Threading;
  14. using System.Text.RegularExpressions;
  15. using System.Runtime.InteropServices;
  16. using System.Media;
  17. using System.Diagnostics;
  18. using TwitchCSharp.Clients;
  19. using TwitchCSharp.Models;
  20.  
  21. namespace TestBot
  22. {
  23.     public partial class Form1 : Form
  24.     {
  25.         #region Variables
  26.         private static string TwitchClientID = "id here";
  27.         private static string userName = "bylimboTest";
  28.         private static string password = "oauth here";
  29.  
  30.         TwitchReadOnlyClient APIClient = new TwitchReadOnlyClient(TwitchClientID);
  31.        
  32.  
  33.         IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, userName, password);
  34.         NetworkStream serverStream = default(NetworkStream);
  35.         string readData = "";
  36.         Thread chatThread;
  37.         List<string> BannedWords = new List<string> { "word"/*Banned words here*/};
  38.         //IniFile PointsIni = new IniFile(@"C:\Users\jacob\Documents\visual studio 2017\Projects\TestBot\TestBot\Points.ini");
  39.         #endregion
  40.            
  41.            
  42.         public Form1()
  43.         {
  44.             InitializeComponent();
  45.         }
  46.         private void Form1_Load(object sender, EventArgs e)
  47.         {
  48.             irc.joinRoom("bylimbo_");
  49.             chatThread = new Thread(getMessage);
  50.             chatThread.Start();
  51.             ViewBoxTimer.Start();
  52.             ViewBoxTimer_Tick(null, null);
  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.  
  81.         private void msg() //This is where everything is dealt with in chat, commands, automatic timeouts, etc.
  82.         {
  83.             if (this.InvokeRequired) this.Invoke(new MethodInvoker(msg));
  84.             else
  85.             {
  86.                 string[] separator = new string[] { "#bylimbo_ :" };
  87.                 string[] singlesep = new string[] { ":", "!" };
  88.  
  89.  
  90.                 if (readData.Contains("PRIVMSG"))
  91.                 {
  92.                     string userName = readData.Split(singlesep, StringSplitOptions.None)[1];
  93.                     string message = readData.Split(separator, StringSplitOptions.None)[1];
  94.  
  95.                     if (BannedWordFilters(userName, message)) return;
  96.  
  97.                     if (message[0] == '!') commands(userName, message);
  98.  
  99.                     chatBox.Text = chatBox.Text + userName + " : " + message + Environment.NewLine;
  100.                 }
  101.  
  102.                 if (readData.Contains("PING"))
  103.                 {
  104.                     irc.PingResponse();
  105.                 }
  106.             }
  107.         }
  108.  
  109.         private void commands(string userName, string message)
  110.         {
  111.             string command = message.Split(new[] { ' ', '!' }, StringSplitOptions.None)[1]; //!command
  112.  
  113.             switch (command.ToLower())
  114.             {
  115.                 case "commisions":
  116.                     irc.sendChatMessage("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 TwitchDataClient();
  153.             var chatters = dataClient.GetChannelViewers("byLimbo_");
  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.         class IrcClient
  183.         {
  184.             private string userName;
  185.             private string channel;
  186.  
  187.             public TcpClient tcpClient;
  188.             private StreamReader inputStream;
  189.             private StreamWriter outputStream;
  190.  
  191.             public IrcClient(string ip, int port, string userName, string password)
  192.             {
  193.                 tcpClient = new TcpClient(ip, port);
  194.                 inputStream = new StreamReader(tcpClient.GetStream());
  195.                 outputStream = new StreamWriter(tcpClient.GetStream());
  196.  
  197.                 outputStream.WriteLine("PASS " + password);
  198.                 outputStream.WriteLine("NICK " + userName);
  199.                 outputStream.WriteLine("USER " + userName + " 8 * :" + userName);
  200.                 outputStream.WriteLine("CAP REQ :twitch.tv/membership");
  201.                 outputStream.WriteLine("CAP REQ :twitch.tv/commands");
  202.                 outputStream.Flush();
  203.             }
  204.  
  205.             public void joinRoom(string channel)
  206.             {
  207.                 this.channel = channel;
  208.                 outputStream.WriteLine("JOIN #" + channel);
  209.                 outputStream.Flush();
  210.             }
  211.  
  212.             public void leaveRoom()
  213.             {
  214.                 outputStream.Close();
  215.                 inputStream.Close();
  216.             }
  217.  
  218.             public void sendIrcMessage(string message)
  219.             {
  220.                 outputStream.WriteLine(message);
  221.                 outputStream.Flush();
  222.             }
  223.  
  224.             public void sendChatMessage(string message)
  225.             {
  226.                 sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel + " :" + message);
  227.             }
  228.  
  229.             public void PingResponse()
  230.             {
  231.                 sendIrcMessage("PONG tmi.twitch.tv\r\n");
  232.             }
  233.  
  234.             public string readMessage()
  235.             {
  236.                 string message = "";
  237.                 message = inputStream.ReadLine();
  238.                 return message;
  239.             }
  240.         }
  241.     }
  242.  
  243.  
  244.  
  245. >   TestBot.exe!TestBot.Form1.ViewListUpdate() Line 249 C#
  246.     TestBot.exe!TestBot.Form1.ViewBoxTimer_Tick(object sender, System.EventArgs e) Line 239 C#
  247.     TestBot.exe!TestBot.Form1.Form1_Load(object sender, System.EventArgs e) Line 52 C#
  248.     [External Code]
  249.     TestBot.exe!TestBot.Program.Main() Line 19  C#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement