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.

Logging.cs 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Combot.Databases;
  4. using Combot.IRCServices.Messaging;
  5. namespace Combot.Modules.Plugins
  6. {
  7. public class Logging : Module
  8. {
  9. public override void Initialize()
  10. {
  11. Bot.IRC.ConnectEvent += AddServer;
  12. Bot.IRC.Message.ChannelMessageReceivedEvent += LogChannelMessage;
  13. Bot.IRC.Message.PrivateMessageReceivedEvent += LogPrivateMessage;
  14. Bot.IRC.Message.JoinChannelEvent += LogChannelJoin;
  15. Bot.IRC.Message.PartChannelEvent += LogChannelPart;
  16. Bot.IRC.Message.KickEvent += LogChannelKick;
  17. Bot.IRC.Message.QuitEvent += LogQuit;
  18. }
  19. private void LogChannelMessage(object sender, ChannelMessage message)
  20. {
  21. if (!ChannelBlacklist.Contains(message.Channel)
  22. && !NickBlacklist.Contains(message.Sender.Nickname))
  23. {
  24. AddChannel(message.Channel);
  25. AddNick(message.Sender);
  26. string query = "INSERT INTO `channelmessages` SET " +
  27. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  28. "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
  29. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
  30. "`message` = {5}, " +
  31. "`date_added` = {6}";
  32. Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, message.Channel, Bot.ServerConfig.Name, message.Sender.Nickname, message.Message, message.TimeStamp });
  33. }
  34. }
  35. private void LogPrivateMessage(object sender, PrivateMessage message)
  36. {
  37. if (!NickBlacklist.Contains(message.Sender.Nickname))
  38. {
  39. AddNick(message.Sender);
  40. string query = "INSERT INTO `privatemessages` SET " +
  41. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  42. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {1} && `nickname` = {2}), " +
  43. "`message` = {3}, " +
  44. "`date_added` = {4}";
  45. Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, message.Sender.Nickname, message.Message, message.TimeStamp });
  46. }
  47. }
  48. private void LogChannelJoin(object sender, JoinChannelInfo info)
  49. {
  50. if (!ChannelBlacklist.Contains(info.Channel)
  51. && !NickBlacklist.Contains(info.Nick.Nickname))
  52. {
  53. AddChannel(info.Channel);
  54. AddNick(info.Nick);
  55. string query = "INSERT INTO `channeljoins` SET " +
  56. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  57. "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
  58. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nicks`.`nickname` = {4}), " +
  59. "`date_added` = {5}";
  60. Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, info.TimeStamp });
  61. }
  62. }
  63. private void LogChannelPart(object sender, PartChannelInfo info)
  64. {
  65. if (!ChannelBlacklist.Contains(info.Channel)
  66. && !NickBlacklist.Contains(info.Nick.Nickname))
  67. {
  68. AddChannel(info.Channel);
  69. AddNick(info.Nick);
  70. string query = "INSERT INTO `channelparts` SET " +
  71. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  72. "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
  73. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
  74. "`date_added` = {5}";
  75. Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, info.TimeStamp });
  76. }
  77. }
  78. private void LogChannelKick(object sender, KickInfo info)
  79. {
  80. if (!ChannelBlacklist.Contains(info.Channel)
  81. && !NickBlacklist.Contains(info.KickedNick.Nickname))
  82. {
  83. AddChannel(info.Channel);
  84. AddNick(info.Nick);
  85. AddNick(info.KickedNick);
  86. string query = "INSERT INTO `channelkicks` SET " +
  87. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  88. "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
  89. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
  90. "`kicked_nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {5} && `nickname` = {6}), " +
  91. "`reason` = {7}, " +
  92. "`date_added` = {8}";
  93. Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, Bot.ServerConfig.Name, info.KickedNick.Nickname, info.Reason, info.TimeStamp });
  94. }
  95. }
  96. private void LogQuit(object sender, QuitInfo info)
  97. {
  98. if (!NickBlacklist.Contains(info.Nick.Nickname))
  99. {
  100. AddNick(info.Nick);
  101. string query = "INSERT INTO `quits` SET " +
  102. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  103. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {1} && `nickname` = {2}), " +
  104. "`message` = {3}, " +
  105. "`date_added` = {4}";
  106. Bot.Database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Nick.Nickname, info.Message, info.TimeStamp});
  107. }
  108. }
  109. }
  110. }