-
Notifications
You must be signed in to change notification settings - Fork 12
Award bonus points #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Award bonus points #119
Changes from 1 commit
6edabfc
1731fc1
0efac08
d7df179
015bcfe
857a305
c2e36d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| const Discord = require('discord.js'); | ||
| const util = require('apex-util'); | ||
| const { isAdmin } = require('./botUtils.js'); | ||
| const models = require('../db/models'); | ||
|
|
||
| // If production server, set default debug mode to production setting | ||
| if (process.env.NODE_ENV === 'production' && !process.env.DEBUG_MODE) process.env.DEBUG_MODE = 0; | ||
|
|
@@ -10,11 +11,32 @@ const client = new Discord.Client(); | |
| // Pre-load controllers | ||
| const controllers = require('./controllers')(); | ||
|
|
||
| // const numberOfMessagesForBonus = 1000; | ||
| const awardBonusPoints = (user) => { | ||
|
|
||
| const awardBonusPoints = async (user) => { | ||
| const numberOfMessagesForBonus = 1000; | ||
| // Get User Message Count | ||
| const memberData = await models.Member.findAll( | ||
| { | ||
| attributes: ['messagesCount', 'points'], | ||
| where: { discordUser: user }, | ||
| }, | ||
| ); | ||
| let { messagesCount } = memberData[0].dataValues; | ||
| let { points } = memberData[0].dataValues; | ||
| util.log('Results from database call', memberData[0].dataValues, 4); | ||
| // Check if its greater or equal to numberOfMessagesForBonus | ||
| util.log('User: ', user, 0); | ||
| if (messagesCount >= numberOfMessagesForBonus) { | ||
| points += 5; | ||
| messagesCount = 0; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: 3424242 }, | ||
| // { where: { discordUser: user } }, | ||
| // ).then((updatedRows) => { | ||
| // util.log('Updated result', updatedRows, 4); | ||
| // }); | ||
| // util.log('User: ', user, 0); | ||
| }; | ||
|
|
||
| // Alert when ready | ||
|
|
@@ -24,7 +46,7 @@ client.on('ready', () => { | |
|
|
||
| // Listen for messages | ||
| client.on('message', (message) => { | ||
| awardBonusPoints(message.author.username); | ||
| awardBonusPoints(message.author.id); | ||
| // Check for ! prefix on message to ensure it is a command | ||
| if (message.content.charAt(0) === '!') { | ||
| util.log('Command message received', message.content, 0); | ||
|
|
||
There was a problem hiding this comment.
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.