Advertisement
Blizzardo1

20 minute C# Bot dIRC

Oct 26th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.58 KB | None | 0 0
  1. /*
  2.     dIRC - Dummy IRC Bot
  3.     Copyright (c) 2007 - 2013, Blizzardo1 and Blizzeta S&W
  4. */
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Net;
  9. using System.Net.Sockets;
  10. using System.Text;
  11. using System.Threading;
  12.  
  13. namespace dIRC
  14. {
  15.     class Program
  16.     {
  17.         public static StreamWriter writer = null;
  18.         public static StreamReader reader = null;
  19.         public static TcpClient client = null;
  20.  
  21.         public static void Connect(string host, int port)
  22.         {
  23.             client = new TcpClient();
  24.             client.Connect(host, port);
  25.  
  26.             writer = new StreamWriter(client.GetStream());
  27.             reader = new StreamReader(client.GetStream());
  28.            
  29.             Nick("PowerSharp");
  30.             Sleep(25);
  31.             User("Blizzy", "Blizzy");
  32.             Sleep(100);
  33.             Join("#Blizzeta");
  34.             Sleep(50);
  35.             SendMessage("#Blizzeta", "Hi! Blizzy here from a Powershell script with C#! Allow me to idle!");
  36.            
  37.             Listen();
  38.         }
  39.  
  40.         public static void Listen()
  41.         {
  42.             (new Thread(new ThreadStart(delegate
  43.             {
  44.                 while (client.Connected)
  45.                 {
  46.                     string m = string.Empty;
  47.                     while ((m = reader.ReadLine()) != null)
  48.                     {
  49.                         Console.WriteLine(m);
  50.                         Sleep(10);
  51.                     }
  52.                 }
  53.             }))).Start();
  54.         }
  55.  
  56.         public static void Join(string Channel, string Pass = "")
  57.         {
  58.             if (string.IsNullOrEmpty(Pass))
  59.                 writer.WriteLine("JOIN {0}", Channel);
  60.             else
  61.                 writer.WriteLine("JOIN {0} {1}", Channel, Pass);
  62.             writer.Flush();
  63.         }
  64.  
  65.         public static void SendMessage(string channel, string message)
  66.         {
  67.             writer.WriteLine("PRIVMSG {0} :{1}", channel, message);
  68.             writer.Flush();
  69.         }
  70.  
  71.         public static void User(string username, string realname, int usermode = 8)
  72.         {
  73.             writer.WriteLine("USER {0} {1} * :{2}", usermode, usermode, realname);
  74.             writer.Flush();
  75.         }
  76.  
  77.         public static void Sleep(int mil)
  78.         {
  79.             Thread.Sleep(mil);
  80.         }
  81.  
  82.         public static void Nick(string NewNick)
  83.         {
  84.             writer.WriteLine("NICK {0}", NewNick);
  85.             writer.Flush();
  86.         }
  87.  
  88.         public static void Main(string[] args)
  89.         {
  90.             Connect("irc.geekshed.net", 6667);
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement