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

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