kill count
This commit is contained in:
43
bot.js
43
bot.js
@ -1,7 +1,7 @@
|
|||||||
import Telegraf from 'telegraf'
|
import Telegraf from 'telegraf'
|
||||||
import TelegrafExtra from 'telegraf/extra'
|
import TelegrafExtra from 'telegraf/extra'
|
||||||
import { saveChat, getChats, saveLogoutTime, getLastLogoutTime, saveKillCount, getKillCount,
|
import { saveChat, getChats, saveLogoutTime, getLastLogoutTime, saveKillCount, getKillCount,
|
||||||
saveLevelUp, getLevelUpCount, saveLevel, setOnlineState, setOfflineState, getPlayersData
|
saveLevelUp, getLevelUpCount, saveLevel, setOnlineState, setOfflineState, getPlayersData, getAllKills
|
||||||
} from './database'
|
} from './database'
|
||||||
import {
|
import {
|
||||||
EVENT_TYPE_JOIN, EVENT_TYPE_DEATH, EVENT_TYPE_QUIT, EVENT_TYPE_PLAYER_LEVEL_CHANGE,
|
EVENT_TYPE_JOIN, EVENT_TYPE_DEATH, EVENT_TYPE_QUIT, EVENT_TYPE_PLAYER_LEVEL_CHANGE,
|
||||||
@ -13,25 +13,44 @@ import stringTable from 'string-table'
|
|||||||
|
|
||||||
const bot = new Telegraf('643297173:AAGuqfZx3GhiiARwvY7AtWTTFw1T-2FiwCM')
|
const bot = new Telegraf('643297173:AAGuqfZx3GhiiARwvY7AtWTTFw1T-2FiwCM')
|
||||||
const markdown = TelegrafExtra.markdown()
|
const markdown = TelegrafExtra.markdown()
|
||||||
|
const formattedStringTable = data => stringTable.create(data)
|
||||||
|
.split('\n')
|
||||||
|
.map(line => `\`\`\`${line.slice(0, -1)}\`\`\``)
|
||||||
|
.join('\n')
|
||||||
|
|
||||||
bot.start(({ message: { chat: { id } } }) => saveChat(id))
|
bot.start(({ message: { chat: { id } } }) => saveChat(id))
|
||||||
bot.command(
|
bot.command(
|
||||||
'players',
|
'players',
|
||||||
({ replyWithMarkdown }) => getPlayersData()
|
({ replyWithMarkdown }) => getPlayersData()
|
||||||
.then(getPlayersData => replyWithMarkdown(
|
.then(playersData => replyWithMarkdown(
|
||||||
stringTable.create(
|
formattedStringTable(
|
||||||
getPlayersData
|
playersData.map(({ displayName, level, online }) => ({
|
||||||
.map(({ displayName, level, online }) => ({
|
'имя': `👤 ${displayName}`,
|
||||||
'имя': `👤 ${displayName}`,
|
'уровень': level,
|
||||||
'уровень': level,
|
'статус': `${online ? '✅ онлайн' : '❔ оффлайн'}`
|
||||||
'статус': `${online ? '✅ онлайн' : '❔ оффлайн'}`
|
}))
|
||||||
}))
|
|
||||||
)
|
)
|
||||||
.split('\n')
|
|
||||||
.map(line => `\`\`\`${line.slice(0, -1)}\`\`\``)
|
|
||||||
.join('\n')
|
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
|
bot.command(
|
||||||
|
'kills',
|
||||||
|
({ replyWithMarkdown }) => getAllKills()
|
||||||
|
.then(allKills => {
|
||||||
|
let groupedKills = []
|
||||||
|
let currentGroupId = 0
|
||||||
|
allKills.forEach(kills => {
|
||||||
|
if (currentGroupId !== 0 && groupedKills[currentGroupId].displayName !== kills.displayName) {
|
||||||
|
currentGroupId++
|
||||||
|
}
|
||||||
|
groupedKills[currentGroupId] = {
|
||||||
|
displayName: kills.displayName,
|
||||||
|
...groupedKills[currentGroupId],
|
||||||
|
[kills.entityName]: kills.killCount
|
||||||
|
}
|
||||||
|
})
|
||||||
|
replyWithMarkdown(formattedStringTable(groupedKills))
|
||||||
|
})
|
||||||
|
)
|
||||||
bot.launch()
|
bot.launch()
|
||||||
|
|
||||||
const sendMessageToAll = text => getChats()
|
const sendMessageToAll = text => getChats()
|
||||||
|
@ -93,6 +93,7 @@ export const getKillCount = (displayName, entityName) => get(
|
|||||||
'killCount',
|
'killCount',
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
|
export const getAllKills = () => all('SELECT * FROM playerKills ORDER BY displayName ASC')
|
||||||
|
|
||||||
export const saveLevelUp = (displayName, levelUpCount) => run(
|
export const saveLevelUp = (displayName, levelUpCount) => run(
|
||||||
`INSERT OR REPLACE INTO levelUps (displayName, levelUpCount) VALUES (?, ?)`,
|
`INSERT OR REPLACE INTO levelUps (displayName, levelUpCount) VALUES (?, ?)`,
|
||||||
|
Reference in New Issue
Block a user