From 32d1ebaa9508676cc44155eb4c65bd9376e124c3 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sun, 29 Dec 2019 10:04:03 -0500 Subject: [PATCH] bot: add new variables * $time: a made up time * $now: current time * $msg: the user's message --- bot/handlers.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/bot/handlers.go b/bot/handlers.go index 0a1a3e9..7361b8f 100644 --- a/bot/handlers.go +++ b/bot/handlers.go @@ -141,6 +141,22 @@ func (b *bot) Filter(message msg.Message, input string) string { input = strings.Replace(input, "$nonzero", num, 1) } + for strings.Contains(input, "$time") { + hrs := rand.Intn(23) + mins := rand.Intn(59) + input = strings.Replace(input, "$time", fmt.Sprintf("%0.2d:%0.2d", hrs, mins), 1) + } + + for strings.Contains(input, "$now") { + now := time.Now().Format("15:04") + input = strings.Replace(input, "$now", now, 1) + } + + for strings.Contains(input, "$msg") { + msg := message.Body + input = strings.Replace(input, "$msg", msg, 1) + } + r, err := regexp.Compile("\\$[A-z]+") if err != nil { panic(err) @@ -184,7 +200,7 @@ func (b *bot) listVars(conn Connector, channel string, parts []string) { if err != nil { log.Fatal().Err(err) } - msg := "I know: $who, $someone, $digit, $nonzero" + msg := "I know: $who, $someone, $digit, $nonzero, $time, $now, $msg" if len(variables) > 0 { msg += ", " + strings.Join(variables, ", ") }