From b805641ea402eef139cbcb8288571c39aca5645e Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 21 Sep 2018 16:09:26 +0300 Subject: [PATCH] Fix passive command regex compiling and send m.notices by default --- .gitignore | 1 + matrix/commands.go | 2 +- matrix/event.go | 4 +++- matrix/matrix.go | 8 ++++++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 5c0bbe0..7dda685 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ sed/ github/ gitlab/ rss/ +factorial/ diff --git a/matrix/commands.go b/matrix/commands.go index 5bc264a..4263334 100644 --- a/matrix/commands.go +++ b/matrix/commands.go @@ -83,7 +83,7 @@ func (pc *ParsedCommand) parseCommandSyntax(command maubot.Command) error { func (pc *ParsedCommand) parsePassiveCommandSyntax(command maubot.PassiveCommand) error { pc.MatchAgainst = command.MatchAgainst var err error - pc.Matches, err = regexp.Compile(fmt.Sprintf("(%s)", command.Matches)) + pc.Matches, err = regexp.Compile(command.Matches) pc.MatchesEvent = command.MatchEvent return err } diff --git a/matrix/event.go b/matrix/event.go index ec1e22e..4458756 100644 --- a/matrix/event.go +++ b/matrix/event.go @@ -46,7 +46,9 @@ func (evt *EventFuncsImpl) MarkRead() error { } func (evt *EventFuncsImpl) Reply(text string) (string, error) { - return evt.ReplyContent(format.RenderMarkdown(text)) + content := format.RenderMarkdown(text) + content.MsgType = gomatrix.MsgNotice + return evt.ReplyContent(content) } func (evt *EventFuncsImpl) ReplyContent(content gomatrix.Content) (string, error) { diff --git a/matrix/matrix.go b/matrix/matrix.go index 5799e19..0bf5a01 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -143,11 +143,15 @@ func (client *Client) JoinRoom(roomID string) (resp *gomatrix.RespJoinRoom, err } func (client *Client) SendMessage(roomID, text string) (string, error) { - return client.SendContent(roomID, format.RenderMarkdown(text)) + content := format.RenderMarkdown(text) + content.MsgType = gomatrix.MsgNotice + return client.SendContent(roomID, content) } func (client *Client) SendMessagef(roomID, text string, args ...interface{}) (string, error) { - return client.SendContent(roomID, format.RenderMarkdown(fmt.Sprintf(text, args...))) + content := format.RenderMarkdown(fmt.Sprintf(text, args...)) + content.MsgType = gomatrix.MsgNotice + return client.SendContent(roomID, content) } func (client *Client) SendContent(roomID string, content gomatrix.Content) (string, error) {