-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathcounter.js
30 lines (27 loc) · 1.02 KB
/
counter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const { db } = require("quick.eco");
function counter(message, client) {
let channel = message.channel;
let count = db.fetch(`counter_${message.guild.id}`);
if (count === null) count = db.set(`counter_${message.guild.id}`, {
number: 0,
author: client.user.id
});
if (!message.author.bot && message.author.id === count.author) {
message.delete();
message.reply("Please wait for your turn").then(m => m.delete(3000));
return;
}
if (!message.author.bot && isNaN(message.content)) {
message.delete();
message.reply("messages in this channel must be a number").then(m => m.delete(3000));
return;
}
if (!message.author.bot && parseInt(message.content) !== count.number + 1) {
message.delete();
message.reply(`next number must be ${count.number + 1}`).then(m => m.delete(3000));
return;
}
count = db.set(`counter_${message.guild.id}`, { number: count.number + 1, author: message.author.id });
channel.setTopic(`Next number must be ${count.number + 1}.`);
}
module.exports = counter;