diff --git a/bot.js b/bot.js index 654286b..e9cb6ad 100644 --- a/bot.js +++ b/bot.js @@ -33,9 +33,10 @@ bot.command( )) ) bot.hears( - /^kills (.+)$/, + /^\/kills[ =](.+)$/, ctx => getAllKills(ctx.match[1]) .then(allKills => { + console.log(allKills) if (!allKills) { ctx.reply('Не найдено') return diff --git a/database.js b/database.js index 9780d62..66496e1 100644 --- a/database.js +++ b/database.js @@ -59,12 +59,12 @@ const get = (sql, params, column, defaultParam = null) => new Promise((resolve, }) }) -const all = (sql, params = []) => new Promise((resolve, reject) => { +const all = (sql, params = [], defaultParam = null) => new Promise((resolve, reject) => { db.all(sql, params, (err, rows) => { if (err) { reject(err) } else { - resolve(rows) + resolve(rows.length ? rows : defaultParam) } }) }) @@ -93,7 +93,7 @@ export const getKillCount = (displayName, entityName) => get( 'killCount', 0 ) -export const getAllKills = displayName => all('SELECT * FROM playerKills WHERE displayName = ? ORDER BY displayName ASC', [ displayName ]) +export const getAllKills = displayName => all('SELECT * FROM playerKills WHERE displayName = ?', [ displayName ]) export const saveLevelUp = (displayName, levelUpCount) => run( `INSERT OR REPLACE INTO levelUps (displayName, levelUpCount) VALUES (?, ?)`,