More functions for clients

This commit is contained in:
Tulir Asokan 2018-09-21 00:35:24 +03:00
parent f7fd012218
commit 6868b08fa9
3 changed files with 110 additions and 14 deletions

View file

@ -55,17 +55,17 @@ func (evt *EventFuncsImpl) ReplyContent(content gomatrix.Content) (string, error
}
func (evt *EventFuncsImpl) SendMessage(text string) (string, error) {
return evt.SendContent(format.RenderMarkdown(text))
return evt.Client.SendMessage(evt.RoomID, text)
}
func (evt *EventFuncsImpl) SendMessagef(text string, args ...interface{}) (string, error) {
return evt.Client.SendMessagef(evt.RoomID, text, args...)
}
func (evt *EventFuncsImpl) SendContent(content gomatrix.Content) (string, error) {
return evt.SendRawEvent(gomatrix.EventMessage, content)
return evt.Client.SendContent(evt.RoomID, content)
}
func (evt *EventFuncsImpl) SendRawEvent(evtType gomatrix.EventType, content interface{}) (string, error) {
resp, err := evt.Client.SendMessageEvent(evt.RoomID, evtType, content)
if err != nil {
return "", err
}
return resp.EventID, nil
}
func (evt *EventFuncsImpl) SendMessageEvent(evtType gomatrix.EventType, content interface{}) (eventID string, err error) {
return evt.Client.SendMessageEvent(evt.RoomID, evtType, content)
}

View file

@ -17,9 +17,12 @@
package matrix
import (
"fmt"
"maubot.xyz"
"maubot.xyz/database"
"maunium.net/go/gomatrix"
"maunium.net/go/gomatrix/format"
log "maunium.net/go/maulogger"
)
@ -135,8 +138,28 @@ func (client *Client) onJoin(evt *maubot.Event) maubot.EventHandlerResult {
return maubot.Continue
}
func (client *Client) JoinRoom(roomID string) {
client.Client.JoinRoom(roomID, "", nil)
func (client *Client) JoinRoom(roomID string) (resp *gomatrix.RespJoinRoom, err error) {
return client.Client.JoinRoom(roomID, "", nil)
}
func (client *Client) SendMessage(roomID, text string) (string, error) {
return client.SendContent(roomID, format.RenderMarkdown(text))
}
func (client *Client) SendMessagef(roomID, text string, args ...interface{}) (string, error) {
return client.SendContent(roomID, format.RenderMarkdown(fmt.Sprintf(text, args...)))
}
func (client *Client) SendContent(roomID string, content gomatrix.Content) (string, error) {
return client.SendMessageEvent(roomID, gomatrix.EventMessage, content)
}
func (client *Client) SendMessageEvent(roomID string, evtType gomatrix.EventType, content interface{}) (string, error) {
resp, err := client.Client.SendMessageEvent(roomID, evtType, content)
if err != nil {
return "", err
}
return resp.EventID, nil
}
func (client *Client) Sync() {