Skip to content

Commit

Permalink
Add balance command
Browse files Browse the repository at this point in the history
The balance command work with `/bal` & `/balance`.
  • Loading branch information
mittalyashu committed Mar 3, 2019
1 parent 42604ee commit f6f6f70
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion help.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const helpMessage = message => {
description: "Available Commands",
fields: [
{
name: "**/bal**",
name: "**/bal** or **/balance**",
value: "Check your balance.",
},
{
Expand Down
11 changes: 0 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ sequelize
msg.channel.send(msg.author.toString() + " StudioBot is in test phase, It will be implemented in the future.");
// withdrawCommand(argument,msg);
break;
case "bal":
// retrives balance from Redis
const userBalance = await rClient.hgetAsync(msg.author.id, "balance");// get the balance of the user
if(userBalance){ // if balance returns value
msg.channel.send(msg.author.toString() + ": Check your DM");
const botMessage=await msg.author.send("Your balance is " + userBalance + " xDAI");// send private message

}else{
msg.channel.send("Sorry" + msg.author.toString() + " could not get your balance at this time, try again.")
}
break;
case "tip":
// send xDAI to another user
tipCommand(argument, msg);
Expand Down
18 changes: 18 additions & 0 deletions message.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const userSchema = require("./model/user")

const helpMessage = require("./help")
const donateToBot = require("./donate")

Expand All @@ -19,6 +21,22 @@ const formatMessage = async message => {
message.author.send("Your deposit address is:")
message.author.send("`" + depositAddress + "`")
break
case "balance":
case "bal":
const findUser = await userSchema.findByPk(message.author.id)
try {
const userBalance = findUser.dataValues.balance
message.channel.send(message.author.toString() + ", check your DM")
message.author.send("Your balance is ||" + userBalance + "|| xDAI")
} catch (error) {
message.channel.send(
"Sorry " +
message.author.toString() +
", the bot couldn't get your balance at the moment, try again later."
)
console.log(error)
}
break
case "donate":
donateToBot(message)
break
Expand Down

0 comments on commit f6f6f70

Please sign in to comment.