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