From b7d6ea332a051b547ac6614db006cb00d08966c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=AEittaG=20ordnasselA?= Date: Thu, 23 May 2019 16:39:53 +0200 Subject: [PATCH] Strip /post from text string --- mods/mastodon.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mods/mastodon.go b/mods/mastodon.go index 1a15b25..bd8e409 100644 --- a/mods/mastodon.go +++ b/mods/mastodon.go @@ -8,6 +8,7 @@ import ( "fmt" "log" "os" + "strings" "git.fromouter.space/hamcha/tg" "github.com/mattn/go-mastodon" @@ -130,7 +131,13 @@ func mastodon_message(broker *tg.Broker, update tg.APIMessage) { return } - status, err := sendToot(*(update.Text), "") + // Strip command from beginning of text string, if it's there + text := *(update.Text) + if strings.HasPrefix(text, "/post ") || strings.HasPrefix(text, "/post@"+*botname+" ") { + text = text[strings.IndexRune(text, ' ')+1:] + } + + status, err := sendToot(text, "") if err != nil { log.Printf("[mastodon] Send toot failed: %s\n", err.Error()) broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &tg.MessageOptions{