The easy to use and full featured Irc Bot everyone is talking about!
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Whois.cs 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace Combot.Modules.Plugins
  4. {
  5. public class Whois : Module
  6. {
  7. public override void Initialize()
  8. {
  9. Bot.CommandReceivedEvent += HandleCommandEvent;
  10. }
  11. public override void ParseCommand(CommandMessage command)
  12. {
  13. Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command));
  14. switch (foundCommand.Name)
  15. {
  16. case "Whois":
  17. string option = (command.Arguments.ContainsKey("Option")) ? command.Arguments["Option"] : string.Empty;
  18. string mask = (command.Arguments.ContainsKey("Nickname")) ? command.Arguments["Nickname"] : command.Nick.Nickname;
  19. List<string> nicksList = new List<string>();
  20. List<string> hostList = new List<string>();
  21. bool detail = (option.ToLower() == "detail");
  22. findMatches(ref nicksList, ref hostList, mask, mask, detail);
  23. if (nicksList.Any() || hostList.Any())
  24. {
  25. // display results
  26. if (nicksList.Any() && (string.IsNullOrEmpty(option) || option.ToLower() == "nicks" || option.ToLower() == "detail"))
  27. {
  28. string nicksFound = string.Format("\u0002{0}\u0002 has been seen as: \u0002{1}\u0002", mask, string.Join(", ", nicksList));
  29. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, nicksFound, true);
  30. }
  31. if (hostList.Any() && (string.IsNullOrEmpty(option) || option.ToLower() == "hosts" || option.ToLower() == "detail"))
  32. {
  33. string hostsFound = string.Format("\u0002{0}\u0002 has used the following hosts: \u0002{1}\u0002", mask, string.Join(", ", hostList));
  34. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, hostsFound, true);
  35. }
  36. }
  37. else
  38. {
  39. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, string.Format("I have no information about \u0002{0}\u0002", mask), true);
  40. }
  41. break;
  42. }
  43. }
  44. private void findMatches(ref List<string> nickList, ref List<string> hostList, string nick, string host, bool detail)
  45. {
  46. List<Dictionary<string, object>> results = findAssociationList(nick, host, detail);
  47. for (int i = 0; i < results.Count; i++)
  48. {
  49. string foundNick = results[i]["nickname"].ToString();
  50. string foundHost = results[i]["host"].ToString();
  51. if (nickList != null && !nickList.Contains(foundNick))
  52. {
  53. nickList.Add(foundNick);
  54. findMatches(ref nickList, ref hostList, foundNick, foundNick, detail);
  55. }
  56. if (hostList != null && !hostList.Contains(foundHost))
  57. {
  58. hostList.Add(foundHost);
  59. findMatches(ref nickList, ref hostList, foundHost, foundHost, detail);
  60. }
  61. }
  62. }
  63. private List<Dictionary<string, object>> findAssociationList(string nick, string host, bool detail)
  64. {
  65. string reg = string.Empty;
  66. if (detail)
  67. {
  68. reg = "(`nicks`.`nickname` = {1} OR `nickinfo`.`host` = {2}) ";
  69. }
  70. else
  71. {
  72. reg = "(`nicks`.`nickname` = {1} OR (`nickinfo`.`host` = {2} AND `nickinfo`.`registered` = true)) ";
  73. }
  74. string search = "SELECT `nickinfo`.`host`, `nicks`.`nickname` FROM `nickinfo` " +
  75. "INNER JOIN `nicks` " +
  76. "ON `nickinfo`.`nick_id` = `nicks`.`id` " +
  77. "INNER JOIN `servers` " +
  78. "ON `nicks`.`server_id` = `servers`.`id` " +
  79. "WHERE `servers`.`name` = {0} AND " +
  80. reg +
  81. "GROUP BY `nickinfo`.`host`, `nicks`.`nickname`";
  82. return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, nick, host });
  83. }
  84. }
  85. }