~edwargix/msc-link-bot

6e5db14f522c44951d1b00a8f7b69e720c4e9577 — David Florness 2 years ago dffa54b
Use mautrix helper function to remove reply text
1 files changed, 6 insertions(+), 12 deletions(-)

M main.go
M main.go => main.go +6 -12
@@ 9,7 9,6 @@ import (
	"os"
	"regexp"
	"strconv"
	"strings"
	"time"

	_ "github.com/mattn/go-sqlite3"


@@ 156,17 155,12 @@ func getMsgResponse(client *mautrix.Client, evt *event.Event) *event.MessageEven
}

func getMSCs(body string) (mscs []uint) {
	lines := strings.Split(body, "\n")
	for _, line := range lines {
		if len(line) == 0 || line[0] == '>' {
			continue
		}
		matches := MSC_REGEX.FindAllStringSubmatch(line, -1)
		for _, match := range matches {
			// error can never happen because of %d in regex
			msc, _ := strconv.Atoi(match[1])
			mscs = append(mscs, uint(msc))
		}
	bodyNoReplies := event.TrimReplyFallbackText(body)
	matches := MSC_REGEX.FindAllStringSubmatch(bodyNoReplies, -1)
	for _, match := range matches {
		// error can never happen because of %d in regex
		msc, _ := strconv.Atoi(match[1])
		mscs = append(mscs, uint(msc))
	}
	return mscs
}