The easy to use and full featured Irc Bot everyone is talking about!
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Logging.cs 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.CommandReceivedEvent += HandleCommandEvent;
  12. Bot.IRC.ConnectEvent += AddServer;
  13. Bot.IRC.Message.ChannelMessageReceivedEvent += LogChannelMessage;
  14. Bot.IRC.Message.PrivateMessageReceivedEvent += LogPrivateMessage;
  15. Bot.IRC.Message.JoinChannelEvent += LogChannelJoin;
  16. Bot.IRC.Message.PartChannelEvent += LogChannelPart;
  17. Bot.IRC.Message.KickEvent += LogChannelKick;
  18. Bot.IRC.Message.QuitEvent += LogQuit;
  19. }
  20. public override void ParseCommand(CommandMessage command)
  21. {
  22. Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command));
  23. }
  24. private void LogChannelMessage(object sender, ChannelMessage message)
  25. {
  26. AddChannel(message.Channel);
  27. AddNick(message.Sender.Nickname);
  28. Database database = new Database(Bot.ServerConfig.Database);
  29. string query = "INSERT INTO `channelmessages` SET " +
  30. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  31. "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
  32. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
  33. "`message` = {5}, " +
  34. "`date_added` = {6}";
  35. database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, message.Channel, Bot.ServerConfig.Name, message.Sender.Nickname, message.Message, message.TimeStamp});
  36. }
  37. private void LogPrivateMessage(object sender, PrivateMessage message)
  38. {
  39. AddNick(message.Sender.Nickname);
  40. Database database = new Database(Bot.ServerConfig.Database);
  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. database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, message.Sender.Nickname, message.Message, message.TimeStamp});
  47. }
  48. private void LogChannelJoin(object sender, JoinChannelInfo info)
  49. {
  50. AddChannel(info.Channel);
  51. AddNick(info.Nick.Nickname);
  52. Database database = new Database(Bot.ServerConfig.Database);
  53. string query = "INSERT INTO `channeljoins` SET " +
  54. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  55. "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
  56. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
  57. "`date_added` = {5}";
  58. database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, info.TimeStamp});
  59. }
  60. private void LogChannelPart(object sender, PartChannelInfo info)
  61. {
  62. AddChannel(info.Channel);
  63. AddNick(info.Nick.Nickname);
  64. Database database = new Database(Bot.ServerConfig.Database);
  65. string query = "INSERT INTO `channelparts` SET " +
  66. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  67. "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
  68. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
  69. "`date_added` = {5}";
  70. database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, info.TimeStamp});
  71. }
  72. private void LogChannelKick(object sender, KickInfo info)
  73. {
  74. AddChannel(info.Channel);
  75. AddNick(info.Nick.Nickname);
  76. AddNick(info.KickedNick.Nickname);
  77. Database database = new Database(Bot.ServerConfig.Database);
  78. string query = "INSERT INTO `channelkickss` SET " +
  79. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  80. "`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
  81. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
  82. "`kicked_nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {5} && `nickname` = {6}), " +
  83. "`reason` = {7}, " +
  84. "`date_added` = {8}";
  85. 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});
  86. }
  87. private void LogQuit(object sender, QuitInfo info)
  88. {
  89. AddNick(info.Nick.Nickname);
  90. Database database = new Database(Bot.ServerConfig.Database);
  91. string query = "INSERT INTO `quits` SET " +
  92. "`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
  93. "`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {1} && `nickname` = {2}), " +
  94. "`message` = {3}, " +
  95. "`date_added` = {4}";
  96. database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Nick.Nickname, info.Message, info.TimeStamp});
  97. }
  98. }
  99. }