Created
June 8, 2022 21:19
-
-
Save pja237/04acc9e0131c134f0bf48ad704b82ae5 to your computer and use it in GitHub Desktop.
PoC of a matrix bot which on room invite joins and sends the message with the sbatch --mail-user switch with roomID. `go run matrixSlurmBot.go`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"maunium.net/go/mautrix" | |
"maunium.net/go/mautrix/event" | |
) | |
const ( | |
matrixServer = "https://matrix-client.matrix.org" | |
matrixBotUser = "@SlurmBotNameHere:matrix.org" | |
matrixBotToken = "botTokenHere" | |
) | |
func main() { | |
client, err := mautrix.NewClient(matrixServer, matrixBotUser, matrixBotToken) | |
if err != nil { | |
log.Fatalf("ERROR: %q\n", err) | |
} | |
log.Printf("SUCCESS: %#v\n", client) | |
syncer := client.Syncer.(*mautrix.DefaultSyncer) | |
syncer.OnEvent(client.Store.(*mautrix.InMemoryStore).UpdateState) | |
syncer.OnEventType(event.StateMember, func(source mautrix.EventSource, event *event.Event) { | |
fmt.Printf("GOT EVENT %#v\n SOURCE: %#v\n", event, source) | |
// skip non-member events and member events that don't pertain | |
// to us | |
//if *event.StateKey != authInfo.UserID.String() || event.Type.Type != "m.room.member" { | |
if *event.StateKey != matrixBotUser || event.Type.Type != "m.room.member" { | |
return | |
} | |
content := event.Content.AsMember() | |
// skip non-invite messages | |
if content.Membership != "invite" { | |
return | |
} | |
fmt.Printf("Joining room %s...\n", event.RoomID) | |
_, err := client.JoinRoomByID(event.RoomID) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("Joined room %s\n", event.RoomID) | |
client.SendText(event.RoomID, fmt.Sprintf("Hello from slurmMatrixbot, use this switch in your job submission script and i'll get back to you: --mail-user=matrix:%s\n", event.RoomID)) | |
}) | |
fmt.Println("Looking for rooms to join...") | |
client.Sync() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment