Advertisement
zs13213134

Untitled

Oct 10th, 2021
1,152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 3.91 KB | None | 0 0
  1. const Discord = require("discord.js");
  2. const bot = new Discord.Client();
  3. const st = require('settings.json')
  4. var mysql = require('mysql');
  5. var replaceall = require("replaceall");
  6.  
  7.  
  8. var con = mysql.createConnection({
  9.   host: st.dbhost,
  10.   user: st.dbuser,
  11.   password: st.dbuser,
  12.   database: st.database,
  13.   charset: "utf8mb4"
  14. });
  15.  
  16.  
  17. function mysqlEscape(stringToEscape){
  18.     return stringToEscape
  19.         .replace("\\", "\\\\")
  20.         .replace("\'", "\\\'")
  21.         .replace("\"", "\\\"")
  22.         .replace("\n", "\\\n")
  23.         .replace("\r", "\\\r")
  24.         .replace("\x00", "\\\x00")
  25.         .replace("\x1a", "\\\x1a")
  26. }
  27.  
  28. function replaceSzarok(stringToReplace) {
  29.     return replaceall("'", '"', stringToReplace);
  30. }
  31.  
  32. function getFormattedDate() {
  33.     var date = new Date();
  34.     var str = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " +  date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
  35.     return str;
  36. }
  37.  
  38. con.connect(function(err) {
  39.   if (err) console.log(err);
  40. });
  41.  
  42. bot.on("ready", () => {
  43.   bot.user.setStatus(st.status);
  44.   console.log("Discord Userbot logger, rewritten by Levente#6914\nOriginal code by: palmarci\nStarted on:", getFormattedDate());
  45. });
  46.  
  47. bot.on("message", (message) => {
  48.  
  49.  if (message.author.id !== bot.user.id)
  50.     {
  51.         var Attachment = (message.attachments).array();
  52.         var hasImage = false;
  53.         var imageUrl = "None";
  54.  
  55.         Attachment.forEach(function(attachment) {
  56.             imageUrl = attachment.url;
  57.             hasImage = true;
  58.         })
  59.  
  60.     sqlquerry= "INSERT INTO `messages` (`ID`, `timestamp`, `author_id`, `author_name`, `message`, `channel_name`, `guild`, `has_image`, `image_url`) VALUES (NULL, '" + getFormattedDate() + ".000000', '"message.author.id"' '"+mysqlEscape(replaceSzarok(message.author.username))+"#"+message.author.discriminator+"', '"+mysqlEscape(replaceSzarok(message.content))+"', '"+mysqlEscape(replaceSzarok(message.channel.name))+"', '"+mysqlEscape(replaceSzarok(message.guild.name))+"', '"+hasImage+"', '"+imageUrl+"')"
  61.  
  62.         /*if(hasImage) {
  63.       sqlquerry= "INSERT INTO `messages` (`ID`, `timestamp`, `author_id`, `author_name`, `message`, `channel_name`, `guild`, `has_image`, `image_url`) VALUES (NULL, '" + getFormattedDate() + ".000000', '"message.author.id"' '"+mysqlEscape(replaceSzarok(message.author.username))+"#"+message.author.discriminator+"', '"+mysqlEscape(replaceSzarok(message.content))+"', '"+mysqlEscape(replaceSzarok(message.channel.name))+"', '"+mysqlEscape(replaceSzarok(message.guild.name))+"', '"+hasImage+"', '"+imageUrl+"')"
  64.             //sqlquerry = "INSERT INTO `messages`(`ID`, `timestamp`, `author_id`, `author_name`, `message`, `channel_name`, `has_image`, `image_url`) VALUES (NULL, '" + getFormattedDate() + ".000000', " + message.author.id + ", '" + mysqlEscape(replaceSzarok(message.author.username)) + "', '"+ mysqlEscape(replaceSzarok(message.content)) + "', '" + "" + message.channel.name + "', " + hasImage + ", '" + imageUrl + "')";
  65.         } else {
  66.       sqlquerry= "INSERT INTO `messages` (`ID`, `timestamp`, `author_id`, `author_name`, `message`, `channel_name`, `guild`, `has_image`, `image_url`) VALUES (NULL, '" + getFormattedDate() + ".000000', '"message.author.id"' '"+mysqlEscape(replaceSzarok(message.author.username))+"#"+message.author.discriminator+"', '"+mysqlEscape(replaceSzarok(message.content))+"', '"+mysqlEscape(replaceSzarok(message.channel.name))+"', '"+mysqlEscape(replaceSzarok(message.guild.name))+"', '"+hasImage+"', '"+imageUrl+"')"
  67.             //sqlquerry = "INSERT INTO `messages`(`ID`, `timestamp`, `author_id`, `author_name`, `message`, `channel_name`) VALUES (NULL, '" + getFormattedDate() + ".000000', " + message.author.id + ", '" + mysqlEscape(replaceSzarok(message.author.username)) + "', '"+ mysqlEscape(replaceSzarok(message.content)) + "', '" + "" + message.channel.name + "')";
  68.         }*/
  69.  
  70.         con.query(sqlquerry), function (err, result, fields)
  71.         {
  72.             if (err) throw err;
  73.         }
  74.     }
  75. });
  76.  
  77. bot.login(st.token);
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement