Advertisement
Mox-L

credit like probot

Apr 10th, 2020
4,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. const Canvas = require('canvas')
  3. const credits = JSON.parse(fs.readFileSync("./credits.json"));
  4. var time = require("./time.json");
  5. client.on("message", async message => {
  6.   if (message.author.bot || message.channel.type === "dm") return;
  7.   let args = message.content.split(" ");
  8.   let author = message.author.id;
  9.   if (!credits[author])
  10.     credits[author] = {
  11.       credits: 0
  12.     };
  13.   fs.writeFileSync("./credits.json", JSON.stringify(credits, null, 4));
  14. if (args[0].toLowerCase() == `${prefix}credits` ||
  15. args[0].toLowerCase() === `${prefix}credit` ||
  16. args[0].toLowerCase() === `c`
  17.  
  18. ) {
  19.     const mention = message.mentions.users.first() || message.author;
  20.     const mentionn = message.mentions.users.first();
  21.     if (!args[2]) {
  22.       message.channel.send(
  23.         `**:bank: | ${mention.username}, Your :credit_card: balance is \`$${credits[mention.id].credits}\`**`
  24.       );
  25.     } else if (mentionn && args[2]) {
  26.       if (isNaN(args[2])) return message.channel.send(`** :interrobang: | ${message.author.username}, i can't find it!**`);
  27.      if (args[2] < 1) return message.channel.send(`** :interrobang: | ${message.author.username}, type the credit you need to transfer!**`);
  28.      if (mention.bot) return message.channel.send(`**:thinking: | ${message.author.username}, bots do not have credits**`);
  29.      if (mentionn.id === message.author.id)
  30.        return message.channel.send(`**:interrobang: | ${message.author.username}, I can't find User **`);
  31.       if (args[2] > credits[author].credits)
  32.         return message.channel.send(
  33.           `**:thinking: | ${message.author.username}, Your balance is not enough for that!**`
  34.         );
  35.       if (args[2].includes("-")) return message.channel.send(`**:interrobang: | ${message.author.username}, type the credit you need to transfer!**`);
  36.       //let resulting = Math.floor(args[2] - args[2] * (5 / 100));
  37.       let tax = Math.floor(args[2] * (5 / 100));
  38.       let first = Math.floor(Math.random() * 10);
  39.       let second = Math.floor(Math.random() * 10);
  40.       let third = Math.floor(Math.random() * 10);
  41.       let fourth = Math.floor(Math.random() * 10);
  42.       let num = `${ first }${ second }${ third }${ fourth }`;
  43.       let canvas = Canvas.createCanvas(100, 50);
  44.       let ctx = canvas.getContext("2d");
  45.  //let tax = message.content.split(" ")[1]
  46. let Price = message.content.split(" ")[2];
  47.  //tax = tax.replace(/%5/g,"");
  48. let resulting = Math.floor(Price-(Price*(5/100)));      const background = await Canvas.loadImage(
  49.         "https://cdn.discordapp.com/attachments/365219235288317962/656362038884565014/captcha.png"
  50.       );
  51.       ctx.drawImage(background, 6, 3, canvas.width, canvas.height);
  52.       ctx.font = "25px Tahoma";
  53.           ctx.fontSize = "7px";
  54.           ctx.fillStyle = "Yellow";
  55. message.delete();
  56.      //let resulting = Math.floor(Price-(Price*(5/100)));
  57.       message.channel.send(`**${message.author.username}, Transfer Fees \`${tax}\`, Amount :\`${resulting}\` **
  58.    type these numbers to confirm : `
  59. ).then(m => {
  60.  
  61.           ctx.fillText(num, canvas.width / 4.8, canvas.height / 1.5);
  62.           message.channel.sendFile(canvas.toBuffer()).then(s => {
  63.             message.channel
  64.               .awaitMessages(r => r.author.id === message.author.id, {
  65.                 max: 1,
  66.                 time: 20000,
  67.                 errors: ["time"]
  68.              
  69.               })
  70.  
  71.               .then(collected => {
  72.  
  73.                 if (collected.first().content === num) {
  74.  
  75.                   message.channel.send(
  76.                     `**:moneybag: | ${
  77.                       message.author.username
  78.                     }, has transferred \`$${resulting}\` to ${mentionn}**`
  79.                   );           m.delete();
  80. s.delete();
  81.                   mention.send(
  82.                     `**:atm: | Transfer Receipt**\`\`\`You Have Received \$${resulting}\ From User ${message.author.username}; (ID ${    message.author.id     })\`\`\``);
  83.   m.delete();
  84. s.delete();
  85.  
  86.                   credits[author].credits += Math.floor(
  87.                     -resulting
  88.                   );
  89.                   credits[mentionn.id].credits += Math.floor(
  90.                     +resulting
  91.                   );
  92.                   fs.writeFileSync(
  93.                     "./credits.json",
  94.                     JSON.stringify(credits, null, 4)
  95.                   );
  96.                 } else {
  97.                   m.delete();
  98.                 }
  99.               });
  100.           });
  101.         });
  102.     }
  103.   }
  104.  
  105.   if (args[0].toLowerCase() === `${prefix}daily` ||
  106.  args[0].toLowerCase() === `d`
  107. ) {
  108.     let cooldown = 8.64e7;
  109.     let Daily = time[message.author.id];
  110.     if (Daily !== null && cooldown - (Date.now() - Daily) > 0) {
  111.       let times = cooldown - (Date.now() - Daily);
  112.       message.channel.send( `**:rolling_eyes: | ${ message.author.username }, your daily credits refreshes in \'${pretty(times, { verbose: true })}'.\**`);
  113.       fs.writeFile("./time.json", JSON.stringify(time), function(e) {
  114.         if (e) throw e;
  115.       });
  116.     } else {
  117.       let ammount = (300, 500, 100, 200, 120, 150, 350, 320, 220, 250);
  118.       credits[author].credits += ammount;
  119.       time[message.author.id] = Date.now();
  120.       message.channel.send(
  121.         `**:moneybag: ${message.author.username}, You got :dollar: ${ammount} daily credits!**`
  122.       );
  123.       fs.writeFile("./credits.json", JSON.stringify(credits), function(e) {
  124.         if (e) throw e;
  125.       });
  126.     }
  127.   }
  128. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement