The easy to use and full featured Irc Bot everyone is talking about!
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Bot.cs 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6. using System.Threading.Tasks;
  7. using Combot.IRCServices;
  8. namespace Combot
  9. {
  10. public class Bot
  11. {
  12. public event Action<BotError> ErrorEvent;
  13. public Config Config;
  14. public IRC IRC;
  15. public bool Connected = false;
  16. public Bot()
  17. {
  18. Config = new Config();
  19. IRC = new IRC();
  20. IRC.DisconnectEvent += HandleDisconnectEvent;
  21. }
  22. public bool Connect()
  23. {
  24. int i = 0;
  25. do
  26. {
  27. if (Config.Server.Hosts.Count > i)
  28. {
  29. Connected = IRC.Connect(Config.Server.Hosts[i].Address, Config.Server.Hosts[i].Port, 5000);
  30. i++;
  31. }
  32. else
  33. {
  34. break;
  35. }
  36. }
  37. while (!Connected);
  38. return Connected;
  39. }
  40. public bool Disconnect()
  41. {
  42. IRC.Disconnect();
  43. Connected = false;
  44. return Connected;
  45. }
  46. public void Login()
  47. {
  48. IRC.Login(Config.Server.Name, new Nick() { Nickname = Config.Nick, Host = Dns.GetHostName(), Realname = Config.Realname });
  49. }
  50. private void HandleDisconnectEvent()
  51. {
  52. Connected = false;
  53. }
  54. }
  55. }