From a9081c62d465b7e380cecdf42df1a4bf7e2d158c Mon Sep 17 00:00:00 2001 From: Tiffany Le-Nguyen Date: Sun, 29 Apr 2018 20:36:17 -0400 Subject: [PATCH] Fix !knowme and !mm (#4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨ Unfinished changes * :fire: Remove console log * :fire: Remove unnecessary console.logs * :fire: Remove another console.log * :fire: Remove unecessary comment * Add top level documentation and fix missing import (#2) * :bug: Fix missing import * :memo: Add top level documentation * :memo: Fix typo * :bug: Fix !knowme and !mm * v1.0.1 --- package.json | 2 +- src/commands.js | 20 ++++++++++---------- src/queries.js | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index f1dd24e..c64412c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "camperbot", - "version": "1.0.0", + "version": "1.0.1", "description": "freeCodeCamp montreal discord bot", "main": "src/app.js", "repository": "git@github.com:sirMerr/camperbot.git", diff --git a/src/commands.js b/src/commands.js index 6eb54de..1333fcf 100644 --- a/src/commands.js +++ b/src/commands.js @@ -23,6 +23,7 @@ export const knowme = msg => { insertAccount({ discordId: msg.author.id, + createdAt: msg.member.joinedAt, callback, errorHandler, }); @@ -48,22 +49,21 @@ export const repopulate = msg => { // Give user(s) marshmellows export const marshmellow = msg => { - const usersIds = msg.mentions.users.keyArray(); + const mentionedId = msg.mentions.users.first().id; - const callback = data => {}; - - if (usersIds.length > 0) { + if (mentionedId === msg.author.id) { + msg.reply("lol you can't give yourself marshmellows"); + } else { incrementMarshmellow({ - discordIds: usersIds, - callback, + discordId: mentionedId, + callback: () => { + console.log('!mm success'); + }, errorHandler: err => { console.log('!mm', err); + msg.reply('Unable to give marshmellows :('); }, }); - } else { - msg.reply( - "you didn't say which user(s) you wanted to give a marshmellow to!" - ); } }; diff --git a/src/queries.js b/src/queries.js index 3475be3..847a31e 100644 --- a/src/queries.js +++ b/src/queries.js @@ -32,13 +32,13 @@ export const insertAccount = ({ // Increment marshmellows for a given array of users export const incrementMarshmellow = ({ - discordIds, // array of discord ids + discordId, // array of discord ids callback, errorHandler, }) => { const query = sql` UPDATE accounts SET marshmellows = marshmellows + 1 - WHERE discord_id IN (${"'" + discordIds.join() + "'"}) + WHERE discord_id = ${discordId} RETURNING accounts.marshmellows `;