SHARE
TWEET

Untitled

a guest May 19th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require('discord.js');
  2. const fs = require('fs')
  3. const token = 'NTc4NDQwNzI0NDU5MTU5NTky.XNzpAw.jtVMnrjWr_rcktX7QvrWJbdjFto';
  4.  
  5. const client = new Discord.Client();
  6.  
  7. function checkExist(username) {
  8.     let rawdata = fs.readFileSync('data.json');
  9.     let s = JSON.parse(rawdata);
  10.     for(var i = 0; i < s.length; ++i) {
  11.         if(s[i].name === username) {
  12.             return true;
  13.         }
  14.     }
  15.     return false;
  16. }
  17.  
  18. function Register(username) {
  19.  
  20.     let rawdata = fs.readFileSync('data.json');
  21.     let s = JSON.parse(rawdata);
  22.  
  23.     for(var i = 0; i < s.length; ++i) {
  24.         if(s[i].name === username) {
  25.             return false;
  26.         }
  27.     }
  28.  
  29.     let user = {
  30.         name: username,
  31.         count: 0
  32.     }
  33.  
  34.     s.push(user);
  35.  
  36.     let data = JSON.stringify(s, null, 2);
  37.    
  38.     fs.writeFile('data.json', data, (err) => {  
  39.         if (err) throw err;
  40.         console.log('Data written to file');
  41.     });
  42.     console.log("register success")
  43.     return true;
  44.  
  45. }
  46.  
  47. function NibbaCore(username, count, writetodata) {
  48.  
  49.     let rawdata = fs.readFileSync('data.json');
  50.     let s = JSON.parse(rawdata);
  51.  
  52.     if(!writetodata) {
  53.         for(var i = 0; i < s.length; ++i) {
  54.  
  55.             if(s[i].name === username) {
  56.                 return s[i].count;
  57.             }
  58.         }
  59.     } else {
  60.         for(var i = 0; i < s.length; ++i) {
  61.    
  62.             if(s[i].name === username) {
  63.                 s[i].count = s[i].count + count;
  64.                 var temp = s[i].count;
  65.             }
  66.         }
  67.     }
  68.    
  69.     let data = JSON.stringify(s, null, 2);
  70.    
  71.     fs.writeFile('data.json', data, (err) => {  
  72.         if (err) throw err;
  73.         console.log('Data written to file');
  74.     });
  75.  
  76.     return temp;
  77. }
  78.  
  79. function getTotal() {
  80.     let rawdata = fs.readFileSync('data.json');
  81.     let s = JSON.parse(rawdata);
  82.     let total = 0;
  83.     for(var i = 0; i < s.length; ++i) {
  84.         total = total + s[i].count;
  85.     }
  86.  
  87.     return total;
  88. }
  89.  
  90. client.on('message', (msg) => {
  91.     //console.log(msg.member.displayName)
  92.     var user = msg.author;
  93.     var username = user.username;
  94.     if(checkExist(username)) {
  95.         var temp = msg.content.toLowerCase();
  96.         var count = (temp.match(/nigger/g) || []).length;
  97.    
  98.         if(count > 0) {
  99.             msg.channel.send(user + ' You just said nigger ' + count + ' time(s), you have now said nigger:');
  100.             const embed = new Discord.RichEmbed()
  101.             .setTitle(NibbaCore(username, count, true)  + " times")
  102.             .setColor('#000000')
  103.             //msg.channel.send(embed);
  104.             msg.channel.send(embed);
  105.         }
  106.     }
  107.     const embed = new Discord.RichEmbed()
  108.     if(msg.content === "!help") {
  109.         const embed = new Discord.RichEmbed()
  110.         .setTitle("The Nibba Menu")
  111.         .setDescription("!register - register\n !count - display count\n !total - number of times nigger was said in the channel")
  112.         .setColor('#000000')
  113.         msg.channel.send(embed);
  114.     }
  115.     if(msg.content === "!register") {
  116.         if(Register(username)) {
  117.             msg.channel.send(user + ' You have been successfully registered!');
  118.             //msg.channel.send(embed);
  119.         } else {
  120.             msg.channel.send(user + " You're registered already, fucking nigger");
  121.             //msg.channel.send(embed);
  122.         }
  123.     }
  124.  
  125.     if(msg.content === "!count"){
  126.  
  127.         if(checkExist(username)){
  128.             const embed = new Discord.RichEmbed()
  129.             .setTitle(NibbaCore(username,0,false)  + " times")
  130.             .setColor('#000000')
  131.             //msg.channel.send(embed);
  132.             msg.channel.send(user + ' Has said nigger');
  133.             msg.channel.send(embed);
  134.         } else {
  135.             msg.channel.send(user + ' Are not registered, type !register to register');
  136.         }
  137.     }
  138.  
  139.     if(msg.content === "!total") {
  140.         const embed = new Discord.RichEmbed()
  141.         .setTitle("This channel has said nigger a total of: ")
  142.         .setDescription(getTotal() + " time(s)")
  143.         .setColor('#000000')
  144.  
  145.         msg.channel.send(embed)
  146.     }
  147.  
  148. });
  149.  
  150. client.on('ready', () => {
  151.     console.log('Bot is now connected');
  152. });
  153.  
  154. client.login(token);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top