diff --git a/bot.js b/bot.js index e667895..d4987cb 100644 --- a/bot.js +++ b/bot.js @@ -1,4 +1,5 @@ import Telegraf from 'telegraf' +import TelegrafExtra from 'telegraf/extra' import { saveChat, getChats, saveLogoutTime, getLastLogoutTime, saveKillCount, getKillCount, saveLevelUp, getLevelUpCount, saveLevel, setOnlineState, setOfflineState, getPlayersData } from './database' @@ -10,6 +11,7 @@ import { currentTime } from './utility' import { getEntityDeathMessage, getEntityName } from './ru' const bot = new Telegraf('643297173:AAGuqfZx3GhiiARwvY7AtWTTFw1T-2FiwCM') +const markdown = TelegrafExtra.markdown() bot.start(({ message: { chat: { id } } }) => saveChat(id)) bot.command( @@ -17,7 +19,7 @@ bot.command( ({ replyWithMarkdown }) => getPlayersData() .then(getPlayersData => replyWithMarkdown( getPlayersData - .map(({ displayName, level, online }) => `:bust_in_silhouette: *${displayName}* уровень ${level} ${online ? '*онлайн*' : 'оффлайн'}`) + .map(({ displayName, level, online }) => `👤 *${displayName}* уровень ${level} ${online ? '*онлайн*' : 'оффлайн'}`) .join('\n') )) ) @@ -25,7 +27,7 @@ bot.launch() const sendMessageToAll = text => getChats() .then(chats => chats.map(({ chatId }) => chatId) - .forEach(chatId => bot.telegram.sendMessage(chatId, text)) + .forEach(chatId => bot.telegram.sendMessage(chatId, text, markdown)) ) const JOIN_NOTIFICATION_TIME_DELTA = 60 * 60 // 1h @@ -38,14 +40,14 @@ export const sendEvent = ({ type, displayName, ...payload }) => { setOnlineState(displayName) getLastLogoutTime(displayName) .then(lastLogoutTime => lastLogoutTime < currentTime() - JOIN_NOTIFICATION_TIME_DELTA && - sendMessageToAll(`Игрок ${displayName} присоединился!`)) + sendMessageToAll(`👤 *${displayName}* присоединился 😼`)) break case EVENT_TYPE_QUIT: setOfflineState(displayName) saveLogoutTime(displayName) break case EVENT_TYPE_DEATH: - sendMessageToAll(`Игрок ${displayName} ${getEntityDeathMessage(payload)} :(`) + sendMessageToAll(`👤 *${displayName}* ☠️ ${getEntityDeathMessage(payload)} ☠️`) break case EVENT_TYPE_PLAYER_LEVEL_CHANGE: const { newLevel, oldLevel } = payload @@ -57,7 +59,7 @@ export const sendEvent = ({ type, displayName, ...payload }) => { if (newLevel % LEVEL_NOFIFICATION_EACH_LEVELS === 0 && levelUpCount >= LEVEL_NOFIFICATION_EACH_LEVELS ) { - sendMessageToAll(`Игрок ${displayName} прокачался до уровня ${newLevel}!`) + sendMessageToAll(`👤 *${displayName}* теперь уровня *${newLevel}* 👍`) saveLevelUp(displayName, 0) } else { saveLevelUp(displayName, levelUpCount + 1) @@ -69,7 +71,7 @@ export const sendEvent = ({ type, displayName, ...payload }) => { const newKillCount = killCount + 1 saveKillCount(displayName, payload.entityName, newKillCount) if (newKillCount % KILL_NOTIFICATION_EACH_KILLS === 0) { - sendMessageToAll(`${getEntityName(payload)} повержен(а) игроком ${displayName}. Убито ещё ${KILL_NOTIFICATION_EACH_KILLS}! Всего: ${newKillCount}`) + sendMessageToAll(`👻 *${getEntityName(payload)}* повержен(а) 👤 ${displayName}. Убито ещё ${KILL_NOTIFICATION_EACH_KILLS}! Всего 💀: ${newKillCount} 👍`) } }) break