Skip to content

Commit

Permalink
fix typos, fetching currency for Telegram-Bot
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Neubauer committed Nov 2, 2022
1 parent fec29ba commit 4da58c2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Backend/bot/commands/basic_bot_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const basic_bot_commands = function basic_bot_commands() {
`/info <b>+ title</b>: show the game info and description.`,
`/wishlist : show the wishlist.`,
``,
`All commands also work on reply to a message. For example, list all games beginning with the letter 'B', and then reply to a game with /info.`
`All commands also work at reply to a message. For example, list all games beginning with the letter 'B', and then reply to a game with /info.`
].join("\n");
return ctx.reply(helpMsg, { parse_mode: "HTML" });
})
Expand All @@ -39,7 +39,7 @@ const basic_bot_commands = function basic_bot_commands() {
`/info <b>+ title</b>: show the game info and description.`,
`/wishlist : show the wishlist.`,
``,
`All commands also work on reply to a message. For example, list all games beginning with the letter 'B', and then reply to a game with /info.`
`All commands also work at reply to a message. For example, list all games beginning with the letter 'B', and then reply to a game with /info.`
].join("\n");
return ctx.reply(helpMsg, { parse_mode: "HTML" });
})
Expand Down
15 changes: 10 additions & 5 deletions Backend/bot/commands/find_command.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
process.env["NTBA_FIX_319"] = 1;
const bot = require('../bot')
const fetch = require("node-fetch")
const fetch = require("node-fetch");
const currency = require('../utils/currency');

require('dotenv').config()

const find_command = function find_command() {

const uri = process.env.BACKEND_URL


bot.hears(/^!find|^\/find/i, async (ctx) => {

const CURRENCY = await currency.getcurrency()

var checkreply = ctx.message.reply_to_message
if (checkreply === undefined) {
let getmsg = ctx.message.text
Expand All @@ -25,9 +30,9 @@ bot.hears(/^!find|^\/find/i, async (ctx) => {
if (data.answer === 'NoGame') {
return ctx.reply('Game not Found!')
} else if (data.iswishlist === 'true') {
return ctx.reply(`The Game is on your Wishlist!\r\n \r\n ${data.title}\r\n${data.price},-`)
return ctx.reply(`The Game is on your Wishlist!\r\n \r\n ${data.title}\r\n${data.price}${CURRENCY}`)
} else {
return ctx.reply(`${data.title}\r\n${data.price},-`)
return ctx.reply(`${data.title}\r\n${data.price}${CURRENCY}`)
}
});
} else {
Expand All @@ -48,9 +53,9 @@ bot.hears(/^!find|^\/find/i, async (ctx) => {
if (data.answer === 'NoGame') {
return ctx.reply('Game not Found!')
} else if (data.iswishlist === 'true') {
return ctx.reply(`The Game is on your Wishlist!\r\n \r\n ${data.title}\r\n${data.price},-`)
return ctx.reply(`The Game is on your Wishlist!\r\n \r\n ${data.title}\r\n${data.price}${CURRENCY}`)
} else {
return ctx.reply(`${data.title}\r\n${data.price} ,-`)
return ctx.reply(`${data.title}\r\n${data.price}${CURRENCY}`)
}
});
} else {
Expand Down
24 changes: 24 additions & 0 deletions Backend/bot/utils/currency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const fetch = require("node-fetch")

require('dotenv').config()

const uri = process.env.BACKEND_URL

const getcurrency = () => {
let fetchCurrency = fetch(uri + '/api/public/currency').then((res) =>
res.json()).then(json => json.map(game => {

if (game.currency === 'EUR') {
return('€')
} else if (game.currency === 'USD') {
return('$')
} else if (game.currency === 'BTC') {
return('₿')
} else {
return 'failed getting currency'
}
}))
return fetchCurrency
}

exports.getcurrency = getcurrency
2 changes: 1 addition & 1 deletion Backend/routes/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ router.get("/wishlist/:id/detail/:title", (req, res, next) => {
})

router.get("/public/currency", (req, res, next) => {
var params = [req.params.currency]
var params = []
var sql = "select currency from Settings"
db.all(sql, params, (err, row) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Some commands to use are:
`/info <GameTitle>` - Replies the description of the provided title.\
`/wishlist` - Replies the wishlist.

All commands also work on reply to a message. For example, list all games beginning with the letter 'B', and then reply to a game with `/info`.\
All commands also work at reply to a message. For example, list all games beginning with the letter 'B', and then reply to a game with `/info`.\
More detailed infos will be provided in the Bot itself.

## Information
Expand Down

0 comments on commit 4da58c2

Please sign in to comment.