feat: add caculate parse
This commit is contained in:
4 files changed
+31
-13
No files matched your search
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/9/21
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands.parse
|
||||
|
||||
import javax.script.ScriptEngineManager
|
||||
import javax.script.ScriptException
|
||||
|
||||
object CalculateCommand {
|
||||
|
||||
private val engine = ScriptEngineManager().getEngineByName("JavaScript")
|
||||
|
||||
fun parse(input: String): String? {
|
||||
return try {
|
||||
engine.eval(input)
|
||||
} catch (_: ScriptException) {
|
||||
"Invalid expression"
|
||||
return null
|
||||
}.toString()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user