The easy to use and full featured Irc Bot everyone is talking about!
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Console_Interface.cs 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. // Incoming Messages
  27. Combot.IRC.Message.RawMessageEvent += (sender, e) => RawMessageHandler(sender, e, Combot.ServerConfig.Name);
  28. // Outgoing Messages
  29. Combot.IRC.Command.PrivateMessageCommandEvent += (sender, e) => PrivateMessageCommandHandler(sender, e, Combot.ServerConfig.Name);
  30. Combot.IRC.Command.PrivateNoticeCommandEvent += (sender, e) => PrivateNoticeCommandHandler(sender, e, Combot.ServerConfig.Name);
  31. Combot.IRC.ConnectEvent += () => ConnectHandler(Combot.ServerConfig.Name);
  32. Combot.IRC.DisconnectEvent += () => DisconnectHandler(Combot.ServerConfig.Name);
  33. Combot.IRC.TCPErrorEvent += e => TCPErrorHandler(e, Combot.ServerConfig.Name);
  34. CombotSessions.Add(Combot);
  35. if (server.AutoConnect)
  36. {
  37. Combot.Connect();
  38. }
  39. }
  40. bool run = true;
  41. while (run)
  42. {
  43. ConsoleKeyInfo info = Console.ReadKey();
  44. if (info.Key == ConsoleKey.Escape)
  45. {
  46. Console.WriteLine("Exiting...");
  47. run = false;
  48. }
  49. }
  50. }
  51. private static void RawMessageHandler(object sender, string message, string server)
  52. {
  53. string msg = string.Format("[{0}] [{1}] {2}", DateTime.Now.ToString("HH:mm:ss"), server, message);
  54. Console.WriteLine(msg);
  55. }
  56. private static void BotErrorHandler(BotError error, string server)
  57. {
  58. string message = string.Format("[{0}] [{1}] \u0002{2} Error\u0002: {3}", DateTime.Now.ToString("HH:mm:ss"), server, error.Type, error.Message);
  59. Console.WriteLine(message);
  60. }
  61. private static void TCPErrorHandler(Combot.IRCServices.TCP.TCPError error, string server)
  62. {
  63. string message = string.Format("[{0}] [{1}] \u0002TCP Error {2}\u0002: {3}", DateTime.Now.ToString("HH:mm:ss"), server, error.Code, error.Message);
  64. Console.WriteLine(message);
  65. }
  66. private static void PrivateMessageCommandHandler(object sender, PrivateMessageCommand message, string server)
  67. {
  68. string msg = string.Format("[{0}] [{1}] \u0002{2}\u0002: {3}", message.TimeStamp.ToString("HH:mm:ss"), server, " --Combot-- ", message.Message);
  69. Console.WriteLine(msg);
  70. }
  71. private static void PrivateNoticeCommandHandler(object sender, PrivateNoticeCommand message, string server)
  72. {
  73. string msg = string.Format("[{0}] [{1}] \u0002{2}\u0002 -NOTICE-: {3}", message.TimeStamp.ToString("HH:mm:ss"), server, " --Combot-- ", message.Message);
  74. Console.WriteLine(msg);
  75. }
  76. private static void ConnectHandler(string server)
  77. {
  78. Console.WriteLine("-- {0} Connected --", server);
  79. }
  80. private static void DisconnectHandler(string server)
  81. {
  82. Console.WriteLine("-- {0} Disconnected --", server);
  83. }
  84. }
  85. }