husk
This commit is contained in:
parent
11ac166eed
commit
fe144096a1
25
bot.js
25
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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user