All pastes #1856190 Raw Edit

captain-obvious's whybot IRC Bot

public text v1 · immutable
#1856190 ·published 2010-04-03 23:54 UTC
rendered paste body
/*
 * Created by SharpDevelop.
 * User: Ken
 * Date: 4/3/2010
 * Time: 4:24 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System.Net;
using System.Threading;
using System.Net.Sockets;
using System.IO;
using System;
namespace whybotIRC
{
	public class Program
	{

		public static string SERVER = "irc.swiftirc.net"; // this defines the server you want your bot to connect to
        private static int PORT = 6667; // you can leave this the same
        private static string USER = "USER whybot 8 * whybot"; // replace coolbot with the ident of your bot and coolbot1 with the real name of your bot
        private static string NICK = "whybot"; // nickname of your bot
        private static string CHANNEL = "#xcpq"; // channel you want your bot to join
        public static StreamWriter writer;
        public static StreamReader reader;
        public static string inputline;
        public static bool started;
		public static void Main(string[] args)
        {
            NetworkStream stream; // defines the sockets
            TcpClient irc;
            
            
            try
            {
                irc = new TcpClient(SERVER, PORT);
                stream = irc.GetStream();
                reader = new StreamReader(stream);
                writer = new StreamWriter(stream);
                writer.AutoFlush = true;
//                PingSender ping = new PingSender();
//                ping.Start(); // pinging the server so your bot doesnt ping out
                writer.WriteLine(USER); // sending user information
                writer.WriteLine("NICK " + NICK); // sending your nick
                writer.WriteLine("JOIN " + CHANNEL); // joining your channel
  		//writer.WriteLine("PRIVMSG nickserv :id iartare45g");
                //Console.WriteLine("PRIVMSG nickserv :id atiawerart0");
              
                while (true)
            {
                inputline = reader.ReadLine();
                
                Console.WriteLine("TEST: INPUTLINE = " + inputline);
                Console.WriteLine(inputline);
				if (inputline.Contains("PRIVMSG #xcpq :!test")) // just another command
                {
                	writer.WriteLine("PRIVMSG #xcpq :TEST LOL");
                	Console.WriteLine("PRIVMSG #xcpq :TEST LOL");
                	
                }
				else if (inputline.Contains("PRIVMSG #xcpq :!blah"))
				{
					writer.WriteLine("PRIVMSG #xcpq :SECOND TEST LOL");
					Console.WriteLine("PRIVMSG #xcpq :SECOND TEST LOL");
					
                }

				else if (inputline.StartsWith("PING"))
				{
					writer.WriteLine("PONG :{0}", inputline.Substring(inputline.IndexOf(" :") + 2));
					Console.WriteLine("PONG :{0}", inputline.Substring(inputline.IndexOf(" :") + 2));
				}
               //Commands for the bot
              // writer.WriteLine("PING :" + SERVER);
              // writer.Flush();
              // Thread.Sleep(15000);     
              inputline = null;
         }
               
                       
                    
                } catch (Exception e) {
            Console.WriteLine("EXCEPTION: " + e.ToString());
            //Thread.Sleep(500);
            string[] argv = { };
            Main(argv);
        }
            }
        // error handling
       
	}
}