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.

Quotes.cs 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, quoteMessage);
  42. }
  43. else
  44. {
  45. if (command.Arguments.ContainsKey("Nickname"))
  46. {
  47. string quoteMessage = string.Format("There are no quotes for \u0002{0}\u0002", command.Arguments["Nickname"]);
  48. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, quoteMessage);
  49. }
  50. else
  51. {
  52. string quoteMessage = string.Format("There are no quotes for \u0002{0}\u0002.", channel);
  53. SendResponse(command.MessageType, command.Location, command.Nick.Nickname, quoteMessage);
  54. }
  55. }
  56. }
  57. private List<Dictionary<string, object>> GetQuoteList(string channel)
  58. {
  59. string search = "SELECT `channelmessages`.`message`, `nicks`.`nickname` FROM `channelmessages` " +
  60. "INNER JOIN `nicks` " +
  61. "ON `channelmessages`.`nick_id` = `nicks`.`id` " +
  62. "INNER JOIN `channels` " +
  63. "ON `channelmessages`.`channel_id` = `channels`.`id` " +
  64. "INNER JOIN `servers` " +
  65. "ON `channelmessages`.`server_id` = `servers`.`id` " +
  66. "WHERE `servers`.`name` = {0} AND `channels`.`name` = {1}";
  67. return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, channel });
  68. }
  69. private List<Dictionary<string, object>> GetQuoteList(string channel, string nickname)
  70. {
  71. string search = "SELECT `channelmessages`.`message`, `nicks`.`nickname` FROM `channelmessages` " +
  72. "INNER JOIN `nicks` " +
  73. "ON `channelmessages`.`nick_id` = `nicks`.`id` " +
  74. "INNER JOIN `channels` " +
  75. "ON `channelmessages`.`channel_id` = `channels`.`id` " +
  76. "INNER JOIN `servers` " +
  77. "ON `channelmessages`.`server_id` = `servers`.`id` " +
  78. "WHERE `servers`.`name` = {0} AND `channels`.`name` = {1} AND `nicks`.`nickname` = {2}";
  79. return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, channel, nickname });
  80. }
  81. }
  82. }