Advertisement
Guest User

Untitled

a guest
Jun 24th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.27 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.  
  19. namespace TwitchBot_2._0
  20. {
  21. public partial class Form1 : Form
  22. {
  23.  
  24. #region Variables
  25.  
  26. private static string userName = BotnameBox.Text.ToLower();
  27. private static string Streamer = ChannelBox.Text.ToLower();
  28. #region hiddenpassword
  29. private static string password = OauthBox.Text.ToLower();
  30. #endregion
  31.  
  32. IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, userName, password);
  33. NetworkStream serverStream = default(NetworkStream);
  34. string readData = "";
  35. Thread chatThread;
  36.  
  37. List<string> BannedWords = new List<string> { "penis", "dick", "fuck"};
  38. List<string> AntiChatSpamBots = new List<string> { "streamer"};
  39. #endregion
  40.  
  41. public Form1()
  42. {
  43. InitializeComponent();
  44. }
  45. private void Form1_Load(object sender, EventArgs e)
  46. {
  47.  
  48. }
  49. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  50. {
  51. irc.leaveRoom();
  52. serverStream.Dispose();
  53. Environment.Exit(0);
  54. }
  55.  
  56. private void getMessage()
  57. {
  58. serverStream = irc.tcpClient.GetStream();
  59. int buffsize = 0;
  60. byte[] instream = new byte[10025];
  61. buffsize = irc.tcpClient.ReceiveBufferSize;
  62. while(true)
  63. {
  64. try
  65. {
  66. readData = irc.readMessage();
  67. msg();
  68. }
  69. catch(Exception e)
  70. {
  71.  
  72. }
  73. }
  74. }
  75.  
  76. private void msg()
  77. {
  78. if (this.InvokeRequired) this.Invoke(new MethodInvoker(msg));
  79. else
  80. {
  81. string[] separator = new string[] { "#trolin720 :" };
  82. string[] singlesep = new string[] { ":","!" };
  83.  
  84. if (readData.Contains("PRIVMSG"))
  85. {
  86. string username = readData.Split(singlesep, StringSplitOptions.None)[1];
  87. string message = readData.Split(separator, StringSplitOptions.None)[1];
  88.  
  89. if (BannedWordFilter(userName, message)) return;
  90. if (AntiSpamBotKiller(userName, message)) return;
  91.  
  92. if (message[0] == '!')
  93. commands(username, message);
  94. chatBox.Text = chatBox.Text + username + ": " + message + Environment.NewLine;
  95. }
  96.  
  97. }
  98. }
  99.  
  100. private void commands(string username, string message)
  101. {
  102. string command = message.Split(new[] { ' ', '!'}, StringSplitOptions.None)[1];
  103.  
  104. switch(command.ToLower())
  105. {
  106. case "bot":
  107. irc.sendChatMessage("This bot was made by Trolin720 and will be able to be downloaded soon...");
  108. break;
  109. case "flabs":
  110. irc.sendChatMessage("Go watch Flabmania and drop him a follow at Twitch.tv/Flabmania");
  111. break;
  112. default:
  113. break;
  114. }
  115. }
  116.  
  117. private void botMsg_TextChanged(object sender, EventArgs e)
  118. {
  119. botMsg.ForeColor = Color.White;
  120. if (botMsg.Text == "Send a Message...")
  121. {
  122. botMsg.ForeColor = Color.Gray;
  123. }
  124. else if (botMsg.Text == "")
  125. {
  126. botMsg.ForeColor = Color.White;
  127. }
  128. else
  129. {
  130. //idk
  131. }
  132.  
  133. }
  134.  
  135. private void botMsg_MouseHover(object sender, EventArgs e)
  136. {
  137. if (botMsg.Text == "Send a Message...")
  138. {
  139. botMsg.Text = "";
  140. }
  141. else
  142. {
  143. botMsg.Text = botMsg.Text;
  144.  
  145. }
  146. botMsg.ForeColor = Color.White;
  147. }
  148.  
  149. private void botMsg_MouseLeave(object sender, EventArgs e)
  150. {
  151. if (botMsg.Text == "")
  152. {
  153. botMsg.Text = "Send a Message...";
  154. }
  155. else
  156. {
  157. botMsg.Text = botMsg.Text;
  158. }
  159. botMsg.ForeColor = Color.Gray;
  160. }
  161.  
  162. private void botSend_Click(object sender, EventArgs e)
  163. {
  164. irc.sendChatMessage(botMsg.Text);
  165. chatBox.Text = chatBox.Text + userName + ": " + botMsg.Text + Environment.NewLine;
  166. if (botMsg.Text == "/clear")
  167. {
  168. MessageBox.Show("Deleteing Chat...");
  169. chatBox.Text = "";
  170. }
  171. }
  172.  
  173. private bool BannedWordFilter(string username, string message)
  174. {
  175. foreach(string word in BannedWords)
  176. {
  177. if (message.Contains(word))
  178. {
  179. string command = "/timeout " + username + " 300";
  180. irc.sendChatMessage(command);
  181. irc.sendChatMessage(username + " that is a Banned Word.");
  182. return true;
  183. }
  184. }
  185. return false;
  186. }
  187.  
  188. private bool AntiSpamBotKiller(string username, string message)
  189. {
  190. foreach (string word in AntiChatSpamBots)
  191. {
  192. if (message.Contains(word))
  193. {
  194. string command = "/timeout " + username + " 600";
  195. irc.sendChatMessage(command);
  196. return true;
  197. }
  198. }
  199. return false;
  200. }
  201.  
  202. private void button1_Click(object sender, EventArgs e)
  203. {
  204. irc.joinRoom(ChannelBox.Text.ToLower());
  205. chatThread = new Thread(getMessage);
  206. chatThread.Start();
  207. }
  208. }
  209.  
  210. class IrcClient
  211. {
  212. private string userName;
  213. private string channel;
  214.  
  215. public TcpClient tcpClient;
  216. private StreamReader inputStream;
  217. private StreamWriter outputStream;
  218.  
  219. public IrcClient(string ip, int port, string userName, string password)
  220. {
  221. tcpClient = new TcpClient(ip, port);
  222. inputStream = new StreamReader(tcpClient.GetStream());
  223. outputStream = new StreamWriter(tcpClient.GetStream());
  224.  
  225. outputStream.WriteLine("PASS " + password);
  226. outputStream.WriteLine("NICK " + userName);
  227. outputStream.WriteLine("USER " + userName + " 8 * :" + userName);
  228. outputStream.WriteLine("CAP REQ :twitch.tv/membership");
  229. outputStream.WriteLine("CAP REQ :twitch.tv/commands");
  230. outputStream.Flush();
  231. }
  232.  
  233. public void joinRoom(string channel)
  234. {
  235. this.channel = channel;
  236. outputStream.WriteLine("JOIN #" + channel);
  237. outputStream.Flush();
  238. }
  239.  
  240. public void leaveRoom()
  241. {
  242. outputStream.Close();
  243. inputStream.Close();
  244. }
  245.  
  246. public void sendIrcMessage(string message)
  247. {
  248. outputStream.WriteLine(message);
  249. outputStream.Flush();
  250. }
  251.  
  252. public void sendChatMessage(string message)
  253. {
  254. sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel + " :" + message);
  255. }
  256.  
  257. public void PingResponse()
  258. {
  259. sendIrcMessage("PONG tmi.twitch.tv\r\n");
  260. }
  261.  
  262. public string readMessage()
  263. {
  264. string message = "";
  265. message = inputStream.ReadLine();
  266. return message;
  267. }
  268. }
  269.  
  270. }
  271.  
  272. RAW Paste Data
  273. using System;
  274. using System.Collections.Generic;
  275. using System.ComponentModel;
  276. using System.Data;
  277. using System.Drawing;
  278. using System.Linq;
  279. using System.Text;
  280. using System.Threading.Tasks;
  281. using System.Windows.Forms;
  282. using System.Net;
  283. using System.Net.Sockets;
  284. using System.IO;
  285. using System.Threading;
  286. using System.Text.RegularExpressions;
  287. using System.Runtime.InteropServices;
  288. using System.Media;
  289. using System.Diagnostics;
  290.  
  291. namespace TwitchBot_2._0
  292. {
  293. public partial class Form1 : Form
  294. {
  295.  
  296. #region Variables
  297.  
  298. private static string userName = BotnameBox.Text.ToLower();
  299. private static string Streamer;
  300. #region hiddenpassword
  301. private static string password;
  302. #endregion
  303.  
  304. IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, userName, password);
  305. NetworkStream serverStream = default(NetworkStream);
  306. string readData = "";
  307. Thread chatThread;
  308.  
  309. List<string> BannedWords = new List<string> { "penis", "dick", "fuck"};
  310. List<string> AntiChatSpamBots = new List<string> { "streamer"};
  311. #endregion
  312.  
  313. public Form1()
  314. {
  315. InitializeComponent();
  316. }
  317. private void Form1_Load(object sender, EventArgs e)
  318. {
  319.  
  320. }
  321. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  322. {
  323. irc.leaveRoom();
  324. serverStream.Dispose();
  325. Environment.Exit(0);
  326. }
  327.  
  328. private void getMessage()
  329. {
  330. serverStream = irc.tcpClient.GetStream();
  331. int buffsize = 0;
  332. byte[] instream = new byte[10025];
  333. buffsize = irc.tcpClient.ReceiveBufferSize;
  334. while(true)
  335. {
  336. try
  337. {
  338. readData = irc.readMessage();
  339. msg();
  340. }
  341. catch(Exception e)
  342. {
  343.  
  344. }
  345. }
  346. }
  347.  
  348. private void msg()
  349. {
  350. if (this.InvokeRequired) this.Invoke(new MethodInvoker(msg));
  351. else
  352. {
  353. string[] separator = new string[] { "#trolin720 :" };
  354. string[] singlesep = new string[] { ":","!" };
  355.  
  356. if (readData.Contains("PRIVMSG"))
  357. {
  358. string username = readData.Split(singlesep, StringSplitOptions.None)[1];
  359. string message = readData.Split(separator, StringSplitOptions.None)[1];
  360.  
  361. if (BannedWordFilter(userName, message)) return;
  362. if (AntiSpamBotKiller(userName, message)) return;
  363.  
  364. if (message[0] == '!')
  365. commands(username, message);
  366. chatBox.Text = chatBox.Text + username + ": " + message + Environment.NewLine;
  367. }
  368.  
  369. }
  370. }
  371.  
  372. private void commands(string username, string message)
  373. {
  374. string command = message.Split(new[] { ' ', '!'}, StringSplitOptions.None)[1];
  375.  
  376. switch(command.ToLower())
  377. {
  378. case "bot":
  379. irc.sendChatMessage("This bot was made by Trolin720 and will be able to be downloaded soon...");
  380. break;
  381. case "flabs":
  382. irc.sendChatMessage("Go watch Flabmania and drop him a follow at Twitch.tv/Flabmania");
  383. break;
  384. default:
  385. break;
  386. }
  387. }
  388.  
  389. private void botMsg_TextChanged(object sender, EventArgs e)
  390. {
  391. botMsg.ForeColor = Color.White;
  392. if (botMsg.Text == "Send a Message...")
  393. {
  394. botMsg.ForeColor = Color.Gray;
  395. }
  396. else if (botMsg.Text == "")
  397. {
  398. botMsg.ForeColor = Color.White;
  399. }
  400. else
  401. {
  402. //idk
  403. }
  404.  
  405. }
  406.  
  407. private void botMsg_MouseHover(object sender, EventArgs e)
  408. {
  409. if (botMsg.Text == "Send a Message...")
  410. {
  411. botMsg.Text = "";
  412. }
  413. else
  414. {
  415. botMsg.Text = botMsg.Text;
  416.  
  417. }
  418. botMsg.ForeColor = Color.White;
  419. }
  420.  
  421. private void botMsg_MouseLeave(object sender, EventArgs e)
  422. {
  423. if (botMsg.Text == "")
  424. {
  425. botMsg.Text = "Send a Message...";
  426. }
  427. else
  428. {
  429. botMsg.Text = botMsg.Text;
  430. }
  431. botMsg.ForeColor = Color.Gray;
  432. }
  433.  
  434. private void botSend_Click(object sender, EventArgs e)
  435. {
  436. irc.sendChatMessage(botMsg.Text);
  437. chatBox.Text = chatBox.Text + userName + ": " + botMsg.Text + Environment.NewLine;
  438. if (botMsg.Text == "/clear")
  439. {
  440. MessageBox.Show("Deleteing Chat...");
  441. chatBox.Text = "";
  442. }
  443. }
  444.  
  445. private bool BannedWordFilter(string username, string message)
  446. {
  447. foreach(string word in BannedWords)
  448. {
  449. if (message.Contains(word))
  450. {
  451. string command = "/timeout " + username + " 300";
  452. irc.sendChatMessage(command);
  453. irc.sendChatMessage(username + " that is a Banned Word.");
  454. return true;
  455. }
  456. }
  457. return false;
  458. }
  459.  
  460. private bool AntiSpamBotKiller(string username, string message)
  461. {
  462. foreach (string word in AntiChatSpamBots)
  463. {
  464. if (message.Contains(word))
  465. {
  466. string command = "/timeout " + username + " 600";
  467. irc.sendChatMessage(command);
  468. return true;
  469. }
  470. }
  471. return false;
  472. }
  473.  
  474. private void button1_Click(object sender, EventArgs e)
  475. {
  476. irc.joinRoom(ChannelBox.Text.ToLower());
  477. chatThread = new Thread(getMessage);
  478. chatThread.Start();
  479. }
  480. }
  481.  
  482. class IrcClient
  483. {
  484. private string userName;
  485. private string channel;
  486.  
  487. public TcpClient tcpClient;
  488. private StreamReader inputStream;
  489. private StreamWriter outputStream;
  490.  
  491. public IrcClient(string ip, int port, string userName, string password)
  492. {
  493. tcpClient = new TcpClient(ip, port);
  494. inputStream = new StreamReader(tcpClient.GetStream());
  495. outputStream = new StreamWriter(tcpClient.GetStream());
  496.  
  497. outputStream.WriteLine("PASS " + password);
  498. outputStream.WriteLine("NICK " + userName);
  499. outputStream.WriteLine("USER " + userName + " 8 * :" + userName);
  500. outputStream.WriteLine("CAP REQ :twitch.tv/membership");
  501. outputStream.WriteLine("CAP REQ :twitch.tv/commands");
  502. outputStream.Flush();
  503. }
  504.  
  505. public void joinRoom(string channel)
  506. {
  507. this.channel = channel;
  508. outputStream.WriteLine("JOIN #" + channel);
  509. outputStream.Flush();
  510. }
  511.  
  512. public void leaveRoom()
  513. {
  514. outputStream.Close();
  515. inputStream.Close();
  516. }
  517.  
  518. public void sendIrcMessage(string message)
  519. {
  520. outputStream.WriteLine(message);
  521. outputStream.Flush();
  522. }
  523.  
  524. public void sendChatMessage(string message)
  525. {
  526. sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel + " :" + message);
  527. }
  528.  
  529. public void PingResponse()
  530. {
  531. sendIrcMessage("PONG tmi.twitch.tv\r\n");
  532. }
  533.  
  534. public string readMessage()
  535. {
  536. string message = "";
  537. message = inputStream.ReadLine();
  538. return message;
  539. }
  540. }
  541. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement