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.

MainViewModel.cs 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net;
  7. using Combot;
  8. using Combot.IRCServices.Messaging;
  9. namespace Interface.ViewModels
  10. {
  11. public class MainViewModel : ViewModelBase
  12. {
  13. public Bot Combot = new Bot();
  14. public string ApplicationTitle { get; set; }
  15. private string _CurrentBuffer = string.Empty;
  16. public string CurrentBuffer { get { return _CurrentBuffer; } set { _CurrentBuffer = value; OnPropertyChanged("CurrentBuffer"); } }
  17. private bool _Connected = false;
  18. public bool Connected { get { return _Connected; } set { _Connected = value; if (_Connected) { ToggleConnectionText = "Disconnect"; } else { ToggleConnectionText = "Connect"; } OnPropertyChanged("Connected"); } }
  19. private string _ToggleConnectionText = "Connect";
  20. public string ToggleConnectionText { get { return _ToggleConnectionText; } set { _ToggleConnectionText = value; OnPropertyChanged("ToggleConnectionText"); } }
  21. public DelegateCommand ToggleConnection { get; private set; }
  22. public DelegateCommand JoinChannel { get; private set; }
  23. public MainViewModel()
  24. {
  25. ApplicationTitle = "Combot";
  26. Combot.Config.Nick = "Combot_V3";
  27. Combot.Config.Realname = "Combot_V3_realname";
  28. Combot.Config.Server = new Server();
  29. Combot.Config.Server.AutoConnect = true;
  30. Combot.Config.Server.Channels = new List<string>() { "#testing" };
  31. Combot.Config.Server.Name = "Rizon";
  32. IPAddress[] ipList = Dns.GetHostAddresses("irc.rizon.net");
  33. Combot.Config.Server.Hosts = new List<IPEndPoint>();
  34. foreach (IPAddress ip in ipList)
  35. {
  36. Combot.Config.Server.Hosts.Add(new System.Net.IPEndPoint(ip, 6667));
  37. }
  38. Combot.IRC.Message.ErrorMessageEvent += ErrorMessageHandler;
  39. Combot.IRC.Message.ServerReplyEvent += ServerReplyHandler;
  40. Combot.IRC.Message.ChannelMessageReceivedEvent += ChannelMessageReceivedHandler;
  41. Combot.IRC.Message.ChannelNoticeReceivedEvent += ChannelNoticeReceivedHandler;
  42. Combot.IRC.Message.PrivateMessageReceivedEvent += PrivateMessageReceivedHandler;
  43. Combot.IRC.Message.PrivateNoticeReceivedEvent += PrivateNoticeReceivedHandler;
  44. Combot.IRC.DisconnectEvent += DisconnectHandler;
  45. Combot.IRC.TCPErrorEvent += TCPErrorHandler;
  46. ToggleConnection = new DelegateCommand(ExecuteToggleConnection, CanToggleConnection);
  47. JoinChannel = new DelegateCommand(ExecuteJoinChannel, CanJoinChannel);
  48. }
  49. private void TCPErrorHandler(Combot.IRCServices.TCP.TCPError error)
  50. {
  51. CurrentBuffer += string.Format("[{0}] {1}", error.Code.ToString(), error.Message) + Environment.NewLine;
  52. }
  53. private void ServerReplyHandler(object sender, IReply reply)
  54. {
  55. CurrentBuffer += reply.Message + Environment.NewLine;
  56. }
  57. private void ErrorMessageHandler(object sender, ErrorMessage message)
  58. {
  59. CurrentBuffer += message.Message + Environment.NewLine;
  60. }
  61. private void ChannelMessageReceivedHandler(object sender, ChannelMessage message)
  62. {
  63. CurrentBuffer += message.Message + Environment.NewLine;
  64. }
  65. private void ChannelNoticeReceivedHandler(object sender, ChannelNotice message)
  66. {
  67. CurrentBuffer += message.Message + Environment.NewLine;
  68. }
  69. private void PrivateMessageReceivedHandler(object sender, PrivateMessage message)
  70. {
  71. CurrentBuffer += message.Message + Environment.NewLine;
  72. }
  73. private void PrivateNoticeReceivedHandler(object sender, PrivateNotice message)
  74. {
  75. CurrentBuffer += message.Message + Environment.NewLine;
  76. }
  77. private void DisconnectHandler()
  78. {
  79. Connected = false;
  80. }
  81. private void ExecuteToggleConnection()
  82. {
  83. if (_Connected)
  84. {
  85. Disconnect();
  86. }
  87. else
  88. {
  89. Connect();
  90. }
  91. }
  92. private bool CanToggleConnection()
  93. {
  94. return true;
  95. }
  96. private void Connect()
  97. {
  98. Connected = Combot.Connect();
  99. }
  100. private void Disconnect()
  101. {
  102. Connected = Combot.Disconnect();
  103. }
  104. private void ExecuteJoinChannel()
  105. {
  106. if (_Connected)
  107. {
  108. Combot.IRC.IRCSendJoin("#testing");
  109. }
  110. }
  111. private bool CanJoinChannel() { return true; }
  112. }
  113. }