Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added update when bonus is met
  • Loading branch information
drubiodev committed Mar 10, 2018
commit d7df179be0d88025e04cf06994375d8b3a9313e4
22 changes: 10 additions & 12 deletions bot/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,30 @@ const client = new Discord.Client();
// Pre-load controllers
const controllers = require('./controllers')();


// Award bonus points
const awardBonusPoints = async (user) => {
const numberOfMessagesForBonus = 1000;
const amountOfBonusPoints = 100;
// Get User Message Count
const memberData = await models.Member.findAll(
{
attributes: ['messagesCount', 'points'],
where: { discordUser: user },
where: { discordUser: user.author.id },
},
);
let { messagesCount } = memberData[0].dataValues;
let { points } = memberData[0].dataValues;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! If you wanted to you could condense these two lines into one. When deconstructing a variable, you can add multiple items... For example here you could say let { messagesCount, points } = memberData[0].dataValues; and it would say the same thing with one less line of code. They could also be made a const too since they don't change.

util.log('Results from database call', memberData[0].dataValues, 4);
// Check if its greater or equal to numberOfMessagesForBonus
if (messagesCount >= numberOfMessagesForBonus) {
points += 5;
points += amountOfBonusPoints;
messagesCount = 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick input, I noticed this is going to affect the points that users gain from regularly chatting. That feature directly uses the messagesCount to determine how many points the users have earned through chatting. If there would be a way to implement this without resetting the message count to zero each time that would be great.

// Update member information
await models.Member.update(
{ messagesCount, points },
{ where: { discordUser: user.author.id } },
);
}
// Update member information
// const updateMemberData = await models.Member.update(
// { messagesCount: 3424242 },
// { where: { discordUser: user } },
// );
// util.log('Updated result', updateMemberData, 4);

// util.log('User: ', user, 0);
};

// Alert when ready
Expand All @@ -46,7 +44,7 @@ client.on('ready', () => {

// Listen for messages
client.on('message', (message) => {
awardBonusPoints(message.author.id);
awardBonusPoints(message);
// Check for ! prefix on message to ensure it is a command
if (message.content.charAt(0) === '!') {
util.log('Command message received', message.content, 0);
Expand Down
2 changes: 2 additions & 0 deletions db/models/member.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module.exports = (sequelize, DataTypes) => {
email: DataTypes.STRING,
uuid: DataTypes.STRING,
verified: DataTypes.BOOLEAN,
messagesCount: DataTypes.INTEGER,
points: DataTypes.INTEGER,
}, {
classMethods: {
associate: (models) => {
Expand Down