-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (48 loc) · 1.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"log"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
"os"
)
func login(config Config) (*mautrix.Client, error) {
client, err := mautrix.NewClient(config.Homeserver, "", "")
if err != nil {
return nil, err
}
resp, err := client.Login(&mautrix.ReqLogin{
Type: "m.login.password",
Identifier: mautrix.UserIdentifier{
Type: mautrix.IdentifierType("m.id.user"),
User: config.Username,
},
Password: config.Password,
})
if err != nil {
return nil, err
}
client.SetCredentials(resp.UserID, resp.AccessToken)
log.Println("logged in to matrix.org")
return client, err
}
func main() {
config, err := parseArgs()
if err != nil {
log.Println(err)
os.Exit(0)
}
client, err := login(config)
if err != nil {
log.Println(err)
os.Exit(0)
}
bot := GocoinBot{ID: client.UserID}
syncer := client.Syncer.(*mautrix.DefaultSyncer)
syncer.OnEventType(event.EventMessage, func(source mautrix.EventSource, matrixEvent *event.Event) {
bot.HandleMessage(client, *matrixEvent)
})
err = client.Sync()
if err != nil {
log.Println(err)
}
}