Guest User

Untitled

a guest
Jan 24th, 2014
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.23 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 IrcDotNet;
  11.  
  12. namespace icc_twitch_bot
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         public IrcRegistrationInfo  irc_iri
  22.         {
  23.             get
  24.             {
  25.                 return new IrcUserRegistrationInfo()
  26.                 {
  27.                     NickName = "jsBot",
  28.                     UserName = "jsBot",
  29.                     RealName = "jsBot",
  30.                     Password = "oauth:94xo4jf562po2aafb94wklg0nhpm75f"
  31.                 };
  32.             }
  33.         }
  34.  
  35.         public IrcClient gIrcClient = new IrcClient();
  36.  
  37.         private void button1_Click(object sender, EventArgs e)
  38.         {
  39.             button1.Enabled = false;
  40.  
  41.             if (!gIrcClient.IsConnected)
  42.             {
  43.                 button1.Text = "Connecting...";
  44.                 gIrcClient.Connect("irc.twitch.tv", 6667, false, irc_iri);
  45.             }
  46.             else
  47.             {
  48.                 button1.Text = "Disconnecting...";
  49.                 gIrcClient.Quit(5000, "bye");
  50.             }
  51.         }
  52.  
  53.         void ircClient_Connected(object sender, EventArgs e)
  54.         {
  55.             try
  56.             {
  57.                 if (button1.InvokeRequired)
  58.                 {
  59.                     MethodInvoker del = delegate {
  60.                         button1.Text = "Disconnect";
  61.                         button1.Enabled = true; };
  62.                     button1.Invoke(del);
  63.                 }
  64.                 else
  65.                 {
  66.                     button1.Text = "Disconnect";
  67.                     button1.Enabled = true;
  68.                 }
  69.                 gIrcClient.Channels.Join("#lgt_justice");                
  70.             }
  71.             catch (Exception ex) { MessageBox.Show(ex.Message); }
  72.         }
  73.  
  74.         void gIrcClient_Disconnected(object sender, EventArgs e)
  75.         {
  76.             if (!gIrcClient.IsConnected)
  77.             {
  78.                 try
  79.                 {
  80.                     if (button1.InvokeRequired)
  81.                     {
  82.                         MethodInvoker del = delegate
  83.                         {
  84.                             button1.Text = "Connect";
  85.                             button1.Enabled = true;
  86.                         };
  87.                         button1.Invoke(del);
  88.                     }
  89.                     else
  90.                     {
  91.                         button1.Text = "Connect";
  92.                         button1.Enabled = true;
  93.                     }
  94.                 }
  95.                 catch (Exception ex) { MessageBox.Show(ex.Message); }
  96.             }
  97.             else gIrcClient.Disconnect();
  98.         }
  99.  
  100.         void LocalUser_JoinedChannel(object sender, IrcChannelEventArgs e)
  101.         {
  102.             try
  103.             {                
  104.                 gIrcClient.Channels[0].MessageReceived += Form1_MessageReceived;
  105.                 gIrcClient.LocalUser.SendMessage(e.Channel, "yolo!");
  106.                 MessageBox.Show(gIrcClient.Channels[0].Users[0].User.NickName);
  107.                 MessageBox.Show("lol");
  108.             }
  109.             catch (Exception ex) { MessageBox.Show(ex.Message); }
  110.         }
  111.  
  112.         void Form1_MessageReceived(object sender, IrcMessageEventArgs e)
  113.         {
  114.             try
  115.             {
  116.                 if (e.Text.Equals("asd"))
  117.                     gIrcClient.LocalUser.SendMessage(e.Targets, "received");
  118.             }
  119.             catch (Exception ex) { MessageBox.Show(ex.Message); }
  120.         }
  121.  
  122.         private void Form1_FormClosed(object sender, FormClosedEventArgs e)
  123.         {
  124.             if (gIrcClient.IsConnected)
  125.                 gIrcClient.Disconnect();
  126.         }
  127.  
  128.         private void Form1_Load(object sender, EventArgs e)
  129.         {
  130.             gIrcClient.Connected += ircClient_Connected;
  131.             gIrcClient.Disconnected += gIrcClient_Disconnected;
  132.             gIrcClient.LocalUser.JoinedChannel += LocalUser_JoinedChannel;
  133.             gIrcClient.FloodPreventer = new IrcStandardFloodPreventer(1, 10000);        
  134.         }
  135.  
  136.    
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment