The easy to use and full featured Irc Bot everyone is talking about!
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Commands.cs 35KB

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