Strip /post from text string

This commit is contained in:
Hamcha 2019-05-23 16:39:53 +02:00
parent 876338370e
commit b7d6ea332a
Signed by: hamcha
GPG Key ID: A40413D21021EAEE
1 changed files with 8 additions and 1 deletions

View File

@ -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, "<b>ERRORE!</b> @hamcha controlla la console!", &tg.MessageOptions{