|
1 |
| -import * as fend from 'fend-wasm'; |
| 1 | +import { evaluateFendWithTimeout, substituteInlineFendExpressions } from 'fend-wasm'; |
2 | 2 |
|
3 |
| -const two = fend.evaluateFendWithTimeout('1+1', 500); |
| 3 | +const two = evaluateFendWithTimeout('1+1', 500); |
4 | 4 | if (two !== '2') {
|
5 | 5 | throw new Error(`could not execute webassembly: got '${two}' instead of '2'`);
|
6 | 6 | }
|
@@ -35,13 +35,13 @@ type Update = {
|
35 | 35 |
|
36 | 36 | function processInput(input: string, chatType: string) {
|
37 | 37 | if (input == '/start' || input == '/help') {
|
38 |
| - return "fend is an arbitrary-precision unit-aware calculator.\n\nYou can send it maths questions like '1+1', 'sin(pi)' or 'sqrt(5)'. In group chats, you'll need to enclose your input in [[double square brackets]] like this: [[1+1]]."; |
| 38 | + return "fend is an arbitrary-precision unit-aware calculator.\n\nYou can send maths questions like '1+1', 'sin(pi)' or 'sqrt(5)'. In group chats, you'll need to enclose your input in [[double square brackets]] like this: [[1+1]]."; |
39 | 39 | }
|
40 | 40 |
|
41 | 41 | if (chatType == 'private' || chatType == 'inline') {
|
42 |
| - return fend.evaluateFendWithTimeout(input, 500); |
| 42 | + return evaluateFendWithTimeout(input, 500); |
43 | 43 | } else if (chatType == 'group' || chatType == 'supergroup' || chatType == 'channel') {
|
44 |
| - let response = JSON.parse(fend.substituteInlineFendExpressions(input, 500)); |
| 44 | + let response = JSON.parse(substituteInlineFendExpressions(input, 500)); |
45 | 45 | let result = '';
|
46 | 46 | let foundCalculation = false;
|
47 | 47 | for (let part of response) {
|
@@ -96,7 +96,14 @@ async function processUpdate(update: Update) {
|
96 | 96 | let result = processInput(input, 'inline');
|
97 | 97 | let results: InlineQueryResult[] = [];
|
98 | 98 | if (result != null && result != '') {
|
99 |
| - results.push({type: 'article', title: result, id: '1', input_message_content: {message_text: result}}); |
| 99 | + results.push({ |
| 100 | + type: 'article', |
| 101 | + title: result, |
| 102 | + id: '1', |
| 103 | + input_message_content: { |
| 104 | + message_text: result, |
| 105 | + }, |
| 106 | + }); |
100 | 107 | }
|
101 | 108 | await postJSON('answerInlineQuery', {
|
102 | 109 | inline_query_id: update.inline_query.id,
|
|
0 commit comments