~edwargix/msc-link-bot

771de6ebea057c083d88e0d849ccaabe54616ef6 — David Florness 3 years ago 432e291
Only respond to msgs that were sent in the last five minutes
1 files changed, 5 insertions(+), 0 deletions(-)

M main.go
M main.go => main.go +5 -0
@@ 5,6 5,7 @@ import (
	"fmt"
	"os"
	"regexp"
	"time"

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



@@ 136,6 137,10 @@ func isBadEncryptError(err error) bool {
// this function assumes evt.Type is EventMessage
// return value is the body of the message to send back, if any
func getMsgResponse(client *mautrix.Client, evt *event.Event) string {
	// only respond to messages that were sent in the last five minutes
	if time.Unix(evt.Timestamp / 1000, evt.Timestamp % 1000).Before(time.Now().Add(time.Minute * -5)) {
		return ""
	}
	content := evt.Content.AsMessage()
	if content.MsgType != event.MsgText {
		return ""