Advertisement
Guest User

Untitled

a guest
Aug 16th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using ChatSharp;
  7. using System.Runtime.InteropServices;
  8. using System.Windows.Forms;
  9. using System.Drawing;
  10. using System.Data;
  11. using Microsoft.Win32;
  12.  
  13.  
  14.  
  15.  
  16. namespace Tim_s_IRC_bot
  17. {
  18. class Program
  19. {
  20.  
  21.  
  22.  
  23. static void Main(string[] args)
  24. {
  25.  
  26.  
  27. {
  28.  
  29.  
  30.  
  31.  
  32. if (System.IO.File.Exists(System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemDrive"), "/TimsBot/settings.ini")))
  33. {
  34.  
  35.  
  36. }
  37. else
  38. {
  39. Console.WriteLine("Welcome to Tims IRC bot");
  40. Console.ReadLine();
  41. Console.WriteLine("WHich channel do you want the bot to join?");
  42. string Channel = Console.ReadLine();
  43. Console.WriteLine("Which nickname do you want to have?");
  44.  
  45. string Nickname = Console.ReadLine();
  46. Console.WriteLine("Which username do you have?(if none just leave blank)");
  47. string username = Console.ReadLine();
  48. if (username == "") {
  49. username = username.Replace("", "TimsBot");
  50.  
  51.  
  52. }
  53. Console.WriteLine("Which password do you have for the account?(leave blank if none)");
  54. string password = Console.ReadLine();
  55. System.IO.Directory.CreateDirectory("/TimsBot/");
  56. System.IO.File.WriteAllText(System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemDrive"), "/TimsBot/settings.ini"),"Channel= " + Channel + Environment.NewLine + "Botname= " + Nickname + Environment.NewLine + "username= " + username + Environment.NewLine + "password= " + password);
  57. System.IO.File.Copy(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, "/TimsBot/TimsBot.exe");
  58. System.IO.File.Copy(System.IO.Path.Combine(Environment.CurrentDirectory , "ChatSharp.dll"), "/TimsBot/ChatSharp.dll");
  59. System.IO.File.WriteAllText("/TimsBot/tokensystem.txt", "This is the tokenSystem File" + Environment.NewLine);
  60. Console.Clear();
  61.  
  62. Console.WriteLine("Install successfull, start the program.");
  63. Console.ReadLine();
  64. Environment.Exit(0);
  65. }
  66.  
  67. Console.WriteLine("Connecting to Freenode");
  68.  
  69.  
  70. var handle = GetConsoleWindow();
  71.  
  72. ShowWindow(handle, SW_HIDE);
  73.  
  74. string NickName = System.IO.File.ReadAllText("/TimsBot/settings.ini");
  75. string Channel1 = System.IO.File.ReadAllText("/TimsBot/settings.ini");
  76. int index = NickName.IndexOf(System.Environment.NewLine);
  77. NickName = NickName.Substring(index + System.Environment.NewLine.Length).Replace("Botname= ", "");
  78. Channel1 = Channel1.Remove(Channel1.TrimEnd().LastIndexOf(Environment.NewLine)).Replace("Channel= ", "");
  79. var client = new IrcClient("irc.freenode.net", new IrcUser("Tim241", "Tims241", "Twanda01"));
  80. client.ConnectionComplete += (s, e) => client.JoinChannel("##B4A");
  81. Console.Clear();
  82.  
  83.  
  84.  
  85. NotifyIcon trayIcon = new NotifyIcon();
  86. trayIcon.Text = "TimsIRCBot";
  87. trayIcon.Icon = new Icon(SystemIcons.Application, 40, 40);
  88.  
  89. ContextMenu trayMenu = new ContextMenu();
  90.  
  91.  
  92.  
  93.  
  94. trayMenu.MenuItems.Add("exit", new EventHandler(item1_Click));
  95.  
  96. trayIcon.ContextMenu = trayMenu;
  97. trayIcon.Visible = true;
  98.  
  99.  
  100.  
  101.  
  102.  
  103. client.ChannelMessageRecieved += (s, e) =>
  104. {
  105.  
  106. var channel = client.Channels[e.PrivateMessage.Source];
  107.  
  108. if (e.PrivateMessage.Message == "!list")
  109. channel.SendMessage(string.Join(", ", channel.Users.Select(u => u.Nick)));
  110. else if (e.PrivateMessage.Message.StartsWith("!ban "))
  111.  
  112. {
  113.  
  114.  
  115. var target = e.PrivateMessage.Message.Substring(5);
  116. client.WhoIs(target, whois => channel.ChangeMode("+b *!*@" + whois.User.Hostname));
  117. channel.Kick(e.PrivateMessage.Message.Substring(5));
  118. Console.WriteLine(e.PrivateMessage.Message.Substring(5) + " " + "is banned");
  119.  
  120.  
  121.  
  122. }
  123. else if (e.PrivateMessage.Message.StartsWith("!unban "))
  124. {
  125.  
  126. var target = e.PrivateMessage.Message.Substring(7);
  127. client.WhoIs(target, whois => channel.ChangeMode("-b *!*@" + whois.User.Hostname));
  128. Console.WriteLine(e.PrivateMessage.Message.Substring(7) + " " + "is unbanned");
  129.  
  130.  
  131.  
  132. }
  133. else if (e.PrivateMessage.Message == "!leave")
  134. {
  135. channel.Part();
  136. Console.WriteLine("Bot left channel.");
  137. }
  138. else if (e.PrivateMessage.Message.StartsWith("!kick "))
  139. {
  140.  
  141.  
  142. var target = e.PrivateMessage.Message.Substring(7);
  143. channel.Kick(e.PrivateMessage.Message.Substring(6));
  144. Console.WriteLine(e.PrivateMessage.Message.Substring(6) + " " + "is kicked");
  145.  
  146.  
  147.  
  148. }
  149. else if (e.PrivateMessage.Message == "!commands")
  150. {
  151. channel.SendMessage("--- commands list ---");
  152. channel.SendMessage("ban = !ban nick");
  153. channel.SendMessage("kick = !kick nick");
  154. channel.SendMessage("leave = !leave");
  155. channel.SendMessage("say = !say");
  156. channel.SendMessage("join = !join");
  157. Console.WriteLine("!commands requested");
  158. }
  159. else if (e.PrivateMessage.Message.StartsWith("!say "))
  160. {
  161.  
  162. channel.SendMessage(e.PrivateMessage.Message.Substring(5));
  163.  
  164.  
  165.  
  166. }
  167. else if (e.PrivateMessage.Message.StartsWith("!join "))
  168. {
  169.  
  170. client.JoinChannel(e.PrivateMessage.Message.Substring(5));
  171.  
  172.  
  173.  
  174. }
  175. else if (e.PrivateMessage.Message.StartsWith("!give "))
  176. {
  177. string fromvalue = System.IO.File.ReadAllText("/TimsBot/tokensystem/" + e.PrivateMessage.User.Nick);
  178. string tovalue = System.IO.File.ReadAllText("/TimsBot/tokensystem/" + e.PrivateMessage.User.Nick);
  179.  
  180. }
  181. else if (e.PrivateMessage.Message.StartsWith("!tokens"))
  182. {
  183.  
  184. string tokenvalue = System.IO.File.ReadAllText("/TimsBot/tokensystem/" + e.PrivateMessage.User.Nick);
  185. if (System.IO.File.Exists("/TimsBot/tokensystem/" + (e.PrivateMessage.Message.EndsWith())))
  186. {
  187.  
  188. channel.SendMessage(e.PrivateMessage.User.Nick + " You have " + tokenvalue + " Tokens!");
  189. }
  190. else
  191. {
  192. System.IO.File.WriteAllText("/TimsBot/tokensystem/" + e.PrivateMessage.User.Nick, "10000");
  193. string tokenvalue2 = System.IO.File.ReadAllText("/TimsBot/tokensystem/" + e.PrivateMessage.User.Nick);
  194. channel.SendMessage(e.PrivateMessage.User.Nick + " You have " + tokenvalue2 + " Tokens!");
  195. }
  196.  
  197.  
  198.  
  199. }
  200. else if (e.PrivateMessage.Message.StartsWith("!tokens_add"))
  201. {
  202. System.IO.File.AppendAllText("/TimsBot/tokensystem.txt", e.PrivateMessage.User.Nick + " " + (e.PrivateMessage.Message.Substring(12) + Environment.NewLine));
  203. }
  204. client.UserJoinedChannel += (f, g) =>
  205. {
  206. if (System.IO.File.Exists("/TimsBot/tokensystem/" + g.User.Nick))
  207. {
  208.  
  209. }
  210. else {
  211. System.IO.File.WriteAllText("/TimsBot/tokensystem/" + g.User.Nick , "10000");
  212.  
  213. }
  214.  
  215. };
  216.  
  217.  
  218. };
  219.  
  220. client.ConnectAsync();
  221.  
  222. Application.Run();
  223. while (true) ;
  224.  
  225. }
  226.  
  227. }
  228.  
  229.  
  230. public static void HideConsoleWindow()
  231. {
  232. var handle = GetConsoleWindow();
  233.  
  234. ShowWindow(handle, SW_HIDE);
  235. }
  236.  
  237.  
  238. [DllImport("kernel32.dll", SetLastError = true)]
  239. static extern bool AllocConsole();
  240.  
  241. [DllImport("kernel32.dll")]
  242. static extern IntPtr GetConsoleWindow();
  243.  
  244. [DllImport("user32.dll")]
  245. static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  246.  
  247. const int SW_HIDE = 0;
  248. const int SW_SHOW = 5;
  249.  
  250. public static void item1_Click(object sender, EventArgs e )
  251. {
  252.  
  253. Environment.Exit(0);
  254.  
  255. }
  256. }
  257.  
  258.  
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement