The easy to use and full featured Irc Bot everyone is talking about!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Console_Interface.cs 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using Combot;
  9. using Combot.IRCServices.Messaging;
  10. using Combot.Configurations;
  11. using Combot.IRCServices;
  12. using Combot.IRCServices.Commanding;
  13. namespace Console_Interface
  14. {
  15. public class Console_Interface
  16. {
  17. public static List<Bot> CombotSessions = new List<Bot>();
  18. public static Config Config = new Config();
  19. public static void Main(string[] args)
  20. {
  21. Config.LoadServers();
  22. foreach (ServerConfig server in Config.Servers)
  23. {
  24. Bot Combot = new Bot(server);
  25. Combot.ErrorEvent += e => BotErrorHandler(e, Combot.ServerConfig.Name);
  26. Combot.LogEvent += e => LogEventHandler(e, Combot.ServerConfig.Name);
  27. // Incoming Messages
  28. Combot.IRC.Message.RawMessageEvent += (sender, e) => RawMessageHandler(sender, e, Combot.ServerConfig.Name);
  29. // Outgoing Messages
  30. Combot.IRC.Command.PrivateMessageCommandEvent += (sender, e) => PrivateMessageCommandHandler(sender, e, Combot.ServerConfig.Name);
  31. Combot.IRC.Command.PrivateNoticeCommandEvent += (sender, e) => PrivateNoticeCommandHandler(sender, e, Combot.ServerConfig.Name);
  32. Combot.IRC.ConnectEvent += () => ConnectHandler(Combot.ServerConfig.Name);
  33. Combot.IRC.DisconnectEvent += () => DisconnectHandler(Combot.ServerConfig.Name);
  34. Combot.IRC.TCPErrorEvent += e => TCPErrorHandler(e, Combot.ServerConfig.Name);
  35. CombotSessions.Add(Combot);
  36. if (server.AutoConnect)
  37. {
  38. Combot.Connect();
  39. }
  40. }
  41. bool run = true;
  42. while (run)
  43. {
  44. ConsoleKeyInfo info = Console.ReadKey();
  45. if (info.Key == ConsoleKey.Escape)
  46. {
  47. Console.WriteLine("Exiting...");
  48. run = false;
  49. }
  50. }
  51. }
  52. private static void LogEventHandler(string message, string server)
  53. {
  54. string msg = string.Format("[{0}] [{1}] [LOG] {2}", DateTime.Now.ToString("HH:mm:ss"), server, message);
  55. Console.WriteLine(msg);
  56. }
  57. private static void RawMessageHandler(object sender, string message, string server)
  58. {
  59. string msg = string.Format("[{0}] [{1}] {2}", DateTime.Now.ToString("HH:mm:ss"), server, message);
  60. Console.WriteLine(msg);
  61. }
  62. private static void BotErrorHandler(BotError error, string server)
  63. {
  64. string message = string.Format("[{0}] [{1}] \u0002{2} Error\u0002: {3}", DateTime.Now.ToString("HH:mm:ss"), server, error.Type, error.Message);
  65. Console.WriteLine(message);
  66. }
  67. private static void TCPErrorHandler(Combot.IRCServices.TCP.TCPError error, string server)
  68. {
  69. string message = string.Format("[{0}] [{1}] \u0002TCP Error {2}\u0002: {3}", DateTime.Now.ToString("HH:mm:ss"), server, error.Code, error.Message);
  70. Console.WriteLine(message);
  71. }
  72. private static void PrivateMessageCommandHandler(object sender, PrivateMessageCommand message, string server)
  73. {
  74. string msg = string.Format("[{0}] [{1}] \u0002{2}\u0002: {3}", message.TimeStamp.ToString("HH:mm:ss"), server, " --Combot-- ", message.Message);
  75. Console.WriteLine(msg);
  76. }
  77. private static void PrivateNoticeCommandHandler(object sender, PrivateNoticeCommand message, string server)
  78. {
  79. string msg = string.Format("[{0}] [{1}] \u0002{2}\u0002 -NOTICE-: {3}", message.TimeStamp.ToString("HH:mm:ss"), server, " --Combot-- ", message.Message);
  80. Console.WriteLine(msg);
  81. }
  82. private static void ConnectHandler(string server)
  83. {
  84. Console.WriteLine("-- {0} Connected --", server);
  85. }
  86. private static void DisconnectHandler(string server)
  87. {
  88. Console.WriteLine("-- {0} Disconnected --", server);
  89. }
  90. }
  91. }