From fe144096a1c69f40001d50dbb342e2c357088f74 Mon Sep 17 00:00:00 2001 From: smsteel Date: Tue, 19 Feb 2019 23:49:05 +0300 Subject: [PATCH] husk --- bot.js | 25 ++++++++++++------------- data.js | 2 ++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/bot.js b/bot.js index f3c9d58..b0bc980 100644 --- a/bot.js +++ b/bot.js @@ -60,13 +60,14 @@ const sendMessageToAll = text => getChats() const JOIN_NOTIFICATION_TIME_DELTA = 60 * 60 // 1h const LEVEL_NOFIFICATION_EACH_LEVELS = 5 -export const sendEvent = ({ type, displayName, ...payload }) => { +export const sendEvent = async ({ type, displayName, ...payload }) => { switch (type) { case EVENT_TYPE_JOIN: setOnlineState(displayName) - getLastLogoutTime(displayName) - .then(lastLogoutTime => lastLogoutTime < currentTime() - JOIN_NOTIFICATION_TIME_DELTA && - sendMessageToAll(`👤 *${displayName}* присоединился 😼`)) + const lastLogoutTime = await getLastLogoutTime(displayName) + if (lastLogoutTime < currentTime() - JOIN_NOTIFICATION_TIME_DELTA) { + sendMessageToAll(`👤 *${displayName}* присоединился 😼`) + } break case EVENT_TYPE_QUIT: setOfflineState(displayName) @@ -81,7 +82,7 @@ export const sendEvent = ({ type, displayName, ...payload }) => { if (newLevel < oldLevel) { return } - const levelUpCount = getLevelUpCount(displayName) + const levelUpCount = await getLevelUpCount(displayName) if (newLevel % LEVEL_NOFIFICATION_EACH_LEVELS === 0 && levelUpCount >= LEVEL_NOFIFICATION_EACH_LEVELS ) { @@ -92,14 +93,12 @@ export const sendEvent = ({ type, displayName, ...payload }) => { } break case EVENT_TYPE_PLAYER_KILLED_ENTITY: - getKillCount(displayName, payload.entityName) - .then(killCount => { - const newKillCount = killCount + 1 - saveKillCount(displayName, payload.entityName, newKillCount) - if (newKillCount % getKillNotificationEachKillsCount(payload) === 0) { - sendMessageToAll(`👤 *${displayName}* 👻 VS 👻 *${getEntityName(payload)}*. Убито ещё ${getKillNotificationEachKillsCount(payload)}! Всего: ${newKillCount} 👍`) - } - }) + const killCount = await getKillCount(displayName, payload.entityName) + const newKillCount = killCount + 1 + saveKillCount(displayName, payload.entityName, newKillCount) + if (newKillCount % getKillNotificationEachKillsCount(payload) === 0) { + sendMessageToAll(`👤 *${displayName}* 👻 VS 👻 *${getEntityName(payload)}*. Убито ещё ${getKillNotificationEachKillsCount(payload)}! Всего: ${newKillCount} 👍`) + } break } } diff --git a/data.js b/data.js index f51b005..df82d6a 100644 --- a/data.js +++ b/data.js @@ -151,6 +151,8 @@ export const getKillNotificationEachKillsCount = payload => { return 5 case 'Zombie': return 25 + case 'Husk': + return 15 case 'Slime': return 10 case 'Ghast':