Use unique user in unknown command test to avoid last-command fallback interference. Add plugin architecture with registered commands. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
31 lines
689 B
Go
31 lines
689 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"os/exec"
|
|
)
|
|
|
|
type MathPlugin struct{}
|
|
|
|
func (p MathPlugin) Name() string { return "math" }
|
|
func (p MathPlugin) ShortHelp() string { return "Evaluate a math expression" }
|
|
func (p MathPlugin) DetailedHelp() string {
|
|
return "math <expression>\n\nEvaluates a mathematical expression using qalc (libqalculate).\n\nExamples:\n math 2+2\n math 100 * 9.5%\n math sqrt(144)"
|
|
}
|
|
func (p MathPlugin) Execute(msg BotMessage, args string) string {
|
|
return runMath(args)
|
|
}
|
|
|
|
func runMath(s string) string {
|
|
cmd := exec.Command("qalc", s)
|
|
var out bytes.Buffer
|
|
cmd.Stdout = &out
|
|
|
|
err := cmd.Run()
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
return out.String()
|
|
}
|