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

31
bot.js
View File

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

View File

@ -93,7 +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 getAllKills = displayName => all('SELECT * FROM playerKills WHERE displayName = ? ORDER BY displayName ASC', [ displayName ])
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 (?, ?)`,