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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Threading;
  6. using Combot.IRCServices.Messaging;
  7. namespace Combot.Modules.Plugins
  8. {
  9. public class Version : Module
  10. {
  11. private List<VersionItem> versionList;
  12. private ReaderWriterLockSlim listLock;
  13. public override void Initialize()
  14. {
  15. listLock = new ReaderWriterLockSlim();
  16. versionList = new List<VersionItem>();
  17. Bot.IRC.Message.CTCPMessageRecievedEvent += HandleVersionQuery;
  18. Bot.IRC.Message.CTCPNoticeRecievedEvent += HandleVersionResponse;
  19. Bot.CommandReceivedEvent += HandleCommandEvent;
  20. }
  21. public override void ParseCommand(CommandMessage command)
  22. {
  23. Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command));
  24. if (foundCommand.Name == "Version Check")
  25. {
  26. string nick = command.Arguments["Nickname"].ToString();
  27. List<string> nickList = nick.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  28. for (int i = 0; i < nickList.Count; i++)
  29. {
  30. VersionItem tmpItem = new VersionItem();
  31. tmpItem.Location = command.Location;
  32. tmpItem.MessageType = command.MessageType;
  33. tmpItem.Nick = nickList[i];
  34. listLock.EnterWriteLock();
  35. if (versionList.Exists(item => item.Nick == nickList[i]))
  36. {
  37. versionList.RemoveAll(item => item.Nick == nickList[i]);
  38. }
  39. versionList.Add(tmpItem);
  40. listLock.ExitWriteLock();
  41. Bot.IRC.SendCTCPMessage(nickList[i], "VERSION");
  42. }
  43. }
  44. }
  45. public void HandleVersionQuery(object sender, CTCPMessage message)
  46. {
  47. if (message.Command.ToLower() == "version")
  48. {
  49. Bot.IRC.SendCTCPNotice(message.Sender.Nickname, "VERSION", string.Format("Combot v{0} on {1}", Assembly.GetExecutingAssembly().GetName().Version, GetOptionValue("Machine Reply")));
  50. }
  51. }
  52. public void HandleVersionResponse(object sender, CTCPMessage message)
  53. {
  54. if (message.Command == "VERSION")
  55. {
  56. listLock.EnterReadLock();
  57. VersionItem versionItem = versionList.Find(item => item.Nick.ToLower() == message.Sender.Nickname.ToLower());
  58. listLock.ExitReadLock();
  59. if (versionItem != null)
  60. {
  61. string verResponse = string.Format("[{0}] Using version: {1}", versionItem.Nick, message.Arguments);
  62. SendResponse(versionItem.MessageType, versionItem.Location, message.Sender.Nickname, verResponse);
  63. listLock.EnterWriteLock();
  64. versionList.RemoveAll(item => item.Nick == versionItem.Nick);
  65. listLock.ExitWriteLock();
  66. }
  67. }
  68. }
  69. private class VersionItem
  70. {
  71. public string Nick { get; set; }
  72. public string Location { get; set; }
  73. public MessageType MessageType { get; set; }
  74. public VersionItem()
  75. {
  76. Nick = string.Empty;
  77. Location = string.Empty;
  78. MessageType = MessageType.Channel;
  79. }
  80. }
  81. }
  82. }