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 = "id here";
- private static string userName = "bylimboTest";
- private static string password = "oauth here";
- 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> { "word"/*Banned words here*/};
- //IniFile PointsIni = new IniFile(@"C:\Users\jacob\Documents\visual studio 2017\Projects\TestBot\TestBot\Points.ini");
- #endregion
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- irc.joinRoom("bylimbo_");
- chatThread = new Thread(getMessage);
- chatThread.Start();
- ViewBoxTimer.Start();
- ViewBoxTimer_Tick(null, null);
- }
- 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 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;
- }
- 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())
- {
- case "commisions":
- irc.sendChatMessage("For a quote on a commision, vist my website: http://staticgrasscreations.com/commission.html");
- break;
- case "schedule":
- irc.sendChatMessage("My Schedule is Tuesday, Wednesday & Saturday 7:30PM - 10:30PM PST ");
- break;
- default:
- irc.sendChatMessage("That is not a command");
- break;
- }
- }
- 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 ViewBoxTimer_Tick(object sender, EventArgs e)
- {
- ViewListUpdate();
- }
- private void ViewListUpdate()
- {
- ViewerBox.Items.Clear();
- var dataClient = new TwitchDataClient();
- var chatters = dataClient.GetChannelViewers("byLimbo_");
- chatBox.Text += "Checking the viewer list...";
- foreach (string admin in chatters.Chatters.Admins)
- {
- ViewerBox.Items.Add(admin + Environment.NewLine);
- }
- foreach (string staff in chatters.Chatters.Staff)
- {
- ViewerBox.Items.Add(staff + Environment.NewLine);
- }
- foreach (string globalmod in chatters.Chatters.GlobalMods)
- {
- ViewerBox.Items.Add(globalmod + Environment.NewLine);
- }
- foreach (string moderator in chatters.Chatters.Moderators)
- {
- ViewerBox.Items.Add(moderator + Environment.NewLine);
- }
- foreach (string viewers in chatters.Chatters.Viewers)
- {
- ViewerBox.Items.Add(viewers + Environment.NewLine);
- }
- }
- }
- 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;
- }
- }
- }
- > TestBot.exe!TestBot.Form1.ViewListUpdate() Line 249 C#
- TestBot.exe!TestBot.Form1.ViewBoxTimer_Tick(object sender, System.EventArgs e) Line 239 C#
- TestBot.exe!TestBot.Form1.Form1_Load(object sender, System.EventArgs e) Line 52 C#
- [External Code]
- TestBot.exe!TestBot.Program.Main() Line 19 C#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement