示例#1
0
文件: main.go 项目: willemvds/Steve
func DoMath(cv *xmpp.ChatView) {
	if strings.HasSuffix(cv.GetText(), "= ?") {
		expr := strings.TrimSpace(cv.GetText()[0 : len(cv.GetText())-3])
		answer, err := math.Parse("STEVE!", expr)
		if err != nil {
			XMPPSendMessage(cv.GetRemote(), "Steve not know!")
			return
		}
		XMPPSendMessage(cv.GetRemote(), fmt.Sprintf("%d", answer))
	}
}
示例#2
0
文件: main.go 项目: willemvds/Steve
func Taxes(b []byte) {
	s := string(b)
	if strings.HasPrefix(s, "Taxes ") {
		parts := strings.SplitN(s, " ", 3)
		if len(parts) == 3 {
			target := parts[1]
			expr := parts[2]
			answer, err := math.Parse("Taxes", expr)
			if err == nil {
				XMPPSendMessage(target, fmt.Sprintf("Steve do taxes for %s: %s = %d moneys to taxman", target, expr, answer))
			}
		}
	}
}