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.

MainViewModel.cs 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. using Combot.Configurations;
  10. using Combot.Modules;
  11. using Combot.Modules.ModuleClasses;
  12. namespace Interface.ViewModels
  13. {
  14. public class MainViewModel : ViewModelBase
  15. {
  16. public List<Bot> CombotSessions = new List<Bot>();
  17. public Config Config = new Config();
  18. public string ApplicationTitle { get; set; }
  19. private string _CurrentBuffer = string.Empty;
  20. public string CurrentBuffer { get { return _CurrentBuffer; } set { _CurrentBuffer = value; OnPropertyChanged("CurrentBuffer"); } }
  21. private bool _Connected = false;
  22. public bool Connected { get { return _Connected; } set { _Connected = value; if (_Connected) { ToggleConnectionText = "Disconnect"; } else { ToggleConnectionText = "Connect"; } OnPropertyChanged("Connected"); } }
  23. private string _ToggleConnectionText = "Connect";
  24. public string ToggleConnectionText { get { return _ToggleConnectionText; } set { _ToggleConnectionText = value; OnPropertyChanged("ToggleConnectionText"); } }
  25. public DelegateCommand ToggleConnection { get; private set; }
  26. public MainViewModel()
  27. {
  28. ApplicationTitle = "Combot";
  29. //Config.LoadServers();
  30. ServerConfig serverConfig = new ServerConfig();
  31. serverConfig.AutoConnect = true;
  32. serverConfig.Channels = new List<ChannelConfig>
  33. {
  34. new ChannelConfig()
  35. {
  36. Name = "#testing",
  37. Key = string.Empty
  38. },
  39. new ChannelConfig()
  40. {
  41. Name = "#/g/technology",
  42. Key = string.Empty
  43. }
  44. };
  45. serverConfig.Name = "Rizon";
  46. serverConfig.Nickname = "Combot_V3";
  47. serverConfig.Realname = "Combot_Realname";
  48. serverConfig.Username = "Combot_Username";
  49. serverConfig.CommandPrefix = ".";
  50. serverConfig.Hosts = new List<HostConfig> { new HostConfig() { Host = "irc.rizon.net", Port = 6667 } };
  51. serverConfig.Modules = new List<Module>
  52. {
  53. new Module
  54. {
  55. Name = "Ping Me",
  56. ClassName = "PingMe",
  57. Enabled = true,
  58. Commands = new List<Command>
  59. {
  60. new Command
  61. {
  62. Name = "Ping Me",
  63. Description = "Checks the time it takes for a PING to be returned from a nick.",
  64. AllowedAccess = new List<AccessType>()
  65. {
  66. AccessType.User,
  67. AccessType.Voice,
  68. AccessType.HalfOperator,
  69. AccessType.Operator,
  70. AccessType.SuperOperator,
  71. AccessType.Founder,
  72. AccessType.Owner
  73. },
  74. Triggers = new List<string>()
  75. {
  76. "pingme"
  77. }
  78. }
  79. }
  80. }
  81. };
  82. Config.Servers.Add(serverConfig);
  83. Config.SaveServers();
  84. foreach (ServerConfig server in Config.Servers)
  85. {
  86. Bot Combot = new Bot(server);
  87. Combot.IRC.Message.ErrorMessageEvent += ErrorMessageHandler;
  88. Combot.IRC.Message.ServerReplyEvent += ServerReplyHandler;
  89. Combot.IRC.Message.ChannelMessageReceivedEvent += ChannelMessageReceivedHandler;
  90. Combot.IRC.Message.ChannelNoticeReceivedEvent += ChannelNoticeReceivedHandler;
  91. Combot.IRC.Message.PrivateMessageReceivedEvent += PrivateMessageReceivedHandler;
  92. Combot.IRC.Message.PrivateNoticeReceivedEvent += PrivateNoticeReceivedHandler;
  93. Combot.IRC.ConnectEvent += ConnectHandler;
  94. Combot.IRC.DisconnectEvent += DisconnectHandler;
  95. Combot.IRC.TCPErrorEvent += TCPErrorHandler;
  96. CombotSessions.Add(Combot);
  97. }
  98. ToggleConnection = new DelegateCommand(ExecuteToggleConnection, CanToggleConnection);
  99. }
  100. private void TCPErrorHandler(Combot.IRCServices.TCP.TCPError error)
  101. {
  102. CurrentBuffer += string.Format("[{0}] {1}", error.Code.ToString(), error.Message) + Environment.NewLine;
  103. }
  104. private void ServerReplyHandler(object sender, IReply reply)
  105. {
  106. CurrentBuffer += reply.Message + Environment.NewLine;
  107. }
  108. private void ErrorMessageHandler(object sender, ErrorMessage message)
  109. {
  110. CurrentBuffer += message.Message + Environment.NewLine;
  111. }
  112. private void ChannelMessageReceivedHandler(object sender, ChannelMessage message)
  113. {
  114. CurrentBuffer += message.Message + Environment.NewLine;
  115. }
  116. private void ChannelNoticeReceivedHandler(object sender, ChannelNotice message)
  117. {
  118. CurrentBuffer += message.Message + Environment.NewLine;
  119. }
  120. private void PrivateMessageReceivedHandler(object sender, PrivateMessage message)
  121. {
  122. CurrentBuffer += message.Message + Environment.NewLine;
  123. }
  124. private void PrivateNoticeReceivedHandler(object sender, PrivateNotice message)
  125. {
  126. CurrentBuffer += message.Message + Environment.NewLine;
  127. }
  128. private void ConnectHandler()
  129. {
  130. Connected = true;
  131. }
  132. private void DisconnectHandler()
  133. {
  134. Connected = false;
  135. }
  136. private void ExecuteToggleConnection()
  137. {
  138. if (_Connected)
  139. {
  140. Disconnect();
  141. }
  142. else
  143. {
  144. Connect();
  145. }
  146. }
  147. private bool CanToggleConnection()
  148. {
  149. return true;
  150. }
  151. private void Connect()
  152. {
  153. CombotSessions.ForEach(Combot => Combot.Connect());
  154. }
  155. private void Disconnect()
  156. {
  157. CombotSessions.ForEach(Combot => Combot.Disconnect());
  158. }
  159. }
  160. }