kill count

This commit is contained in:
smsteel 2019-02-11 16:18:50 +03:00
parent 94298202b8
commit ac755538f7
2 changed files with 16 additions and 17 deletions

29
bot.js
View File

@ -32,23 +32,22 @@ bot.command(
)
))
)
bot.command(
'kills',
({ replyWithMarkdown }) => getAllKills()
bot.hears(
/^\/kills (.*)$/,
ctx => getAllKills(ctx.match[1])
.then(allKills => {
let groupedKills = [{}]
let currentGroupId = 0
allKills.forEach(kills => {
if (groupedKills[currentGroupId].displayName && groupedKills[currentGroupId].displayName !== kills.displayName) {
currentGroupId++
if (!allKills) {
ctx.reply('Не найдено')
return
}
groupedKills[currentGroupId] = {
displayName: kills.displayName,
...groupedKills[currentGroupId],
[kills.entityName]: kills.killCount
}
})
replyWithMarkdown(formattedStringTable(groupedKills))
ctx.replyWithMarkdown(
formattedStringTable(
allKills.map(kills => ({
'монстр': getEntityName(kills.entityName),
'убийств': kills.killCount
}))
)
)
})
)
bot.launch()

View File

@ -93,7 +93,7 @@ export const getKillCount = (displayName, entityName) => get(
'killCount',
0
)
export const getAllKills = () => all('SELECT * FROM playerKills ORDER BY displayName ASC')
export const getAllKills = displayName => all('SELECT * FROM playerKills WHERE displayName = ? ORDER BY displayName ASC', [ displayName ])
export const saveLevelUp = (displayName, levelUpCount) => run(
`INSERT OR REPLACE INTO levelUps (displayName, levelUpCount) VALUES (?, ?)`,