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.

Commands.cs 36KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5. using Combot.IRCServices.Messaging;
  6. namespace Combot.IRCServices.Commanding
  7. {
  8. public class Commands
  9. {
  10. public event EventHandler<PrivateMessageCommand> PrivateMessageCommandEvent;
  11. public event EventHandler<PrivateNoticeCommand> PrivateNoticeCommandEvent;
  12. public event EventHandler<CTCPMessageCommand> CTCPMessageCommandEvent;
  13. public event EventHandler<CTCPNoticeCommand> CTCPNoticeCommandEvent;
  14. public event EventHandler<PasswordCommand> PasswordCommandEvent;
  15. public event EventHandler<NickCommand> NickCommandEvent;
  16. public event EventHandler<UserCommand> UserCommandEvent;
  17. public event EventHandler<OperCommand> OperCommandEvent;
  18. public event EventHandler<QuitCommand> QuitCommandEvent;
  19. public event EventHandler<JoinCommand> JoinCommandEvent;
  20. public event EventHandler<PartCommand> PartCommandEvent;
  21. public event EventHandler<ChannelModeCommand> ChannelModeCommandEvent;
  22. public event EventHandler<UserModeCommand> UserModeCommandEvent;
  23. public event EventHandler<TopicCommand> TopicCommandEvent;
  24. public event EventHandler<NamesCommand> NamesCommandEvent;
  25. public event EventHandler<ListCommand> ListCommandEvent;
  26. public event EventHandler<InviteCommand> InviteCommandEvent;
  27. public event EventHandler<KickCommand> KickCommandEvent;
  28. public event EventHandler<VersionCommand> VersionCommandEvent;
  29. public event EventHandler<StatsCommand> StatsCommandEvent;
  30. public event EventHandler<LinksCommand> LinksCommandEvent;
  31. public event EventHandler<TimeCommand> TimeCommandEvent;
  32. public event EventHandler<ConnectCommand> ConnectCommandEvent;
  33. public event EventHandler<TraceCommand> TraceCommandEvent;
  34. public event EventHandler<AdminCommand> AdminCommandEvent;
  35. public event EventHandler<InfoCommand> InfoCommandEvent;
  36. public event EventHandler<WhoCommand> WhoCommandEvent;
  37. public event EventHandler<WhoisCommand> WhoisCommandEvent;
  38. public event EventHandler<WhowasCommand> WhowasCommandEvent;
  39. public event EventHandler<KillCommand> KillCommandEvent;
  40. public event EventHandler<PingCommand> PingCommandEvent;
  41. public event EventHandler<PongCommand> PongCommandEvent;
  42. public event EventHandler<AwayCommand> AwayCommandEvent;
  43. public event EventHandler<RehashCommand> RehashCommandEvent;
  44. public event EventHandler<RestartCommand> RestartCommandEvent;
  45. public event EventHandler<SummonCommand> SummonCommandEvent;
  46. public event EventHandler<UsersCommand> UsersCommandEvent;
  47. public event EventHandler<WallopsCommand> WallopsCommandEvent;
  48. public event EventHandler<UserhostCommand> UserhostCommandEvent;
  49. public event EventHandler<IsonCommand> IsonCommandEvent;
  50. private IRC _IRC;
  51. private int MaxMessageLength;
  52. public Commands(IRC irc, int maxMessageLength, int messageSendDelay)
  53. {
  54. _IRC = irc;
  55. MaxMessageLength = maxMessageLength;
  56. }
  57. /// <summary>
  58. /// Sends a private message to a nick or channel
  59. /// </summary>
  60. /// <param name="nick"></param>
  61. /// <param name="message"></param>
  62. public void SendPrivateMessage(string recipient, string message)
  63. {
  64. if (message.Length > MaxMessageLength)
  65. {
  66. List<string> splitMessage = message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  67. string subMessage = string.Empty;
  68. string nextMessage = string.Empty;
  69. for (int i = 0; i < splitMessage.Count; i++)
  70. {
  71. int wordLength = splitMessage[i].Length + 1;
  72. int totalLength = subMessage.Length;
  73. if (totalLength + wordLength > MaxMessageLength)
  74. {
  75. nextMessage = string.Join(" ", splitMessage.GetRange(i, splitMessage.Count - i));
  76. break;
  77. }
  78. subMessage = string.Join(" ", subMessage, splitMessage[i]);
  79. }
  80. if (subMessage != string.Empty)
  81. {
  82. _IRC.SendTCPMessage(string.Format("PRIVMSG {0} :{1}", recipient, subMessage.Remove(0, 1)));
  83. if (PrivateMessageCommandEvent != null)
  84. {
  85. PrivateMessageCommandEvent(this, new PrivateMessageCommand {Message = subMessage.Remove(0, 1), Recipient = recipient});
  86. }
  87. }
  88. if (nextMessage != string.Empty)
  89. {
  90. SendPrivateMessage(recipient, nextMessage);
  91. }
  92. }
  93. else
  94. {
  95. _IRC.SendTCPMessage(string.Format("PRIVMSG {0} :{1}", recipient, message));
  96. if (PrivateMessageCommandEvent != null)
  97. {
  98. PrivateMessageCommandEvent(this, new PrivateMessageCommand { Message = message, Recipient = recipient });
  99. }
  100. }
  101. }
  102. public void SendPrivateMessage(List<string> recipients, string message)
  103. {
  104. string recipient_list = string.Empty;
  105. foreach (string recipient in recipients)
  106. {
  107. recipient_list += recipient + ",";
  108. }
  109. SendPrivateMessage(recipient_list.TrimEnd(','), message);
  110. }
  111. /// <summary>
  112. /// Sends a Notice to either a nick or channel
  113. /// </summary>
  114. /// <param name="nick"></param>
  115. /// <param name="message"></param>
  116. public void SendNotice(string recipient, string message)
  117. {
  118. if (message.Length > MaxMessageLength)
  119. {
  120. List<string> splitMessage = message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  121. string subMessage = string.Empty;
  122. string nextMessage = string.Empty;
  123. for (int i = 0; i < splitMessage.Count; i++)
  124. {
  125. int wordLength = splitMessage[i].Length + 1;
  126. int totalLength = subMessage.Length;
  127. if (totalLength + wordLength > MaxMessageLength)
  128. {
  129. nextMessage = string.Join(" ", splitMessage.GetRange(i, splitMessage.Count - i));
  130. break;
  131. }
  132. subMessage = string.Join(" ", subMessage, splitMessage[i]);
  133. }
  134. if (subMessage != string.Empty)
  135. {
  136. _IRC.SendTCPMessage(string.Format("NOTICE {0} :{1}", recipient, subMessage.Remove(0, 1)));
  137. if (PrivateNoticeCommandEvent != null)
  138. {
  139. PrivateNoticeCommandEvent(this, new PrivateNoticeCommand {Message = subMessage.Remove(0, 1), Recipient = recipient});
  140. }
  141. }
  142. if (nextMessage != string.Empty)
  143. {
  144. SendNotice(recipient, nextMessage);
  145. }
  146. }
  147. else
  148. {
  149. _IRC.SendTCPMessage(string.Format("NOTICE {0} :{1}", recipient, message));
  150. if (PrivateNoticeCommandEvent != null)
  151. {
  152. PrivateNoticeCommandEvent(this, new PrivateNoticeCommand { Message = message, Recipient = recipient });
  153. }
  154. }
  155. }
  156. public void SendNotice(List<string> recipients, string message)
  157. {
  158. string recipient_list = string.Empty;
  159. foreach (string recipient in recipients)
  160. {
  161. recipient_list += recipient + ",";
  162. }
  163. SendNotice(recipient_list.TrimEnd(','), message);
  164. }
  165. /// <summary>
  166. /// Sends a CTCP command and optional message to a nick or channel
  167. /// </summary>
  168. /// <param name="recipient"></param>
  169. /// <param name="command"></param>
  170. /// <param name="message"></param>
  171. public void SendCTCPMessage(string recipient, string command, string message = "")
  172. {
  173. if (message != string.Empty)
  174. {
  175. message = " " + message;
  176. }
  177. _IRC.SendTCPMessage(string.Format("PRIVMSG {0} :\u0001{1}{2}\u0001", recipient, command, message));
  178. if (CTCPMessageCommandEvent != null)
  179. {
  180. CTCPMessageCommandEvent(this, new CTCPMessageCommand { Arguments = message, Command = command, Recipient = recipient });
  181. }
  182. }
  183. public void SendCTCPMessage(List<string> recipients, string command, string message)
  184. {
  185. string recipient_list = string.Empty;
  186. foreach (string recipient in recipients)
  187. {
  188. recipient_list += recipient + ",";
  189. }
  190. if (message != string.Empty)
  191. {
  192. message = " " + message;
  193. }
  194. SendCTCPMessage(recipient_list.TrimEnd(','), command, message);
  195. }
  196. /// <summary>
  197. /// Sends a CTCP command and optional message to a nick or channel
  198. /// </summary>
  199. /// <param name="recipient"></param>
  200. /// <param name="command"></param>
  201. /// <param name="message"></param>
  202. public void SendCTCPNotice(string recipient, string command, string message = "")
  203. {
  204. if (message != string.Empty)
  205. {
  206. message = " " + message;
  207. }
  208. _IRC.SendTCPMessage(string.Format("NOTICE {0} :\u0001{1}{2}\u0001", recipient, command, message));
  209. if (CTCPNoticeCommandEvent != null)
  210. {
  211. CTCPNoticeCommandEvent(this, new CTCPNoticeCommand { Arguments = message, Command = command, Recipient = recipient });
  212. }
  213. }
  214. public void SendCTCPNotice(List<string> recipients, string command, string message)
  215. {
  216. string recipient_list = string.Empty;
  217. foreach (string recipient in recipients)
  218. {
  219. recipient_list += recipient + ",";
  220. }
  221. if (message != string.Empty)
  222. {
  223. message = " " + message;
  224. }
  225. SendCTCPNotice(recipient_list.TrimEnd(','), command, message);
  226. }
  227. /// <summary>
  228. /// Sends the connection password
  229. /// </summary>
  230. /// <param name="password"></param>
  231. public void SendPassword(string password)
  232. {
  233. _IRC.SendTCPMessage(string.Format("PASSWORD {0}", password));
  234. if (PasswordCommandEvent != null)
  235. {
  236. PasswordCommandEvent(this, new PasswordCommand { Password = password });
  237. }
  238. }
  239. /// <summary>
  240. /// Sends a Nick command to set the nickname
  241. /// </summary>
  242. /// <param name="nick"></param>
  243. public void SendNick(string nick)
  244. {
  245. _IRC.SendTCPMessage(string.Format("NICK {0}", nick));
  246. if (NickCommandEvent != null)
  247. {
  248. NickCommandEvent(this, new NickCommand { Nick = nick });
  249. }
  250. }
  251. /// <summary>
  252. /// Sends the User command to set a user
  253. /// </summary>
  254. /// <param name="user"></param>
  255. public void SendUser(string username, string hostname, string servername, string realname)
  256. {
  257. _IRC.SendTCPMessage(string.Format("USER {0} {1} {2} :{3}", username, hostname, servername, realname));
  258. if (UserCommandEvent != null)
  259. {
  260. UserCommandEvent(this, new UserCommand { Username = username, Hostname = hostname, Servername = servername, Realname = realname });
  261. }
  262. }
  263. /// <summary>
  264. /// Sends the Oper command to authorize the client as a newtork Oper
  265. /// </summary>
  266. /// <param name="username"></param>
  267. /// <param name="password"></param>
  268. public void SendOper(string username, string password)
  269. {
  270. _IRC.SendTCPMessage(string.Format("OPER {0} {1}", username, password));
  271. if (OperCommandEvent != null)
  272. {
  273. OperCommandEvent(this, new OperCommand {Username = username, Password = password});
  274. }
  275. }
  276. /// <summary>
  277. /// Sends a Quit command to end the client session
  278. /// </summary>
  279. /// <param name="message"></param>
  280. public void SendQuit()
  281. {
  282. _IRC.SendTCPMessage("QUIT");
  283. if (QuitCommandEvent != null)
  284. {
  285. QuitCommandEvent(this, new QuitCommand());
  286. }
  287. }
  288. public void SendQuit(string message)
  289. {
  290. _IRC.SendTCPMessage(string.Format("QUIT :{0}", message));
  291. if (QuitCommandEvent != null)
  292. {
  293. QuitCommandEvent(this, new QuitCommand {Message = message});
  294. }
  295. }
  296. /// <summary>
  297. /// Sends a Join command to join a channel
  298. /// </summary>
  299. /// <param name="channel"></param>
  300. public void SendJoin(string channel, string key = "")
  301. {
  302. string message = string.Empty;
  303. message = (key != string.Empty) ? string.Format("{0} {1}", channel, key) : channel;
  304. _IRC.SendTCPMessage(string.Format("JOIN {0}", message));
  305. if (JoinCommandEvent != null)
  306. {
  307. JoinCommandEvent(this, new JoinCommand {Channel = channel, Key = key});
  308. }
  309. }
  310. public void SendJoin(List<string> channels, List<string> keys)
  311. {
  312. string message = string.Empty;
  313. string channel_string = string.Empty;
  314. string key_string = string.Empty;
  315. foreach (string channel in channels)
  316. {
  317. channel_string += channel + ",";
  318. }
  319. foreach (string key in keys)
  320. {
  321. if (key != string.Empty)
  322. {
  323. key_string += key + ",";
  324. }
  325. }
  326. channel_string = channel_string.TrimEnd(',');
  327. key_string = key_string.TrimEnd(',');
  328. message = (key_string != string.Empty) ? string.Format("{0} {1}", channel_string, key_string) : channel_string;
  329. _IRC.SendTCPMessage(string.Format("JOIN {0}", message));
  330. if (JoinCommandEvent != null)
  331. {
  332. JoinCommandEvent(this, new JoinCommand {Channel = channel_string, Key = key_string});
  333. }
  334. }
  335. /// <summary>
  336. /// Sends a Part command to leave a channel
  337. /// </summary>
  338. /// <param name="channel"></param>
  339. public void SendPart(string channel)
  340. {
  341. _IRC.SendTCPMessage(string.Format("PART {0}", channel));
  342. if (PartCommandEvent != null)
  343. {
  344. PartCommandEvent(this, new PartCommand {Channel = channel});
  345. }
  346. }
  347. public void SendPart(List<string> channels)
  348. {
  349. string channel_list = string.Empty;
  350. foreach (string channel in channels)
  351. {
  352. channel_list += channel + ",";
  353. }
  354. SendPart(channel_list.TrimEnd(','));
  355. }
  356. /// <summary>
  357. /// Sends a Mode command for either a channel mode or user mode
  358. /// </summary>
  359. /// <param name="channel"></param>
  360. /// <param name="mode"></param>
  361. public void SendMode(string channel, ChannelModeInfo modeInfo)
  362. {
  363. string mode_set = modeInfo.Set ? "+" : "-";
  364. _IRC.SendTCPMessage(string.Format("MODE {0} {1} {2}", channel, mode_set + modeInfo.Mode, modeInfo.Parameter));
  365. if (ChannelModeCommandEvent != null)
  366. {
  367. ChannelModeCommandEvent(this, new ChannelModeCommand {Channel = channel, Mode = modeInfo});
  368. }
  369. }
  370. public void SendMode(string channel, List<ChannelModeInfo> modeInfos)
  371. {
  372. string modeList = string.Empty;
  373. string setList = string.Empty;
  374. bool lastSet = true;
  375. int modeIndex = 1;
  376. foreach (ChannelModeInfo modeInfo in modeInfos)
  377. {
  378. if ((setList.Length + modeList.Length + channel.Length + modeInfo.Parameter.Length + 8 + ((modeInfo.Set != lastSet) ? 1 : 0)) > MaxMessageLength || modeIndex > 4)
  379. {
  380. _IRC.SendTCPMessage(string.Format("MODE {0} {1} {2}", channel, setList, modeList));
  381. setList = string.Empty;
  382. modeList = string.Empty;
  383. lastSet = true;
  384. modeIndex = 1;
  385. }
  386. if (modeInfo.Set != lastSet)
  387. setList += modeInfo.Set ? "+" : "-";
  388. setList += modeInfo.Mode;
  389. modeList += modeInfo.Parameter + " ";
  390. lastSet = modeInfo.Set;
  391. modeIndex++;
  392. if (ChannelModeCommandEvent != null)
  393. {
  394. ChannelModeCommandEvent(this, new ChannelModeCommand { Channel = channel, Mode = modeInfo });
  395. }
  396. }
  397. if (!string.IsNullOrEmpty(setList) && !string.IsNullOrEmpty(modeList))
  398. _IRC.SendTCPMessage(string.Format("MODE {0} {1} {2}", channel, setList, modeList));
  399. }
  400. public void SendMode(string nick, UserModeInfo modeInfo)
  401. {
  402. string mode_set = modeInfo.Set ? "+" : "-";
  403. _IRC.SendTCPMessage(string.Format("MODE {0} {1}", nick, mode_set + modeInfo.Mode));
  404. if (UserModeCommandEvent != null)
  405. {
  406. UserModeCommandEvent(this, new UserModeCommand {Nick = nick, Mode = modeInfo});
  407. }
  408. }
  409. public void SendMode(string nick, List<UserModeInfo> modeInfos)
  410. {
  411. foreach (UserModeInfo modeInfo in modeInfos)
  412. {
  413. SendMode(nick, modeInfo);
  414. }
  415. }
  416. /// <summary>
  417. /// Sends a Topic command to change the channels topic or view the current one
  418. /// </summary>
  419. /// <param name="channel"></param>
  420. public void SendTopic(string channel)
  421. {
  422. _IRC.SendTCPMessage(string.Format("TOPIC {0}", channel));
  423. if (TopicCommandEvent != null)
  424. {
  425. TopicCommandEvent(this, new TopicCommand {Channel = channel});
  426. }
  427. }
  428. public void SendTopic(string channel, string topic)
  429. {
  430. _IRC.SendTCPMessage(string.Format("TOPIC {0} :{1}", channel, topic));
  431. if (TopicCommandEvent != null)
  432. {
  433. TopicCommandEvent(this, new TopicCommand {Channel = channel, Topic = topic});
  434. }
  435. }
  436. /// <summary>
  437. /// Sends a Names command to get a list of visible users
  438. /// </summary>
  439. public void SendNames()
  440. {
  441. _IRC.SendTCPMessage("NAMES");
  442. if (NamesCommandEvent != null)
  443. {
  444. NamesCommandEvent(this, new NamesCommand());
  445. }
  446. }
  447. public void SendNames(string channel)
  448. {
  449. _IRC.SendTCPMessage(string.Format("NAMES {0}", channel));
  450. if (NamesCommandEvent != null)
  451. {
  452. NamesCommandEvent(this, new NamesCommand {Channel = channel});
  453. }
  454. }
  455. public void SendNames(List<string> channels)
  456. {
  457. string channel_list = string.Empty;
  458. foreach (string channel in channels)
  459. {
  460. channel_list += channel + ",";
  461. }
  462. SendNames(channel_list.TrimEnd(','));
  463. }
  464. /// <summary>
  465. /// Sends a List command to get the topic of channels
  466. /// </summary>
  467. public void SendList()
  468. {
  469. _IRC.SendTCPMessage("LIST");
  470. if (ListCommandEvent != null)
  471. {
  472. ListCommandEvent(this, new ListCommand());
  473. }
  474. }
  475. public void SendList(string channel)
  476. {
  477. _IRC.SendTCPMessage(string.Format("LIST {0}", channel));
  478. if (ListCommandEvent != null)
  479. {
  480. ListCommandEvent(this, new ListCommand {Channel = channel});
  481. }
  482. }
  483. public void SendList(List<string> channels)
  484. {
  485. string channel_list = string.Empty;
  486. foreach (string channel in channels)
  487. {
  488. channel_list += channel + ",";
  489. }
  490. SendList(channel_list.TrimEnd(','));
  491. }
  492. /// <summary>
  493. /// Sends an Invite command that invites the specified nick to the channel
  494. /// </summary>
  495. /// <param name="channel"></param>
  496. /// <param name="nick"></param>
  497. public void SendInvite(string channel, string nick)
  498. {
  499. _IRC.SendTCPMessage(string.Format("INVITE {0} {1}", nick, channel));
  500. if (InviteCommandEvent != null)
  501. {
  502. InviteCommandEvent(this, new InviteCommand {Channel = channel, Nick = nick});
  503. }
  504. }
  505. /// <summary>
  506. /// Sends a Kick command to remove a user from a channel
  507. /// </summary>
  508. /// <param name="channel"></param>
  509. /// <param name="nick"></param>
  510. public void SendKick(string channel, string nick)
  511. {
  512. _IRC.SendTCPMessage(string.Format("KICK {0} {1}", channel, nick));
  513. if (KickCommandEvent != null)
  514. {
  515. KickCommandEvent(this, new KickCommand {Channel = channel, Nick = nick});
  516. }
  517. }
  518. public void SendKick(string channel, string nick, string reason)
  519. {
  520. _IRC.SendTCPMessage(string.Format("KICK {0} {1} :{2}", channel, nick, reason));
  521. if (KickCommandEvent != null)
  522. {
  523. KickCommandEvent(this, new KickCommand {Channel = channel, Nick = nick, Reason = reason});
  524. }
  525. }
  526. /// <summary>
  527. /// Sends a Version command to the server to get a Version reply
  528. /// </summary>
  529. /// <param name="server"></param>
  530. public void SendVersion(string server)
  531. {
  532. _IRC.SendTCPMessage(string.Format("VERSION {0}", server));
  533. if (VersionCommandEvent != null)
  534. {
  535. VersionCommandEvent(this, new VersionCommand {Server = server});
  536. }
  537. }
  538. /// <summary>
  539. /// Sends a Stats command to view Server information and statistics
  540. /// </summary>
  541. /// <param name="stat"></param>
  542. public void SendStats(ServerStat stat)
  543. {
  544. _IRC.SendTCPMessage(string.Format("STATS {0}", stat));
  545. if (StatsCommandEvent != null)
  546. {
  547. StatsCommandEvent(this, new StatsCommand {Stat = stat.ToString()});
  548. }
  549. }
  550. public void SendStats(ServerStat stat, string parameter)
  551. {
  552. _IRC.SendTCPMessage(string.Format("STATS {0} {1}", stat, parameter));
  553. if (StatsCommandEvent != null)
  554. {
  555. StatsCommandEvent(this, new StatsCommand {Stat = stat.ToString(), Parameter = parameter});
  556. }
  557. }
  558. /// <summary>
  559. /// Sends a Links command to list all servers matching a mask
  560. /// </summary>
  561. /// <param name="mask"></param>
  562. public void SendLinks(string mask)
  563. {
  564. _IRC.SendTCPMessage(string.Format("LINKS {0}", mask));
  565. if (LinksCommandEvent != null)
  566. {
  567. LinksCommandEvent(this, new LinksCommand {Mask = mask});
  568. }
  569. }
  570. public void SendLinks(string server, string mask)
  571. {
  572. _IRC.SendTCPMessage(string.Format("LINKS {0} {1}", mask, server));
  573. if (LinksCommandEvent != null)
  574. {
  575. LinksCommandEvent(this, new LinksCommand {Mask = mask, Server = server});
  576. }
  577. }
  578. /// <summary>
  579. /// Sends a Time command to query the local server time
  580. /// </summary>
  581. public void SendTime()
  582. {
  583. _IRC.SendTCPMessage("TIME");
  584. if (TimeCommandEvent != null)
  585. {
  586. TimeCommandEvent(this, new TimeCommand());
  587. }
  588. }
  589. public void SendTime(string server)
  590. {
  591. _IRC.SendTCPMessage(string.Format("TIME {0}", server));
  592. if (TimeCommandEvent != null)
  593. {
  594. TimeCommandEvent(this, new TimeCommand {Server = server});
  595. }
  596. }
  597. /// <summary>
  598. /// Senda a Connect command to have the server try to connect to another server
  599. /// </summary>
  600. /// <param name="server"></param>
  601. public void SendConnect(string server)
  602. {
  603. _IRC.SendTCPMessage(string.Format("CONNECT {0}", server));
  604. if (ConnectCommandEvent != null)
  605. {
  606. ConnectCommandEvent(this, new ConnectCommand {Server = server});
  607. }
  608. }
  609. public void SendConnect(string server, string originator, int port)
  610. {
  611. _IRC.SendTCPMessage(string.Format("CONNECT {0} {1} {2}", originator, port, server));
  612. if (ConnectCommandEvent != null)
  613. {
  614. ConnectCommandEvent(this, new ConnectCommand {Server = server, Originator = originator, Port = port});
  615. }
  616. }
  617. /// <summary>
  618. /// Sends a Trace command to find the route to the target (nick or server)
  619. /// </summary>
  620. /// <param name="target"></param>
  621. public void SendTrace(string target)
  622. {
  623. _IRC.SendTCPMessage(string.Format("TRACE {0}", target));
  624. if (TraceCommandEvent != null)
  625. {
  626. TraceCommandEvent(this, new TraceCommand {Target = target});
  627. }
  628. }
  629. /// <summary>
  630. /// Sends an Admin command to get the name of the server Administrator
  631. /// </summary>
  632. public void SendAdmin()
  633. {
  634. _IRC.SendTCPMessage("ADMIN");
  635. if (AdminCommandEvent != null)
  636. {
  637. AdminCommandEvent(this, new AdminCommand());
  638. }
  639. }
  640. public void SendAdmin(string host)
  641. {
  642. _IRC.SendTCPMessage(string.Format("ADMIN {0}", host));
  643. if (AdminCommandEvent != null)
  644. {
  645. AdminCommandEvent(this, new AdminCommand {Host = host});
  646. }
  647. }
  648. /// <summary>
  649. /// Sends an Info command for a specific server or nick
  650. /// </summary>
  651. /// <param name="host"></param>
  652. public void SendInfo(string host)
  653. {
  654. _IRC.SendTCPMessage(string.Format("INFO {0}", host));
  655. if (InfoCommandEvent != null)
  656. {
  657. InfoCommandEvent(this, new InfoCommand {Host = host});
  658. }
  659. }
  660. /// <summary>
  661. /// Sends a Who command to list all public users or matching a mask
  662. /// </summary>
  663. public void SendWho()
  664. {
  665. _IRC.SendTCPMessage("WHO");
  666. if (WhoCommandEvent != null)
  667. {
  668. WhoCommandEvent(this, new WhoCommand());
  669. }
  670. }
  671. public void SendWho(string host, bool ops = false)
  672. {
  673. string msg = string.Empty;
  674. if (ops)
  675. {
  676. msg = string.Format("WHO {0} o", host);
  677. }
  678. else
  679. {
  680. msg = string.Format("WHO {0}", host);
  681. }
  682. _IRC.SendTCPMessage(msg);
  683. if (WhoCommandEvent != null)
  684. {
  685. WhoCommandEvent(this, new WhoCommand {Host = host});
  686. }
  687. }
  688. /// <summary>
  689. /// Sends a Whois command to get info about a user
  690. /// </summary>
  691. /// <param name="nick"></param>
  692. public void SendWhois(string nick)
  693. {
  694. _IRC.SendTCPMessage(string.Format("WHOIS {0}", nick));
  695. if (WhoisCommandEvent != null)
  696. {
  697. WhoisCommandEvent(this, new WhoisCommand {Nick = nick});
  698. }
  699. }
  700. public void SendWhois(string nick, string server)
  701. {
  702. _IRC.SendTCPMessage(string.Format("WHOIS {0} {1}", server, nick));
  703. if (WhoisCommandEvent != null)
  704. {
  705. WhoisCommandEvent(this, new WhoisCommand {Nick = nick, Server = server});
  706. }
  707. }
  708. /// <summary>
  709. /// Sends a Whowas command to get the nick history of a user
  710. /// </summary>
  711. /// <param name="nick"></param>
  712. public void SendWhowas(string nick)
  713. {
  714. _IRC.SendTCPMessage(string.Format("WHOWAS {0}", nick));
  715. if (WhowasCommandEvent != null)
  716. {
  717. WhowasCommandEvent(this, new WhowasCommand {Nick = nick});
  718. }
  719. }
  720. public void SendWhowas(string nick, int entries)
  721. {
  722. _IRC.SendTCPMessage(string.Format("WHOWAS {0} {1}", nick, entries));
  723. if (WhowasCommandEvent != null)
  724. {
  725. WhowasCommandEvent(this, new WhowasCommand {Nick = nick, Entries = entries});
  726. }
  727. }
  728. public void SendWhowas(string nick, int entries, string server)
  729. {
  730. _IRC.SendTCPMessage(string.Format("WHOWAS {0} {1} {2}", nick, entries, server));
  731. if (WhowasCommandEvent != null)
  732. {
  733. WhowasCommandEvent(this, new WhowasCommand {Nick = nick, Entries = entries, Server = server});
  734. }
  735. }
  736. /// <summary>
  737. /// Sends a Kill command to disconnect a nick
  738. /// </summary>
  739. /// <param name="nick"></param>
  740. /// <param name="comment"></param>
  741. public void SendKill(string nick, string comment)
  742. {
  743. _IRC.SendTCPMessage(string.Format("KILL {0} {1}", nick, comment));
  744. if (KillCommandEvent != null)
  745. {
  746. KillCommandEvent(this, new KillCommand {Nick = nick, Comment = comment});
  747. }
  748. }
  749. /// <summary>
  750. /// Sends a Ping command to the recipient
  751. /// </summary>
  752. /// <param name="recipient"></param>
  753. public void SendPing(string recipient)
  754. {
  755. _IRC.SendTCPMessage(string.Format("PING {0}", recipient));
  756. if (PingCommandEvent != null)
  757. {
  758. PingCommandEvent(this, new PingCommand {Recipient = recipient});
  759. }
  760. }
  761. /// <summary>
  762. /// Sends a PONG response to respond to a Ping
  763. /// </summary>
  764. /// <param name="sender"></param>
  765. /// <param name="recipient"></param>
  766. public void SendPong()
  767. {
  768. _IRC.SendTCPMessage("PONG");
  769. if (PongCommandEvent != null)
  770. {
  771. PongCommandEvent(this, new PongCommand());
  772. }
  773. }
  774. public void SendPong(string message)
  775. {
  776. _IRC.SendTCPMessage(string.Format("PONG {0}", message));
  777. if (PongCommandEvent != null)
  778. {
  779. PongCommandEvent(this, new PongCommand());
  780. }
  781. }
  782. public void SendPong(string sender, string recipient)
  783. {
  784. _IRC.SendTCPMessage(string.Format("PONG {0} {1}", sender, recipient));
  785. if (PongCommandEvent != null)
  786. {
  787. PongCommandEvent(this, new PongCommand { Sender = sender, Recipient = recipient });
  788. }
  789. }
  790. /// <summary>
  791. /// Sends an Away command to unset away status
  792. /// </summary>
  793. public void SendAway()
  794. {
  795. _IRC.SendTCPMessage("AWAY");
  796. if (AwayCommandEvent != null)
  797. {
  798. AwayCommandEvent(this, new AwayCommand());
  799. }
  800. }
  801. /// <summary>
  802. /// Sends an Away comand to set away status with auto-reply message
  803. /// </summary>
  804. /// <param name="message"></param>
  805. public void SendAway(string message)
  806. {
  807. _IRC.SendTCPMessage(string.Format("AWAY {0}", message));
  808. if (AwayCommandEvent != null)
  809. {
  810. AwayCommandEvent(this, new AwayCommand {Message = message});
  811. }
  812. }
  813. /// <summary>
  814. /// Sends a Rehash command to the server to reload it's configuration file
  815. /// </summary>
  816. public void SendRehash()
  817. {
  818. _IRC.SendTCPMessage("REHASH");
  819. if (RehashCommandEvent != null)
  820. {
  821. RehashCommandEvent(this, new RehashCommand());
  822. }
  823. }
  824. /// <summary>
  825. /// Sends a Restart command to the server to restart
  826. /// </summary>
  827. public void SendRestart()
  828. {
  829. _IRC.SendTCPMessage("RESTART");
  830. if (RestartCommandEvent != null)
  831. {
  832. RestartCommandEvent(this, new RestartCommand());
  833. }
  834. }
  835. /// <summary>
  836. /// Sends a Summon command to summon a nick to the server
  837. /// </summary>
  838. /// <param name="nick"></param>
  839. public void SendSummon()
  840. {
  841. _IRC.SendTCPMessage("SUMMON");
  842. if (SummonCommandEvent != null)
  843. {
  844. SummonCommandEvent(this, new SummonCommand());
  845. }
  846. }
  847. public void SendSummon(string nick)
  848. {
  849. _IRC.SendTCPMessage(string.Format("SUMMON {0}", nick));
  850. if (SummonCommandEvent != null)
  851. {
  852. SummonCommandEvent(this, new SummonCommand {Nick = nick});
  853. }
  854. }
  855. public void SendSummon(string nick, string host)
  856. {
  857. _IRC.SendTCPMessage(string.Format("SUMMON {0} {1}", nick, host));
  858. if (SummonCommandEvent != null)
  859. {
  860. SummonCommandEvent(this, new SummonCommand {Nick = nick, Host = host});
  861. }
  862. }
  863. /// <summary>
  864. /// Sends a Users command to get a list of Users from a server
  865. /// </summary>
  866. /// <param name="server"></param>
  867. public void SendUsers(string server)
  868. {
  869. _IRC.SendTCPMessage(string.Format("USERS {0}", server));
  870. if (UsersCommandEvent != null)
  871. {
  872. UsersCommandEvent(this, new UsersCommand {Server = server});
  873. }
  874. }
  875. /// <summary>
  876. /// Sends a Wallops command which sends a message to all connected ops
  877. /// </summary>
  878. /// <param name="message"></param>
  879. public void SendWallops(string message)
  880. {
  881. _IRC.SendTCPMessage(string.Format("WALLOPS :{0}", message));
  882. if (WallopsCommandEvent != null)
  883. {
  884. WallopsCommandEvent(this, new WallopsCommand {Message = message});
  885. }
  886. }
  887. /// <summary>
  888. /// Sends an Userhost command to up to 5 nicknames to return information about each nick
  889. /// </summary>
  890. /// <param name="nicks"></param>
  891. public void SendUserhost(List<string> nicks)
  892. {
  893. string message = string.Empty;
  894. foreach (string nick in nicks)
  895. {
  896. message += " " + nick;
  897. }
  898. _IRC.SendTCPMessage(string.Format("USERHOST {0}", message.Trim()));
  899. if (UserhostCommandEvent != null)
  900. {
  901. UserhostCommandEvent(this, new UserhostCommand {Nicks = message.Trim()});
  902. }
  903. }
  904. /// <summary>
  905. /// Sends an IsOn command to get a return if the nicks specified are online
  906. /// </summary>
  907. /// <param name="nicks"></param>
  908. public void SendIson(List<string> nicks)
  909. {
  910. string message = string.Empty;
  911. foreach (string nick in nicks)
  912. {
  913. message += " " + nick;
  914. }
  915. _IRC.SendTCPMessage(string.Format("ISON {0}", message.Trim()));
  916. if (IsonCommandEvent != null)
  917. {
  918. IsonCommandEvent(this, new IsonCommand {Nicks = message.Trim()});
  919. }
  920. }
  921. }
  922. }