const prefix = "s!";
var daily = dailies();
bot.on("message", function (msg) {
if (message.author.bot) return;
if (msg.content.toLowerCase = prefix + "dailies") { daily }
});
function dailies() {
sql, get(`SELECT * FROM scores WHERE userId ="${message.author.id}"`).then(row => {
if (!row) {
sql.run("INSERT INTO scores (userId, daily, points, wr, rotw) VALUES (?, ?, ?, ?, ?)", [message.author.id, 1, 200, 0, 0]);
msg.channel.send('Thank you for joining Playing Destiny Fast! You have 200 glimmer available!');
} else if (row.daily === 1) {
msg.channel.send('You have already accepted your 200 glimmer today! Come back after the daily reset (9am PST) to claim again.');
} else {
sql.run(`UPDATE scores SET glimmer = ${row.glimmer + 200}, daily = 1, WHERE userId = ${message.author.id}`);
msg.channel.send('${message.author.id} has claimed their 200 daily glimmer! Total: ${row.glimmer}');
}
reset.setInterval(function () {
var date = new Date();
if (date.getHours() === 15 && date.getMinutes() === 0) {
sql.run(`UPDATE scores SET daily = 0`);
}
}, 60000);
});
此代码的目标是让用户在聊天中输入s!dailies
并让机器人正确响应。如果用户从未参与,则应使用其信息创建新行。如果用户自从UTC时间(太平洋标准时间上午9点)开始参与,则代码应该响应每日奖励不可用。如果用户没有参与,那么代码应该更新他们的glimmer
货币,确认他们已经收到了每日奖励,并向渠道显示总数。最后,机器人应该每分钟检查一下,看看时间是UTC还是下午4点或下午3点。我相信这是JavaScript的标准时区,并以24小时格式进行记录。
我对SQL和JavaScript一般都很陌生,所以我不确定如何调整以下代码以满足我的需求。
具体来说,在使用date
功能时,JavaScript是否默认为UTC时区的24小时格式?其次,我的脚本会更改每个用户记录的daily
值吗?如果没有,我怎么能只使用JavaScript和SQL呢?