JohnTomah

Untitled

Mar 14th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. client.on("message", message => {
  2.     if (message.author.bot || !message.guild) return;
  3. var prefix = '#'
  4.     let score;
  5.    
  6.     if (message.guild) {
  7.       score = client.getScore.get(message.author.id, message.guild.id);
  8.       if (!score) {
  9.         score = { id: `${message.guild.id}-${message.author.id}`, user: message.author.id, guild: message.guild.id, points: 0, level: 1 };
  10.       }
  11.       score.points++;
  12.       const curLevel = Math.floor(0.1 * Math.sqrt(score.points));
  13.       client.setScore.run(score);
  14.     }
  15.     if (message.content.indexOf(prefix) !== 0) return;
  16.  
  17.     const args = message.content.slice(prefix.length).trim().split(/ +/g);
  18.     const command = args.shift().toLowerCase();
  19.  
  20.     if(command === "points") {
  21.       return message.reply(`You currently have ${score.points} points and are level ${score.level}!`);
  22.     }
  23.    
  24.     if(command === "give") {
  25.       if(!message.author.id === message.guild.owner) return message.reply("You're not the boss of me, you can't do that!");
  26.       const user = message.mentions.users.first() || client.users.get(args[0]);
  27.       if(!user) return message.reply("You must mention someone or give their ID!");
  28.       const pointsToAdd = parseInt(args[1], 10);
  29.       if(!pointsToAdd) return message.reply("You didn't tell me how many points to give...");
  30.           let userscore = client.getScore.get(user.id, message.guild.id);      
  31.       if (!userscore) {
  32.         userscore = { id: `${message.guild.id}-${user.id}`, user: user.id, guild: message.guild.id, points: 0, level: 1 };
  33.       }
  34.       userscore.points += pointsToAdd;
  35.       let userLevel = Math.floor(0.1 * Math.sqrt(score.points));
  36.       userscore.level = userLevel;
  37.       client.setScore.run(userscore);
  38.    
  39.       return message.channel.send(`${user.tag} has received ${pointsToAdd} points and now stands at ${userscore.points} points.`);
  40.     }
  41.    
  42.     if(command === "top") {
  43.       const top10 = sql.prepare("SELECT * FROM scores WHERE guild = ? ORDER BY points DESC LIMIT 10;").all(message.guild.id);
  44.       const embed = new Discord.RichEmbed()
  45.         .setTitle("**TOP 10 TEXT** :speech_balloon:")
  46.         .setAuthor('📋 Guild Score Leaderboards', message.guild.iconURL)
  47.         .setColor(0x00AE86);
  48.  
  49.       for(const data of top10) {
  50.         embed.addField(client.users.get(data.user).tag, `XP: \`${data.points}\` | LVL: \`${data.level}\``);
  51.       }
  52.       return message.channel.send({embed});
  53.     }
  54.    
  55.   });
Advertisement
Add Comment
Please, Sign In to add comment