Esempio n. 1
0
func getBalance(balance string) (bool, *big.Rat) {
	rationalNum := new(big.Rat)
	if strings.Contains(balance, "(") {
		rationalNum.SetFloat64(calc.Solve(balance))
		return true, rationalNum
	}
	_, isValid := rationalNum.SetString(balance)
	return isValid, rationalNum
}
Esempio n. 2
0
func process(text string) (result string, err error) {
	defer func() {
		if e := recover(); e != nil {
			result = ""
			err = e.(error)
		}
	}()

	answerf64 := calc.Solve(text)
	var x int = int(answerf64)
	return fmt.Sprintf("%%v = %v\n%%d = %d, %%b = %b, %%o = %o, %%x = %x, %%U = %U\n", answerf64, x, x, x, x, x), nil
}
Esempio n. 3
0
func meuMessageProcess(bot *Meu, e *slack.MessageEvent) interface{} {
	switch {
	case e.Text == "메우, 멱살":
		return "사람은 일을 하고 살아야한다. 메우"
	case e.Text == "메우메우 펫탄탄":
		return `메메메 메메메메 메우메우
메메메 메우메우
펫땅펫땅펫땅펫땅 다이스키`
	}

	text := strings.TrimSpace(e.Text)
	if matched, ok := MatchRE(text, calc_re); ok {
		defer func() {
			if r := recover(); r != nil {
				log.Printf("Recovered : %g\n", r)
				bot.replySimple(e, "에러났다 메우")
			}
		}()
		return fmt.Sprintf("%f", calc.Solve(matched[1]))
	} else {
		specialResponses(bot.getBase(), e)
	}
	if bot.IsBeginWithMention(e) {
		text = strings.TrimSpace(strings.Replace(text, bot.MentionStr(), "", 1))
		if matched, ok := MatchRE(text, et_register); ok {
			register_et(bot, e, matched)
		} else if _, ok := MatchRE(text, et_call); ok {
			next_et(bot, e, matched)
		} else if matched, ok := MatchRE(text, party_register); ok {
			register_party(bot, e, matched)
		} else if matched, ok := MatchRE(text, party_list); ok {
			list_party(bot, e, matched)
		} else if matched, ok := MatchRE(text, party_exit); ok {
			exit_party(bot, e, matched)
		}
	}

	return nil
}
Esempio n. 4
0
func (bot *Meu) onMessageEvent(e *slack.MessageEvent) {
	switch {
	case e.Text == "메우, 멱살":
		bot.sendSimple(e, "사람은 일을 하고 살아야한다. 메우")
		break
	case e.Text == "메우메우 펫탄탄":
		bot.sendSimple(e, `메메메 메메메메 메우메우
메메메 메우메우
펫땅펫땅펫땅펫땅 다이스키`)
		break
	default:
		if matched, ok := MatchRE(e.Text, calc_re); ok {
			defer func() {
				if r := recover(); r != nil {
					log.Println("Recovered : %g", r)
					bot.replySimple(e, "에러났다 메우")
				}
			}()
			bot.sendSimple(e, fmt.Sprintf("%f", calc.Solve(matched[1])))
		}
	}
}