forked from Chisom-M/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
botUtils.js
41 lines (37 loc) · 1.19 KB
/
botUtils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Copyright (c) 2014-2021 Bjoern Kimminich.
* SPDX-License-Identifier: MIT
*/
const models = require('../models/index')
const fuzz = require('fuzzball')
const insecurity = require('./insecurity')
const utils = require('./utils')
const challenges = require('../data/datacache').challenges
async function productPrice (query, user) {
const [products] = await models.sequelize.query('SELECT * FROM Products')
const queriedProducts = products
.filter((product) => fuzz.partial_ratio(query, product.name) > 60)
.map((product) => `${product.name} costs ${product.price}¤`)
return {
action: 'response',
body: queriedProducts.length > 0 ? queriedProducts.join(', ') : 'Sorry I couldn\'t find any products with that name'
}
}
function couponCode (query, user) {
utils.solveIf(challenges.bullyChatbotChallenge, () => { return true })
return {
action: 'response',
body: `Oooookay, if you promise to stop nagging me here's a 10% coupon code for you: ${insecurity.generateCoupon(10)}`
}
}
function testFunction (query, user) {
return {
action: 'response',
body: '3be2e438b7f3d04c89d7749f727bb3bd'
}
}
module.exports = {
productPrice,
couponCode,
testFunction
}