The easy to use and full featured Irc Bot everyone is talking about!
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Quotes.cs 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Combot.Databases;
  5. namespace Combot.Modules.Plugins
  6. {
  7. public class Quotes : Module
  8. {
  9. public override void Initialize()
  10. {
  11. Bot.CommandReceivedEvent += HandleCommandEvent;
  12. }
  13. public override void ParseCommand(CommandMessage command)
  14. {
  15. Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command));
  16. switch (foundCommand.Name)
  17. {
  18. case "Quote":
  19. GetQuote(command);
  20. break;
  21. }
  22. }
  23. private void GetQuote(CommandMessage command)
  24. {
  25. string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
  26. List<Dictionary<string, object>> results = new List<Dictionary<string, object>>();
  27. if (command.Arguments.ContainsKey("Nickname"))
  28. {
  29. results = GetQuoteList(channel, command.Arguments["Nickname"]);
  30. }
  31. else
  32. {
  33. results = GetQuoteList(channel);
  34. }
  35. if (results.Any())
  36. {
  37. Random randNum = new Random();
  38. int index = randNum.Next(results.Count - 1);
  39. Dictionary<string, object> quote = results[index];
  40. string quoteMessage = string.Format("[{0}] {1}", quote["nickname"], quote["message"]);
  41. switch (command.MessageType)
  42. {
  43. case MessageType.Channel:
  44. Bot.IRC.SendPrivateMessage(command.Location, quoteMessage);
  45. break;
  46. case MessageType.Query:
  47. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, quoteMessage);
  48. break;
  49. case MessageType.Notice:
  50. Bot.IRC.SendNotice(command.Nick.Nickname, quoteMessage);
  51. break;
  52. }
  53. }
  54. else
  55. {
  56. if (command.Arguments.ContainsKey("Nickname"))
  57. {
  58. string quoteMessage = string.Format("There are no quotes for \u0002{0}\u0002", command.Arguments["Nickname"]);
  59. switch (command.MessageType)
  60. {
  61. case MessageType.Channel:
  62. Bot.IRC.SendPrivateMessage(command.Location, quoteMessage);
  63. break;
  64. case MessageType.Query:
  65. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, quoteMessage);
  66. break;
  67. case MessageType.Notice:
  68. Bot.IRC.SendNotice(command.Nick.Nickname, quoteMessage);
  69. break;
  70. }
  71. }
  72. else
  73. {
  74. string quoteMessage = string.Format("There are no quotes for \u0002{0}\u0002.", channel);
  75. switch (command.MessageType)
  76. {
  77. case MessageType.Channel:
  78. Bot.IRC.SendPrivateMessage(command.Location, quoteMessage);
  79. break;
  80. case MessageType.Query:
  81. Bot.IRC.SendPrivateMessage(command.Nick.Nickname, quoteMessage);
  82. break;
  83. case MessageType.Notice:
  84. Bot.IRC.SendNotice(command.Nick.Nickname, quoteMessage);
  85. break;
  86. }
  87. }
  88. }
  89. }
  90. private List<Dictionary<string, object>> GetQuoteList(string channel)
  91. {
  92. Database database = new Database(Bot.ServerConfig.Database);
  93. string search = "SELECT `channelmessages`.`message`, `nicks`.`nickname` FROM `channelmessages` " +
  94. "INNER JOIN `nicks` " +
  95. "ON `channelmessages`.`nick_id` = `nicks`.`id` " +
  96. "INNER JOIN `channels` " +
  97. "ON `channelmessages`.`channel_id` = `channels`.`id` " +
  98. "INNER JOIN `servers` " +
  99. "ON `channelmessages`.`server_id` = `servers`.`id` " +
  100. "WHERE `servers`.`name` = {0} AND `channels`.`name` = {1}";
  101. return database.Query(search, new object[] { Bot.ServerConfig.Name, channel });
  102. }
  103. private List<Dictionary<string, object>> GetQuoteList(string channel, string nickname)
  104. {
  105. Database database = new Database(Bot.ServerConfig.Database);
  106. string search = "SELECT `channelmessages`.`message`, `nicks`.`nickname` FROM `channelmessages` " +
  107. "INNER JOIN `nicks` " +
  108. "ON `channelmessages`.`nick_id` = `nicks`.`id` " +
  109. "INNER JOIN `channels` " +
  110. "ON `channelmessages`.`channel_id` = `channels`.`id` " +
  111. "INNER JOIN `servers` " +
  112. "ON `channelmessages`.`server_id` = `servers`.`id` " +
  113. "WHERE `servers`.`name` = {0} AND `channels`.`name` = {1} AND `nicks`.`nickname` = {2}";
  114. return database.Query(search, new object[] { Bot.ServerConfig.Name, channel, nickname });
  115. }
  116. }
  117. }