Add \'servers\' matrix command (fix #10)
This commit is contained in:
parent
b07e9a78d8
commit
714380477e
25
matrix.go
25
matrix.go
@ -80,14 +80,25 @@ func initMatrix() {
|
||||
})
|
||||
syncer.OnEventType(event.EventMessage, func(ctx context.Context, evt *event.Event) {
|
||||
if evt.RoomID.String() == configuration.matrix.room_id {
|
||||
prefixes := []string{"!", configuration.matrix.username+" "}
|
||||
for _,prefix := range prefixes {
|
||||
if strings.HasPrefix(evt.Content.AsMessage().Body, prefix) {
|
||||
found_command := false
|
||||
for _, command := range Chatcommands {
|
||||
if command.cmd == strings.TrimPrefix(evt.Content.AsMessage().Body, "!") {
|
||||
if command.cmd == strings.TrimPrefix(evt.Content.AsMessage().Body, prefix) {
|
||||
found_command = true
|
||||
out := command.callback(ctx, evt)
|
||||
content := format.RenderMarkdown(out, true, false)
|
||||
content.SetReply(evt)
|
||||
client.SendMessageEvent(ctx, evt.RoomID, event.EventMessage, content)
|
||||
}
|
||||
}
|
||||
if !found_command {
|
||||
client.SendText(ctx, evt.RoomID, "🔴 Command not found")
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@ -99,6 +110,18 @@ func initMatrix() {
|
||||
return text
|
||||
})
|
||||
|
||||
registerChatCommand("sites", "Display all available sites", func(ctx context.Context, evt *event.Event) string {
|
||||
text := "⚪️ Getting sites...\n"
|
||||
sites, err := getAllSites()
|
||||
if err.code != 0 {
|
||||
return text+"🔴 Failed to get sites!"
|
||||
}
|
||||
for _, site := range sites {
|
||||
text = fmt.Sprintf("%s- %s\n", text, site)
|
||||
}
|
||||
return text
|
||||
})
|
||||
|
||||
go func () {
|
||||
for range time.Tick(time.Second * 3) {
|
||||
log.Printf("Scanning for queued messages...")
|
||||
|
Loading…
Reference in New Issue
Block a user