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

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