const talkedRecently = new Set();
if(message.content.startsWith(prefix + "day")) {
if (talkedRecently.has(message.author.id)) {
message.channel.send({ content: Вы уже использовали эту команду. Повторите через 24 часа
})
} else {
message.channel.send({ content: Успешно })
talkedRecently.add(message.author.id);
setTimeout(() => {
talkedRecently.delete(message.author.id);
}, 86400000);
}
}
pool.query(`SELECT date_added FROM moneys WHERE UserID = ${interaction.user.id} AND GuildID = ${interaction.guild.id}`, async function (err, result, fields) {
if (err) throw err;
if (result.length > 0) {
if (result[0]['date_added'] === null) {
pool.query(`UPDATE moneys SET Moneyscol = Moneyscol + 500, date_added = NOW(), date_next = (NOW() + INTERVAL 1 DAY) WHERE UserID = ${interaction.user.id} AND GuildID = ${interaction.guild.id}`, async function (err, result, fields) {
if (err) throw err;
return interaction.reply({ content: "Успешно" })
});
} else {
pool.query(`UPDATE moneys SET date_added = NOW() WHERE UserID = ${interaction.user.id} AND GuildID = ${interaction.guild.id}`, async function (err, result, fields) {
if (err) throw err;
pool.query(`SELECT date_added, date_next FROM moneys WHERE UserID = ${interaction.user.id} AND GuildID = ${interaction.guild.id}`, async function (err, result, fields) {
if (err) throw err;
if (result[0]['date_added'] >= result[0]['date_next']) {
pool.query(`UPDATE moneys SET Moneyscol = Moneyscol + 500, date_added = NOW(), date_next = (NOW() + INTERVAL 1 DAY) WHERE UserID = ${interaction.user.id} AND GuildID = ${interaction.guild.id}`, async function (err, result, fields) {
if (err) throw err;
return interaction.reply({ content: "Успешно" })
});
} else {
pool.query(`SELECT TIME_FORMAT(TIMEDIFF(date_next, date_added), '%H ч, %i мин, %s сек') as time from moneys WHERE UserID = ${interaction.user.id} AND GuildID = ${interaction.guild.id}`, async function (err, result, fields) {
if (err) throw err;
const data = {
time: result[0]["time"]
}
let embed = new MessageEmbed()
.setColor("#FF0000")
.setTitle(`${interaction.member.displayName}`)
.setDescription(`Вы уже использовали эту команду. Попробуйте снова через \`${data.time}\``)
.setThumbnail(interaction.user.displayAvatarURL())
.setTimestamp(new Date())
return interaction.reply({ embeds: [embed] })
});
}
});
});
}
} else {
pool.query(`INSERT INTO moneys (GuildID, UserID, Moneyscol, date_added, date_next) VALUES (${interaction.guild.id}, ${interaction.user.id}, 500, NOW(), (NOW() + INTERVAL 1 DAY))`, async function (err, result, fields) {
if (err) throw err;
let embed = new MessageEmbed()
.setColor("#FFCC4D")
.setTitle(`${interaction.member.displayName}`)
.setDescription(`Вы получили ежедневный бонус в размере \`500\` :coin:`)
.setThumbnail(interaction.user.displayAvatarURL())
.setTimestamp(new Date())
return interaction.reply({ embeds: [embed] })
});
}
});
let talkedRecently = 0;
let talkedRecentlyDAYS = 0;
let talkedRecentlyHOURS = 0;
let talkedRecentlyMINUTES = 0;
let talkedRecentlySECUNDES = 0;
if(message.content.startsWith(prefix + "day")) {
if (talkedRecently > 0) {
message.channel.send(`Вы уже использовали эту команду. Повторите через ${Math.floor(talkedRecentlyDAYS)} дней / ${Math.floor(talkedRecentlyHOURS)} часов / ${Math.floor(talkedRecentlyMINUTES)} минут / ${talkedRecentlySECUNDES} секунд.`)
} else {
message.channel.send("Успешно!")
talkedRecently = 86400000;
talkedRecentlyDAYS = talkedRecently/86400000;
let time = setInterval(() => {
if (talkedRecently <= 0) { clearInterval(time); return; }
talkedRecentlySECUNDES -= 1;
if (talkedRecentlySECUNDES < 0) { talkedRecentlySECUNDES = 59; talkedRecentlyMINUTES -= 1; }
if (talkedRecentlyMINUTES < 0) { talkedRecentlyMINUTES = 59; talkedRecentlyHOURS -= 1; }
if (talkedRecentlyHOURS < 0) { talkedRecentlyHOURS = 23; talkedRecentlyDAYS -= 1; }
talkedRecently -= 1000;
}, 1000);
}
}