Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const SQLite = require("better-sqlite3");
- const sql = new SQLite('./src/db.sqlite');
- client.on('ready', () => {
- const table = sql.prepare("SELECT count(*) FROM sqlite_master WHERE type='table' AND name = 'scores';").get();
- if (!table['count(*)']) {
- sql.prepare("CREATE TABLE scores (id TEXT PRIMARY KEY, user TEXT, guild TEXT, points INTEGER);").run();
- sql.prepare("CREATE UNIQUE INDEX idx_scores_id ON scores (id);").run();
- sql.pragma("synchronous = 1");
- sql.pragma("journal_mode = wal");
- }
- client.getScore = sql.prepare("SELECT * FROM scores WHERE user = ? AND guild = ?");
- client.setScore = sql.prepare("INSERT OR REPLACE INTO scores (id, user, guild, points) VALUES (@id, @user, @guild, @points);");
- });
- client.on("message", async (message) => {
- // Check Catnips
- if(command === "catnips") {
- return message.reply(`You currently have ${score.points} catnips!`);
- }
- // Leaderboard
- if(command === "lb") {
- const top10 = sql.prepare("SELECT * FROM scores WHERE guild = ? ORDER BY points DESC LIMIT 10;").all(message.guild.id);
- const embed = new MessageEmbed()
- .setTitle("Leaderboard")
- .setDescription("Our top 10 catnip leaders!")
- .setColor(emcolor);
- for(const data of top10) {
- embed.addField(client.users.get(data.user).tag, `${data.points} catnips`);
- }
- return message.channel.send({embed});
- }
- // Give Points
- if(command === "give") {
- if(message.author.id !== cfg.owner) return;
- const user = message.mentions.users.first() || client.users.get(args[0]);
- if(!user) return message.reply("You must mention someone or give their ID!");
- const pointsToAdd = parseInt(args[1], 10);
- if(!pointsToAdd) return message.reply("You didn't tell me how many points to give...")
- let userscore = client.getScore.get(user.id, message.guild.id);
- if (!userscore) {
- userscore = { id: `${message.guild.id}-${user.id}`, user: user.id, guild: message.guild.id, points: 0, level: 1 }
- }
- userscore.points += pointsToAdd;
- let userLevel = Math.floor(0.1 * Math.sqrt(score.points));
- userscore.level = userLevel;
- client.setScore.run(userscore);
- return message.channel.send(`${user.tag} has received ${pointsToAdd} catnips and now stands at ${userscore.points} catnips.`);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement