Exemplo n.º 1
0
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))
	}
}
Exemplo n.º 2
0
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))
			}
		}
	}
}