Skip to content

Commit

Permalink
Merge pull request #52 from epfl-dojo/feature/drink
Browse files Browse the repository at this point in the history
[VER] Bump to v0.6.0
  • Loading branch information
nicolasreymond authored Jan 24, 2020
2 parents d22cbcb + 697de60 commit c5377ce
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
1. Communicate with [@BotFather](https://t.me/BotFather) to create a bot and get the token.
1. Rename `secrets.sample.json` to `secrets.json`.
1. Replace the `BOT_TOKEN` key in the `secrets.json` file with the bot token.
1. Go on [Giphy get api key](https://support.giphy.com/hc/en-us/articles/360020283431-Request-A-GIPHY-API-Key) and follow the instructions to get an API key.
1. Replace the `API_KEY` key in the `secrets.json` file with the api key you were provided with.
1. Run `npm i` to install the node dependencies.
1. Run script with `node index.js`.

# Commands

* `/start` → Welcome :)
* `/about` → Shows bot version, bug report, etc...
* `/help` → Shows a list of all available commands with their description.
* `/send <@username> <amount>` → Send a specific amount of money to another person.
* `/balance` → Shows the status of everyone's wallet.
Expand Down
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,19 @@ bot.on(`/${commands.list[2].name}`, (msg) => {

// /drink command
bot.on(`/${commands.list[3].name}`, (msg) => {
let gifWords = ['bottle', 'alcohol', 'cheers', 'drink', 'party']
let pickedWord = gifWords[Math.floor(Math.random() * gifWords.length)]
console.log(pickedWord)
fetch(`https://api.giphy.com/v1/gifs/random?api_key=${Secrets.API_KEY}&tag=${pickedWord}&limit=1&offset=0&rating=G&lang=en`)
.then(res => res.json())
.then(json => {
json

msg.reply.video(`${json.data.images.original.url}`, {caption: `Cheers @${users[msg.chat.id][msg.from.id].username}!\nYou currently have ${users[msg.chat.id][msg.from.id].wallet} ${options[msg.chat.id].currency} in your wallet!`})
})
.catch(err => console.error(err))
users[msg.chat.id][msg.from.id].wallet -= 2
utils.writeUsersDataToFile(users)
msg.reply.text(`Cheers @${users[msg.chat.id][msg.from.id].username}!\nYou currently have ${users[msg.chat.id][msg.from.id].wallet} ${options[msg.chat.id].currency} in your wallet!`)
})

// /buybox command
Expand Down
91 changes: 91 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion secrets.sample.json
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{ "BOT_TOKEN" : "123456789:AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQR" }
{
"BOT_TOKEN" : "123456789:AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQR",
"API_KEY" : "AaAaAAaaaBbbbBCcccCcccC"
}

0 comments on commit c5377ce

Please sign in to comment.