From 1743b652424e95652d6ade2b3ac7b52a43c06339 Mon Sep 17 00:00:00 2001 From: Chris Sexton <3216719+chrissexton@users.noreply.github.com> Date: Fri, 12 Jan 2024 10:13:10 -0500 Subject: [PATCH] tldr: add squawk command --- plugins/tldr/tldr.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/tldr/tldr.go b/plugins/tldr/tldr.go index 8780e9e..521ecb8 100644 --- a/plugins/tldr/tldr.go +++ b/plugins/tldr/tldr.go @@ -57,10 +57,16 @@ func (p *TLDRPlugin) register() { HelpText: "Get a rather inaccurate summary of the channel", Handler: p.tldrCmd, }, + { + Kind: bot.Message, IsCmd: true, + Regex: regexp.MustCompile(`tl;?dr-prompt$`), + HelpText: "Get the tl;dr prompt", + Handler: p.squawkTLDR, + }, { Kind: bot.Message, IsCmd: true, Regex: regexp.MustCompile(`tl;?dr-prompt reset`), - HelpText: "Set the tl;dr prompt", + HelpText: "Reset the tl;dr prompt", Handler: p.resetTLDR, }, { @@ -268,6 +274,13 @@ func (p *TLDRPlugin) betterTLDR(r bot.Request) bool { return true } +func (p *TLDRPlugin) squawkTLDR(r bot.Request) bool { + prompt := p.c.Get(templateKey, defaultTemplate) + p.b.Send(r.Conn, bot.Message, r.Msg.Channel, fmt.Sprintf(`Current prompt is: "%s"`, + strings.TrimSpace(prompt))) + return true +} + func (p *TLDRPlugin) resetTLDR(r bot.Request) bool { p.c.Set(templateKey, defaultTemplate) p.b.Send(r.Conn, bot.Message, r.Msg.Channel, fmt.Sprintf(`Set prompt to: "%s"`, @@ -278,7 +291,7 @@ func (p *TLDRPlugin) resetTLDR(r bot.Request) bool { func (p *TLDRPlugin) setTLDR(r bot.Request) bool { prompt := r.Values["prompt"] + "\n" p.c.Set(defaultTemplate, prompt) - p.b.Send(r.Conn, bot.Message, r.Msg.Channel, fmt.Sprintf(`Set prompt to: "%s"`, prompt)) + p.b.Send(r.Conn, bot.Message, r.Msg.Channel, fmt.Sprintf(`Set prompt to: "%s"`, strings.TrimSpace(prompt))) return true }