Advertisement
Guest User

Untitled

a guest
Sep 4th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 18.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5. using ChatSharp;
  6. using System.Runtime.InteropServices;
  7. using Microsoft.Win32;
  8.  
  9.  
  10.  
  11.  
  12.  
  13. namespace Tim_s_IRC_bot
  14. {
  15.     class Program
  16.     {
  17.  
  18.  
  19.  
  20.         static void Main(string[] args)
  21.         {
  22.  
  23.  
  24.             {
  25.  
  26.  
  27.                 string combine = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
  28.  
  29.                 if (System.IO.File.Exists(System.IO.Path.Combine(combine,"TimsBot/settings.ini")))
  30.                 {
  31.  
  32.  
  33.                 }
  34.                 else
  35.                 {
  36.                     Console.WriteLine("Welcome to Tims IRC bot, press enter to continue");
  37.                     Console.ReadLine();
  38.                     Console.Clear();
  39.                     Console.WriteLine("Which server do you want the bot to join?");
  40.                     string Server = Console.ReadLine();
  41.                     Console.Clear();
  42.                     Console.WriteLine("Which channel do you want the bot to join?");
  43.                     string Channel = Console.ReadLine();
  44.                     Console.Clear();
  45.                     Console.WriteLine("Which nickname do you want to have?");
  46.  
  47.                     string Nickname = Console.ReadLine();
  48.                     Console.Clear();
  49.                     Console.WriteLine("Which username do you have?(NEEDED!)");
  50.                     string username = Console.ReadLine();
  51.                     Console.Clear();
  52.                     Console.WriteLine("Which password do you have for the account?(NEEDED!)");
  53.                     string password = Console.ReadLine();
  54.                     Console.Clear();
  55.  
  56.  
  57.  
  58.                     System.IO.Directory.CreateDirectory((System.IO.Path.Combine(combine,"TimsBot/")));
  59.                     System.IO.Directory.CreateDirectory((System.IO.Path.Combine(combine,"TimsBot/data")));
  60.                     System.IO.Directory.CreateDirectory((System.IO.Path.Combine(combine,"TimsBot/data/logs/")));
  61.                     System.IO.Directory.CreateDirectory((System.IO.Path.Combine(combine,"TimsBot/data/systems/warnsystem/warning/")));
  62.                     System.IO.Directory.CreateDirectory((System.IO.Path.Combine(combine,"TimsBot/data/systems/warnsystem/offtopic/")));
  63.                     System.IO.Directory.CreateDirectory((System.IO.Path.Combine(combine,"TimsBot/data/access/")));
  64.                     System.IO.Directory.CreateDirectory((System.IO.Path.Combine(combine,"TimsBot/data/access/commands/")));
  65.                     System.IO.Directory.CreateDirectory((System.IO.Path.Combine(combine,"TimsBot/data/access/commands/users/")));
  66.                     System.IO.File.WriteAllText((System.IO.Path.Combine(combine,"TimsBot/settings.ini")),"Server="+ Server + Environment.NewLine + "Channel=" + Channel + Environment.NewLine + "Botname=" + Nickname + Environment.NewLine + "username=" + username + Environment.NewLine + "password=" + password);
  67.                     System.IO.File.Copy(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, (System.IO.Path.Combine(combine,"TimsBot/TimsBot.exe")));
  68.                     System.IO.File.WriteAllText((System.IO.Path.Combine(combine,"TimsBot/data/logs/log.txt")), "This is the log File" + Environment.NewLine);
  69.  
  70.                     Console.Clear();
  71.                     Console.WriteLine("You can open the ControlPanel by right clicking on the new system tray icon, when you run the program.");
  72.                     Console.ReadLine();
  73.  
  74.                     Console.WriteLine("Install successfull, you can open the program by going to the desktop and click on the shortcut or navigate to TimsBot/ and run TimsBot.exe.");
  75.                     Console.ReadLine();
  76.                     Environment.Exit(0);
  77.                 }
  78.  
  79.  
  80.  
  81.                 try
  82.                 {
  83.  
  84.  
  85.  
  86.                 string readvalue = System.IO.File.ReadAllText((System.IO.Path.Combine(combine,"TimsBot/settings.ini")));
  87.  
  88.                 string modify1 = readvalue.Replace("Server=","").Replace("Channel=", "").Replace("Botname=", "").Replace("username=", "").Replace("password=", "");
  89.  
  90.                 string[] splitvalue = modify1.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
  91.  
  92.  
  93.                 Console.ForegroundColor = ConsoleColor.DarkGreen;
  94.                 Console.Clear();
  95.                 Console.WriteLine("Connecting to the server.");
  96.                 var client = new IrcClient(splitvalue[0], new IrcUser(splitvalue[2], splitvalue[3], splitvalue[4]));
  97.                 client.ConnectionComplete += (s, e) =>
  98.                 {
  99.                     Console.ForegroundColor = ConsoleColor.DarkGreen;
  100.                     Console.WriteLine("Connected to the server.");
  101.                     client.JoinChannel(splitvalue[1]);
  102.                     Console.Title = "Connected";
  103.                     Console.WriteLine("Joining channel.");
  104.                     Console.ResetColor();
  105.  
  106.                 };
  107.                 Console.ResetColor();
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.                 client.ChannelMessageRecieved += (s, e) =>
  118.                 {
  119.  
  120.                     var channel = client.Channels[e.PrivateMessage.Source];
  121.  
  122.                     if (e.PrivateMessage.Message == "!list")
  123.                         channel.SendMessage(string.Join(", ", channel.Users.Select(u => u.Nick)));
  124.                     else if (e.PrivateMessage.Message.StartsWith("!ban "))
  125.  
  126.                     {
  127.                         if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick))
  128.                         {
  129.                             var target = e.PrivateMessage.Message.Substring(5);
  130.                             client.WhoIs(target, whois => channel.ChangeMode("+b *!*@" + whois.User.Hostname));
  131.                             channel.Kick(e.PrivateMessage.Message.Substring(5));
  132.                             client.SendMessage("You got banned from " + splitvalue[1], e.PrivateMessage.Message.Substring(5));
  133.                             Console.ForegroundColor = ConsoleColor.DarkYellow;
  134.                             Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]");
  135.                             Console.ResetColor();
  136.                             Console.ForegroundColor = ConsoleColor.Red;
  137.                             Console.Write(e.PrivateMessage.Message.Substring(5) + " is banned in " + splitvalue[1] + " by ");
  138.                             Console.ResetColor();
  139.                             Console.ForegroundColor = ConsoleColor.Blue;
  140.                             Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine);
  141.                             channel.Kick(e.PrivateMessage.Message.Substring(5));
  142.                         }
  143.  
  144.  
  145.  
  146.                     }
  147.                     else if (e.PrivateMessage.Message.StartsWith("!unban "))
  148.                     {
  149.  
  150.                         if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick))
  151.                         {
  152.  
  153.                             var target = e.PrivateMessage.Message.Substring(7);
  154.                             client.WhoIs(target, whois => channel.ChangeMode("-b *!*@" + whois.User.Hostname));
  155.                             Console.WriteLine(e.PrivateMessage.Message.Substring(7) + " " + "is unbanned");
  156.                             client.SendMessage("You got unbanned from " + splitvalue[1], e.PrivateMessage.Message.Substring(7));
  157.                             Console.ForegroundColor = ConsoleColor.DarkYellow;
  158.                             Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]");
  159.                             Console.ResetColor();
  160.                             Console.ForegroundColor = ConsoleColor.Red;
  161.                             Console.Write(e.PrivateMessage.Message.Substring(7) + " is unbanned in " + splitvalue[1] + " by ");
  162.                             Console.ResetColor();
  163.                             Console.ForegroundColor = ConsoleColor.Blue;
  164.                             Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine);
  165.  
  166.                         }
  167.  
  168.                     }
  169.                     else if (e.PrivateMessage.Message == "!leave")
  170.                     {
  171.                         if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick))
  172.                         {
  173.                             channel.Part();
  174.                             Console.ForegroundColor = ConsoleColor.DarkYellow;
  175.                             Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]");
  176.                             Console.ResetColor();
  177.                             Console.ForegroundColor = ConsoleColor.Red;
  178.                             Console.Write("!leave requested by ");
  179.                             Console.ResetColor();
  180.                             Console.ForegroundColor = ConsoleColor.Blue;
  181.                             Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine);
  182.                         }
  183.                     }
  184.                     else if (e.PrivateMessage.Message == "!cycle")
  185.                     {
  186.                         if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick))
  187.                         {
  188.                             channel.Part();
  189.                             client.JoinChannel(splitvalue[1]);
  190.                             Console.ForegroundColor = ConsoleColor.DarkYellow;
  191.                             Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]");
  192.                             Console.ResetColor();
  193.                             Console.ForegroundColor = ConsoleColor.Red;
  194.                             Console.Write("!cycle requested by ");
  195.                             Console.ResetColor();
  196.                             Console.ForegroundColor = ConsoleColor.Blue;
  197.                             Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine);
  198.  
  199.                         }
  200.                     }
  201.                     else if (e.PrivateMessage.Message.StartsWith("!kick "))
  202.                     {
  203.                         if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick))
  204.                         {
  205.  
  206.  
  207.                             channel.Kick(e.PrivateMessage.Message.Substring(6));
  208.                             client.SendMessage("You got kicked from " + splitvalue[1] ,e.PrivateMessage.Message.Substring(6));
  209.                             Console.ForegroundColor = ConsoleColor.DarkYellow;
  210.                             Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]");
  211.                             Console.ResetColor();
  212.                             Console.ForegroundColor = ConsoleColor.Red;
  213.                             Console.Write(e.PrivateMessage.Message.Substring(6) + " is kicked from " +  splitvalue[1] +  " by " );
  214.                             Console.ResetColor();
  215.                             Console.ForegroundColor = ConsoleColor.Blue;
  216.                             Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine);
  217.                         }
  218.  
  219.  
  220.                     }
  221.                     else if (e.PrivateMessage.Message == "!commands")
  222.                     {
  223.                         if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick))
  224.                         {
  225.                            
  226.                             channel.SendMessage(e.PrivateMessage.User.Nick +", Commands: !ban, !unban, !kick, !join, !warn, !warn_offtopic, !op, !deop" );
  227.                             Console.ForegroundColor = ConsoleColor.DarkYellow;
  228.                             Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]");
  229.                             Console.ResetColor();
  230.                             Console.ForegroundColor = ConsoleColor.Red;
  231.                             Console.Write("!commands requested by " );
  232.                             Console.ResetColor();
  233.                             Console.ForegroundColor = ConsoleColor.Blue;
  234.                             Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine);
  235.                         }
  236.  
  237.  
  238.  
  239.  
  240.                     }
  241.                     else if (e.PrivateMessage.Message.StartsWith("!say "))
  242.                     {
  243.                         if (System.IO.File.Exists((System.IO.Path.Combine(combine,"TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick))
  244.                         {
  245.                             string[] splitvalue2 = e.PrivateMessage.Message.Split(' ');
  246.  
  247.                             client.SendMessage(splitvalue2[1], splitvalue[1] );
  248.                             Console.ForegroundColor = ConsoleColor.DarkYellow;
  249.                             Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]");
  250.                             Console.ResetColor();
  251.                             Console.ForegroundColor = ConsoleColor.Red;
  252.                             Console.Write("!say requested by " );
  253.                             Console.ResetColor();
  254.                             Console.ForegroundColor = ConsoleColor.Blue;
  255.                             Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine);
  256.                         }
  257.  
  258.  
  259.                     }
  260.  
  261.                     else if (e.PrivateMessage.Message.StartsWith("!join "))
  262.                     {
  263.                         if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick))
  264.                         {
  265.                             client.JoinChannel(e.PrivateMessage.Message.Substring(5));
  266.                             Console.ForegroundColor = ConsoleColor.DarkYellow;
  267.                             Console.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "]");
  268.                             Console.ResetColor();
  269.                             Console.ForegroundColor = ConsoleColor.Red;
  270.                             Console.Write("Bot joined" + e.PrivateMessage.Message.Substring(5) + " by" );
  271.                             Console.ResetColor();
  272.                             Console.ForegroundColor = ConsoleColor.Blue;
  273.                             Console.Write(e.PrivateMessage.User.Nick + Environment.NewLine);
  274.                         }
  275.  
  276.  
  277.                     }
  278.                     else if (e.PrivateMessage.Message.StartsWith("!warn_offtopic "))
  279.                     {
  280.                         if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick))
  281.                         {
  282.                             if (System.IO.Directory.Exists((System.IO.Path.Combine(combine, "TimsBot/data/systems/warnsystem/offtopic/")) + e.PrivateMessage.Message.Substring(15)))
  283.                             {
  284.                                 if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/systems/warnsystem/offtopic/")) + e.PrivateMessage.Message.Substring(15) + "/" + "4"))
  285.                                 {
  286.                                     var target = e.PrivateMessage.Message.Substring(15);
  287.                                     client.WhoIs(target, whois => channel.ChangeMode("+b *!*@" + whois.User.Hostname));
  288.  
  289.                                     Console.WriteLine(e.PrivateMessage.Message.Substring(15) + " " + "is banned");
  290.                                     client.SendMessage("You got banned from " + splitvalue[1] + " because you keep going off topic", e.PrivateMessage.Message.Substring(15));
  291.                                     channel.Kick(e.PrivateMessage.Message.Substring(15));
  292.                                 }
  293.                                 else
  294.                                 {
  295.                                     if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/systems/warnsystem/offtopic/")) + e.PrivateMessage.Message.Substring(15) + "/" + "3"))
  296.                                     {
  297.                                         System.IO.File.WriteAllText((System.IO.Path.Combine(combine, "TimsBot/data/systems/warnsystem/offtopic/")) + e.PrivateMessage.Message.Substring(15) + "/" + "4", "Warning number 4");
  298.                                         channel.Kick(e.PrivateMessage.Message.Substring(15));
  299.                                         Console.WriteLine(e.PrivateMessage.Message.Substring(15) + " " + "is kicked");
  300.                                         client.SendMessage("You got kicked from " + splitvalue[1] + " because you keep going off topic", e.PrivateMessage.Message.Substring(6));
  301.  
  302.                                     }
  303.                                     else
  304.                                     {
  305.                                         if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/systems/warnsystem/offtopic/")) + e.PrivateMessage.Message.Substring(15) + "/" + "2"))
  306.                                         {
  307.                                             System.IO.File.WriteAllText((System.IO.Path.Combine(combine, "TimsBot/data/systems/warnsystem/offtopic/")) + e.PrivateMessage.Message.Substring(15) + "/" + "3", "Warning number 3");
  308.                                             client.SendMessage("This is your last warning, please stop being off topic, you will be kicked if you go on in " + splitvalue[1], e.PrivateMessage.Message.Substring(15));
  309.                                         }
  310.                                         else
  311.                                         {
  312.                                             System.IO.File.WriteAllText((System.IO.Path.Combine(combine, "TimsBot/data/systems/warnsystem/offtopic/")) + e.PrivateMessage.Message.Substring(15) + "/" + "2", "Warning number 2");
  313.                                             client.SendMessage("Please remember, this is a chat for chat with related topics in " + splitvalue[1], e.PrivateMessage.Message.Substring(15));
  314.                                         }
  315.                                     }
  316.                                 }
  317.                             }
  318.                             else
  319.                             {
  320.                                 System.IO.Directory.CreateDirectory((System.IO.Path.Combine(combine, "TimsBot/data/systems/warnsystem/offtopic/")) + e.PrivateMessage.Message.Substring(15));
  321.                                 client.SendMessage("Please try and stay on topic in " + splitvalue[1], e.PrivateMessage.Message.Substring(15));
  322.                             }
  323.  
  324.                         }
  325.  
  326.                         else
  327.  
  328.                         {
  329.  
  330.                         }
  331.  
  332.  
  333.  
  334.                     }
  335.                     else if (e.PrivateMessage.Message.StartsWith("!warn "))
  336.                     {
  337.                         if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick))
  338.                         {
  339.                             if (System.IO.Directory.Exists((System.IO.Path.Combine(combine, "TimsBot/data/systems/warnsystem/warning/")) + e.PrivateMessage.Message.Substring(6)))
  340.                             {
  341.                                 if (System.IO.File.Exists((System.IO.Path.Combine(combine,"TimsBot/data/systems/warnsystem/warning/")) + e.PrivateMessage.Message.Substring(6) + "/" + "4"))
  342.                                 {
  343.                                     var target = e.PrivateMessage.Message.Substring(6);
  344.                                     client.WhoIs(target, whois => channel.ChangeMode("+b *!*@" + whois.User.Hostname));
  345.  
  346.                                     Console.WriteLine(e.PrivateMessage.Message.Substring(6) + " " + "is banned");
  347.                                     client.SendMessage("You got banned from " + splitvalue[1] + " because you have 5 warnings", e.PrivateMessage.Message.Substring(6));
  348.                                     channel.Kick(e.PrivateMessage.Message.Substring(6));
  349.                                 }
  350.                                 else
  351.                                 {
  352.                                     if (System.IO.File.Exists((System.IO.Path.Combine(combine,"TimsBot/data/systems/warnsystem/warning/")) + e.PrivateMessage.Message.Substring(6) + "/" + "3"))
  353.                                     {
  354.                                         System.IO.File.WriteAllText((System.IO.Path.Combine(combine,"TimsBot/data/systems/warnsystem/warning/")) + e.PrivateMessage.Message.Substring(6) + "/" + "4", "Warning number 4");
  355.                                         channel.Kick(e.PrivateMessage.Message.Substring(6));
  356.                                         Console.WriteLine(e.PrivateMessage.Message.Substring(6) + " " + "is kicked");
  357.                                         client.SendMessage("You got kicked from " + splitvalue[1] + " because you have 4 warnings, if you get one more warning you will get banned.", e.PrivateMessage.Message.Substring(6));
  358.  
  359.                                     }
  360.                                     else
  361.                                     {
  362.                                         if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/systems/warnsystem/warning/")) + e.PrivateMessage.Message.Substring(6) + "/" + "2"))
  363.                                         {
  364.                                             System.IO.File.WriteAllText((System.IO.Path.Combine(combine, "TimsBot/data/systems/warnsystem/warning/")) + e.PrivateMessage.Message.Substring(6) + "/" + "3", "Warning number 3");
  365.                                             client.SendMessage("Please remember, this is your 3th warning in in " + splitvalue[1], e.PrivateMessage.Message.Substring(6));
  366.                                         }
  367.                                         else
  368.                                         {
  369.                                             System.IO.File.WriteAllText((System.IO.Path.Combine(combine, "TimsBot/data/systems/warnsystem/warning/")) + e.PrivateMessage.Message.Substring(6) + "/" + "2", "Warning number 2");
  370.                                             client.SendMessage("Please remember, this is your second warning in " + splitvalue[1], e.PrivateMessage.Message.Substring(6));
  371.                                         }
  372.                                     }
  373.                                 }
  374.                             }
  375.                             else
  376.                             {
  377.                                 System.IO.Directory.CreateDirectory((System.IO.Path.Combine(combine, "TimsBot/data/systems/warnsystem/warning/")) + e.PrivateMessage.Message.Substring(6));
  378.                                 client.SendMessage("Please remember, this is your first warning in " + splitvalue[1], e.PrivateMessage.Message.Substring(6));
  379.                             }
  380.  
  381.                         }
  382.                     }
  383.  
  384.  
  385.  
  386.  
  387.                     else if (e.PrivateMessage.Message == "!op")
  388.                     {
  389.                         if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick))
  390.                         {
  391.                             var target = e.PrivateMessage.User.Nick;
  392.                             client.WhoIs(target, whois => channel.ChangeMode("+o  "+ e.PrivateMessage.User.Nick));
  393.                         }
  394.                     }
  395.                     else if (e.PrivateMessage.Message == "!deop")
  396.                     {
  397.                         if (System.IO.File.Exists((System.IO.Path.Combine(combine, "TimsBot/data/access/commands/users/")) + e.PrivateMessage.User.Nick))
  398.                         {
  399.                             var target = e.PrivateMessage.User.Nick;
  400.                             client.WhoIs(target, whois => channel.ChangeMode("-o " + e.PrivateMessage.User.Nick));
  401.                         }
  402.                     }
  403.  
  404.  
  405.  
  406.  
  407.                 };
  408.  
  409.                 client.ConnectAsync();
  410.  
  411.  
  412.                 while (true) ;
  413.  
  414.             }
  415.                 catch (Exception e)
  416.                 {
  417.                     Console.ForegroundColor = ConsoleColor.Red;
  418.                     Console.WriteLine("[" + DateTime.Now.ToString("HH:mm:ss") + "] Error: '{0}'", e);
  419.                     Console.ReadLine ();
  420.        
  421.                 }
  422.         }
  423.         }
  424.  
  425.  
  426.  
  427.  
  428.  
  429.         [DllImport("kernel32.dll", SetLastError = true)]
  430.         static extern bool AllocConsole();
  431.  
  432.         [DllImport("kernel32.dll")]
  433.         static extern IntPtr GetConsoleWindow();
  434.  
  435.         [DllImport("user32.dll")]
  436.         static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  437.  
  438.         const int SW_HIDE = 0;
  439.         const int SW_SHOW = 5;
  440.  
  441.  
  442.     }
  443.  
  444.  
  445. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement