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 9.0KB

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