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 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 = "#rice",
  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.Password = "24121exe";
  50. serverConfig.CommandPrefix = ".";
  51. serverConfig.JoinDelay = 1000;
  52. serverConfig.Hosts = new List<HostConfig> { new HostConfig() { Host = "irc.rizon.net", Port = 6667 } };
  53. serverConfig.Modules = new List<Module>
  54. {
  55. new Module
  56. {
  57. Name = "Ping Me",
  58. ClassName = "PingMe",
  59. Enabled = true,
  60. Commands = new List<Command>
  61. {
  62. new Command
  63. {
  64. Name = "Ping Me",
  65. Description = "Checks the time it takes for a PING to be returned from a nick.",
  66. AllowedAccess = new List<AccessType>
  67. {
  68. AccessType.User,
  69. AccessType.Voice,
  70. AccessType.HalfOperator,
  71. AccessType.Operator,
  72. AccessType.SuperOperator,
  73. AccessType.Founder,
  74. AccessType.Owner
  75. },
  76. Triggers = new List<string>
  77. {
  78. "pingme"
  79. }
  80. }
  81. }
  82. },
  83. new Module
  84. {
  85. Name = "Invite",
  86. ClassName = "Invite",
  87. Enabled = true
  88. },
  89. new Module
  90. {
  91. Name = "Version",
  92. ClassName = "Version",
  93. Enabled = true,
  94. Commands = new List<Command>
  95. {
  96. new Command
  97. {
  98. Name = "Version Check",
  99. Description = "Sends a version CTCP request and displays the response.",
  100. AllowedAccess = new List<AccessType>
  101. {
  102. AccessType.User,
  103. AccessType.Voice,
  104. AccessType.HalfOperator,
  105. AccessType.Operator,
  106. AccessType.SuperOperator,
  107. AccessType.Founder,
  108. AccessType.Owner
  109. },
  110. Triggers = new List<string>
  111. {
  112. "version",
  113. "ver"
  114. },
  115. Arguments = new List<CommandArgument>
  116. {
  117. new CommandArgument
  118. {
  119. Name = "Nickname",
  120. Description = "The nickname you want to query for version information.",
  121. Required = true
  122. }
  123. }
  124. }
  125. }
  126. }
  127. };
  128. Config.Servers.Add(serverConfig);
  129. Config.SaveServers();
  130. Config.LoadServers();
  131. foreach (ServerConfig server in Config.Servers)
  132. {
  133. Bot Combot = new Bot(server);
  134. /*
  135. Combot.IRC.Message.ErrorMessageEvent += ErrorMessageHandler;
  136. Combot.IRC.Message.ServerReplyEvent += ServerReplyHandler;
  137. Combot.IRC.Message.ChannelMessageReceivedEvent += ChannelMessageReceivedHandler;
  138. Combot.IRC.Message.ChannelNoticeReceivedEvent += ChannelNoticeReceivedHandler;
  139. Combot.IRC.Message.PrivateMessageReceivedEvent += PrivateMessageReceivedHandler;
  140. Combot.IRC.Message.PrivateNoticeReceivedEvent += PrivateNoticeReceivedHandler;
  141. */
  142. Combot.IRC.Message.RawMessageEvent += RawMessageHandler;
  143. Combot.IRC.ConnectEvent += ConnectHandler;
  144. Combot.IRC.DisconnectEvent += DisconnectHandler;
  145. Combot.IRC.TCPErrorEvent += TCPErrorHandler;
  146. CombotSessions.Add(Combot);
  147. }
  148. ToggleConnection = new DelegateCommand(ExecuteToggleConnection, CanToggleConnection);
  149. }
  150. private void RawMessageHandler(object sender, string message)
  151. {
  152. CurrentBuffer += message + Environment.NewLine;
  153. }
  154. private void TCPErrorHandler(Combot.IRCServices.TCP.TCPError error)
  155. {
  156. CurrentBuffer += string.Format("[{0}] {1}", error.Code.ToString(), error.Message) + Environment.NewLine;
  157. }
  158. private void ServerReplyHandler(object sender, IReply reply)
  159. {
  160. CurrentBuffer += reply.Message + Environment.NewLine;
  161. }
  162. private void ErrorMessageHandler(object sender, ErrorMessage message)
  163. {
  164. CurrentBuffer += message.Message + Environment.NewLine;
  165. }
  166. private void ChannelMessageReceivedHandler(object sender, ChannelMessage message)
  167. {
  168. CurrentBuffer += message.Message + Environment.NewLine;
  169. }
  170. private void ChannelNoticeReceivedHandler(object sender, ChannelNotice message)
  171. {
  172. CurrentBuffer += message.Message + Environment.NewLine;
  173. }
  174. private void PrivateMessageReceivedHandler(object sender, PrivateMessage message)
  175. {
  176. CurrentBuffer += message.Message + Environment.NewLine;
  177. }
  178. private void PrivateNoticeReceivedHandler(object sender, PrivateNotice message)
  179. {
  180. CurrentBuffer += message.Message + Environment.NewLine;
  181. }
  182. private void ConnectHandler()
  183. {
  184. Connected = true;
  185. }
  186. private void DisconnectHandler()
  187. {
  188. Connected = false;
  189. }
  190. private void ExecuteToggleConnection()
  191. {
  192. if (_Connected)
  193. {
  194. Disconnect();
  195. }
  196. else
  197. {
  198. Connect();
  199. }
  200. }
  201. private bool CanToggleConnection()
  202. {
  203. return true;
  204. }
  205. private void Connect()
  206. {
  207. CombotSessions.ForEach(Combot => Combot.Connect());
  208. }
  209. private void Disconnect()
  210. {
  211. CombotSessions.ForEach(Combot => Combot.Disconnect());
  212. }
  213. }
  214. }