Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Net.Sockets;
- using System.IO;
- using System.Threading;
- class IrcBot
- {
- // Irc server to connect
- public static string SERVER = "snext.serveirc.com";
- private static int PORT = 6667;
- private static string USER = "USER predsbot 8 * :I'm a C# irc bot";
- private static string NICK = "Licos";
- private static string CHANNEL = "#preds";
- // StreamWriter is declared here so that PingSender can access it
- public static StreamWriter writer;
- static void Main(string[] args)
- {
- NetworkStream stream;
- TcpClient irc;
- string inputLine;
- StreamReader reader;
- try
- {
- irc = new TcpClient(SERVER, PORT);
- stream = irc.GetStream();
- reader = new StreamReader(stream);
- writer = new StreamWriter(stream);
- // Start PingSender thread
- PingSender ping = new PingSender();
- ping.Start();
- writer.WriteLine(USER);
- writer.Flush();
- writer.WriteLine("NICK " + NICK);
- Thread.Sleep(2000);
- writer.Flush();
- writer.WriteLine("JOIN " + CHANNEL);
- writer.Flush();
- while (true)
- {
- while ((inputLine = reader.ReadLine()) != null)
- {
- Console.WriteLine(inputLine);
- if (inputLine.EndsWith("licos about"))
- {
- writer.WriteLine("PRIVMSG " + CHANNEL + " :LicosBot V1.0, Creator preds rule");
- writer.Flush();
- Thread.Sleep(2000);
- }
- if (inputLine.Contains("licos shutdown"))
- {
- string[] splitArray = inputLine.Split(new char[] { ':' });
- string[] splitArray2 = splitArray[1].Split(new char[] { '!' });
- string[] splitArray3 = splitArray2[1].Split(new char[] { ' ' });
- string compmsg = "";
- string nick = splitArray2[0];
- string message = compmsg;
- if (nick.ToLower() == "predsrule")
- writer.WriteLine("PRIVMSG " + CHANNEL + " :Shutting Down...");
- writer.Flush();
- Thread.Sleep(2000);
- Environment.Exit(0);
- }
- if (inputLine.EndsWith("licos"))
- {
- writer.WriteLine("PRIVMSG " + CHANNEL + " :LicosBot Online");
- writer.Flush();
- Thread.Sleep(2000);
- }
- if (inputLine.EndsWith("licos fail"))
- {
- writer.WriteLine("PRIVMSG " + CHANNEL + " :i'm a failure");
- writer.Flush();
- Thread.Sleep(2000);
- }
- if (inputLine.Contains("licos mshutdown"))
- {
- string[] splitArray = inputLine.Split(new char[] { ':' });
- string[] splitArray2 = splitArray[1].Split(new char[] { '!' });
- string[] splitArray3 = splitArray2[1].Split(new char[] { ' ' });
- string compmsg = "";
- string nick = splitArray2[0];
- string message = compmsg;
- if (nick.ToLower() == "predsrule")
- writer.WriteLine("PRIVMSG " + CHANNEL + " :Shutting Down for Maintenance...");
- writer.WriteLine("PRIVMSG " + CHANNEL + " :Back in 5 Minutes");
- writer.Flush();
- Thread.Sleep(2000);
- Environment.Exit(0);
- }
- if (inputLine.EndsWith("licos pray"))
- {
- writer.WriteLine("PRIVMSG " + CHANNEL + " :The Programmers Prayer");
- writer.WriteLine("PRIVMSG " + CHANNEL + " :Our Program who are in Memory.");
- writer.WriteLine("PRIVMSG " + CHANNEL + " :Hello by thy Name.");
- writer.WriteLine("PRIVMSG " + CHANNEL + " :Thy Operating System come.");
- writer.WriteLine("PRIVMSG " + CHANNEL + " :Thy Commands be done at the Printer as it is on the Screen.");
- writer.WriteLine("PRIVMSG " + CHANNEL + " :Give us this day our daily Data,");
- writer.WriteLine("PRIVMSG " + CHANNEL + " :And forgive us our I/O errors");
- writer.WriteLine("PRIVMSG " + CHANNEL + " :As we forgive those whose logic circuits are faulty.");
- writer.WriteLine("PRIVMSG " + CHANNEL + " :Lead us not into frustration, and deliver us from Power Surges.");
- writer.WriteLine("PRIVMSG " + CHANNEL + " :For Thine is the Algorithm,");
- writer.WriteLine("PRIVMSG " + CHANNEL + " :The Application,");
- writer.WriteLine("PRIVMSG " + CHANNEL + " :And the Solution");
- writer.WriteLine("PRIVMSG " + CHANNEL + " :Looping forever and ever.");
- writer.WriteLine("PRIVMSG " + CHANNEL + " :Return");
- writer.Flush();
- Thread.Sleep(2000);
- }
- if (inputLine.Contains("{say} fail"))
- {
- writer.WriteLine("PRIVMSG " + CHANNEL + " :You Fail");
- writer.Flush();
- Thread.Sleep(2000);
- }
- if (inputLine.Contains("Licos ns"))
- {
- writer.WriteLine("PRIVMSG NickServ :identify jamie51822");
- writer.Flush();
- Thread.Sleep(2000);
- }
- }
- // Close all streams
- writer.Close();
- reader.Close();
- irc.Close();
- }
- }
- catch (Exception e)
- {
- // Show the exception, sleep for a while and try to establish a new connection to irc server
- Console.WriteLine(e.ToString());
- Thread.Sleep(5000);
- string[] argv = { };
- Main(argv);
- }
- }
- }
Add Comment
Please, Sign In to add comment