Skip to content
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

[FT.] /balance #26

Merged
merged 1 commit into from
Dec 20, 2019
Merged
Changes from all commits
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
69 changes: 41 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,31 @@ bot.on('text', async (msg) => {
})

var commands = {
'list': [{
'name': "start",
'desc': 'Welcome command.'
},
{
'name': "help",
'desc': 'Shows a list of available commands.'
},
{
'name': "setprice",
'desc': 'Sets the price of a box or a bottle of mate.'
},
{
'name': "drink",
'desc': 'The user drinks a club-mate.'
},
{
'name': "buybox",
'desc': 'The user buys a box of club mate.'
}
]
'list': [{
'name': "start",
'desc': 'Welcome command.'
},
{
'name': "help",
'desc': 'Shows a list of available commands.'
},
{
'name': "setprice",
'desc': 'Sets the price of a box or a bottle of mate.'
},
{
'name': "drink",
'desc': 'The user drinks a club-mate.'
},
{
'name': "buybox",
'desc': 'The user buys a box of club mate.'
},
{
'name': "balance",
'desc': 'Shows the status of everyone\'s wallet.'
}
]
}

// /start command
Expand Down Expand Up @@ -103,13 +107,22 @@ bot.on([`/${commands.list[3].name}`], (msg) => {

// /buybox command
bot.on([`/${commands.list[4].name}`], (msg) => {
users[msg.chat.id][msg.from.id].wallet -= parseInt(prices[msg.chat.id].box)
fs.writeFile('./users_data.json', JSON.stringify(users, null, 2), 'utf8', function(err) {
if (err) {
return console.log(err)
}
})
msg.reply.text(`Thanks ${users[msg.chat.id][msg.from.id].username} just bought a box of club-mate ! :)\nYou currently have ${users[msg.chat.id][msg.from.id].wallet} in your wallet!`)
users[msg.chat.id][msg.from.id].wallet -= parseInt(prices[msg.chat.id].box)
fs.writeFile('./users_data.json', JSON.stringify(users, null, 2), 'utf8', function(err) {
if (err) {
return console.log(err)
}
})
msg.reply.text(`Thanks ${users[msg.chat.id][msg.from.id].username} just bought a box of club-mate ! :)\nYou currently have ${users[msg.chat.id][msg.from.id].wallet} in your wallet!`)
});

// /balance command
bot.on([`/${commands.list[5].name}`], (msg) => {
let tmpMsg = ""
Object.values(users[msg.chat.id]).forEach(element =>
tmpMsg += `${element.username} → ${element.wallet}.-\n`
)
msg.reply.text(tmpMsg)
});

// bot.on(/^\/send(.+)$/, (msg, props) => {
Expand Down