Skip to content

Commit

Permalink
Remove the use of eval()
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyaacinth committed Jun 30, 2024
1 parent 7ddef07 commit 5bfe6a1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dayjs": "^1.11.10",
"discord-emoji": "^2.4.0",
"discord-user-bots": "^1.6.0",
"mathjs": "^13.0.1",
"matrix-bot-sdk": "^0.7.1",
"minecraft-protocol": "^1.36.1",
"nodejieba": "^2.6.0",
Expand Down
66 changes: 63 additions & 3 deletions pnpm-lock.yaml

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

3 changes: 2 additions & 1 deletion src/commands/count.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GenericMessage } from 'src/clients/base';
import { evaluate } from 'mathjs';

export const USAGE = `<number|expression> [StackCount] 计算在 MC 中的易读数字表达`;

Expand Down Expand Up @@ -67,7 +68,7 @@ export const handleSlashCommand = async (message: GenericMessage) => {
};
try {
// 尝试计算结果
const expResult = eval(expression);
const expResult = evaluate(expression);
return `${message.userName} ${countItem(expResult)}!`;
} catch (error) {
return `${message.userName} 计算出错!`;
Expand Down

0 comments on commit 5bfe6a1

Please sign in to comment.