mirror of
https://github.com/maubot/maubot
synced 2025-08-29 19:00:39 +00:00
More functions for clients
This commit is contained in:
parent
f7fd012218
commit
6868b08fa9
3 changed files with 110 additions and 14 deletions
|
@ -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)
|
||||
}
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue