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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. Bot.IRC.Message.NickChangeEvent += LogNickChange;
  19. }
  20. private void LogChannelMessage(object sender, ChannelMessage message)
  21. {
  22. if (!ChannelBlacklist.Contains(message.Channel)
  23. && !NickBlacklist.Contains(message.Sender.Nickname))
  24. {
  25. AddChannel(message.Channel);
  26. AddNick(message.Sender);
  27. string query = "INSERT INTO `channelmessages` SET " +
  28. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  29. "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
  30. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
  31. "`message` = {5}, " +
  32. "`date_added` = {6}";
  33. Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, message.Channel, Bot.ServerConfig.Name, message.Sender.Nickname, message.Message, message.TimeStamp });
  34. }
  35. }
  36. private void LogPrivateMessage(object sender, PrivateMessage message)
  37. {
  38. if (!NickBlacklist.Contains(message.Sender.Nickname))
  39. {
  40. AddNick(message.Sender);
  41. string query = "INSERT INTO `privatemessages` SET " +
  42. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  43. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {1} && `nickname` = {2}), " +
  44. "`message` = {3}, " +
  45. "`date_added` = {4}";
  46. Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, message.Sender.Nickname, message.Message, message.TimeStamp });
  47. }
  48. }
  49. private void LogChannelJoin(object sender, JoinChannelInfo info)
  50. {
  51. if (!ChannelBlacklist.Contains(info.Channel)
  52. && !NickBlacklist.Contains(info.Nick.Nickname))
  53. {
  54. AddChannel(info.Channel);
  55. AddNick(info.Nick);
  56. string query = "INSERT INTO `channeljoins` SET " +
  57. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  58. "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
  59. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nicks`.`nickname` = {4}), " +
  60. "`date_added` = {5}";
  61. Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, info.TimeStamp });
  62. }
  63. }
  64. private void LogChannelPart(object sender, PartChannelInfo info)
  65. {
  66. if (!ChannelBlacklist.Contains(info.Channel)
  67. && !NickBlacklist.Contains(info.Nick.Nickname))
  68. {
  69. AddChannel(info.Channel);
  70. AddNick(info.Nick);
  71. string query = "INSERT INTO `channelparts` SET " +
  72. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  73. "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
  74. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
  75. "`date_added` = {5}";
  76. Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, info.TimeStamp });
  77. }
  78. }
  79. private void LogChannelKick(object sender, KickInfo info)
  80. {
  81. if (!ChannelBlacklist.Contains(info.Channel)
  82. && !NickBlacklist.Contains(info.KickedNick.Nickname))
  83. {
  84. AddChannel(info.Channel);
  85. AddNick(info.Nick);
  86. AddNick(info.KickedNick);
  87. string query = "INSERT INTO `channelkicks` SET " +
  88. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  89. "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
  90. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
  91. "`kicked_nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {5} && `nickname` = {6}), " +
  92. "`reason` = {7}, " +
  93. "`date_added` = {8}";
  94. 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 });
  95. }
  96. }
  97. private void LogQuit(object sender, QuitInfo info)
  98. {
  99. if (!NickBlacklist.Contains(info.Nick.Nickname))
  100. {
  101. AddNick(info.Nick);
  102. string query = "INSERT INTO `quits` SET " +
  103. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  104. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {1} && `nickname` = {2}), " +
  105. "`message` = {3}, " +
  106. "`date_added` = {4}";
  107. Bot.Database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Nick.Nickname, info.Message, info.TimeStamp});
  108. }
  109. }
  110. private void LogNickChange(object sender, NickChangeInfo info)
  111. {
  112. if (!NickBlacklist.Contains(info.OldNick.Nickname) && !NickBlacklist.Contains(info.NewNick.Nickname))
  113. {
  114. AddNick(info.NewNick);
  115. }
  116. }
  117. }
  118. }