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

View file

@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"strings"
"git.fromouter.space/hamcha/tg" "git.fromouter.space/hamcha/tg"
"github.com/mattn/go-mastodon" "github.com/mattn/go-mastodon"
@ -130,7 +131,13 @@ func mastodon_message(broker *tg.Broker, update tg.APIMessage) {
return 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 { if err != nil {
log.Printf("[mastodon] Send toot failed: %s\n", err.Error()) log.Printf("[mastodon] Send toot failed: %s\n", err.Error())
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @hamcha controlla la console!", &tg.MessageOptions{ broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @hamcha controlla la console!", &tg.MessageOptions{