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 JOIN_NOTIFICATION_TIME_DELTA = 60 * 60 // 1h
const LEVEL_NOFIFICATION_EACH_LEVELS = 5 const LEVEL_NOFIFICATION_EACH_LEVELS = 5
export const sendEvent = ({ type, displayName, ...payload }) => { export const sendEvent = async ({ type, displayName, ...payload }) => {
switch (type) { switch (type) {
case EVENT_TYPE_JOIN: case EVENT_TYPE_JOIN:
setOnlineState(displayName) setOnlineState(displayName)
getLastLogoutTime(displayName) const lastLogoutTime = await getLastLogoutTime(displayName)
.then(lastLogoutTime => lastLogoutTime < currentTime() - JOIN_NOTIFICATION_TIME_DELTA && if (lastLogoutTime < currentTime() - JOIN_NOTIFICATION_TIME_DELTA) {
sendMessageToAll(`👤 *${displayName}* присоединился 😼`)) sendMessageToAll(`👤 *${displayName}* присоединился 😼`)
}
break break
case EVENT_TYPE_QUIT: case EVENT_TYPE_QUIT:
setOfflineState(displayName) setOfflineState(displayName)
@ -81,7 +82,7 @@ export const sendEvent = ({ type, displayName, ...payload }) => {
if (newLevel < oldLevel) { if (newLevel < oldLevel) {
return return
} }
const levelUpCount = getLevelUpCount(displayName) const levelUpCount = await getLevelUpCount(displayName)
if (newLevel % LEVEL_NOFIFICATION_EACH_LEVELS === 0 && if (newLevel % LEVEL_NOFIFICATION_EACH_LEVELS === 0 &&
levelUpCount >= LEVEL_NOFIFICATION_EACH_LEVELS levelUpCount >= LEVEL_NOFIFICATION_EACH_LEVELS
) { ) {
@ -92,14 +93,12 @@ export const sendEvent = ({ type, displayName, ...payload }) => {
} }
break break
case EVENT_TYPE_PLAYER_KILLED_ENTITY: case EVENT_TYPE_PLAYER_KILLED_ENTITY:
getKillCount(displayName, payload.entityName) const killCount = await getKillCount(displayName, payload.entityName)
.then(killCount => { const newKillCount = killCount + 1
const newKillCount = killCount + 1 saveKillCount(displayName, payload.entityName, newKillCount)
saveKillCount(displayName, payload.entityName, newKillCount) if (newKillCount % getKillNotificationEachKillsCount(payload) === 0) {
if (newKillCount % getKillNotificationEachKillsCount(payload) === 0) { sendMessageToAll(`👤 *${displayName}* 👻 VS 👻 *${getEntityName(payload)}*. Убито ещё ${getKillNotificationEachKillsCount(payload)}! Всего: ${newKillCount} 👍`)
sendMessageToAll(`👤 *${displayName}* 👻 VS 👻 *${getEntityName(payload)}*. Убито ещё ${getKillNotificationEachKillsCount(payload)}! Всего: ${newKillCount} 👍`) }
}
})
break break
} }
} }

View File

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