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] })
});
}
});
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"]
}
return interaction.reply({ content: Попробуйте снова через \`${data.time}\``)
});