-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
wa.js
47 lines (39 loc) · 1.07 KB
/
wa.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
42
43
44
45
46
47
'use strict';
require('dotenv').config();
const WolframAlphaAPI = require('wolfram-alpha-api');
const waApi = new WolframAlphaAPI(process.env.WOLFRAM);
async function wa(input) {
const response = {
text: '',
photo: ''
};
try {
response.text = await waApi.getShort(input);
} catch (err) {
if (err.message.includes('No short answer available')) {
try {
const result = await waApi.getSimple(input); // URI (with suffix)
const base64 = result.toString().replace(/^.{22}/, '');
response.photo = Buffer.from(base64, 'base64');
} catch (err) {
response.text = err.message;
}
} else response.text = err.message;
}
return response;
}
async function waFull(input) {
const response = {
text: '',
photo: ''
};
try {
const result = await waApi.getSimple(input); // URI (with suffix)
const base64 = result.toString().replace(/^.{22}/, '');
response.photo = Buffer.from(base64, 'base64');
} catch (err) {
response.text = err.message;
}
return response;
}
module.exports = { wa, waFull };