This commit is contained in:
smsteel 2019-02-19 23:49:05 +03:00
parent 11ac166eed
commit fe144096a1
2 changed files with 14 additions and 13 deletions

25
bot.js
View File

@ -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
}
}

View File

@ -151,6 +151,8 @@ export const getKillNotificationEachKillsCount = payload => {
return 5
case 'Zombie':
return 25
case 'Husk':
return 15
case 'Slime':
return 10
case 'Ghast':