76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"os/signal"
|
|
"sync"
|
|
"syscall"
|
|
|
|
"git.saintnet.tech/stryan/vega/botlib"
|
|
"maunium.net/go/mautrix"
|
|
)
|
|
|
|
func main() {
|
|
c := &botlib.Config{
|
|
Userid: "@testbot:saintnet.tech",
|
|
Server: "matrix.saintnet.tech",
|
|
Token: "MDAxYmxvY2F0aW9uIHNhaW50bmV0LnRlY2gKMDAxM2lkZW50aWZpZXIga2V5CjAwMTBjaWQgZ2VuID0gMQowMDI5Y2lkIHVzZXJfaWQgPSBAdGVzdGJvdDpzYWludG5ldC50ZWNoCjAwMTZjaWQgdHlwZSA9IGFjY2VzcwowMDIxY2lkIG5vbmNlID0gemlKZGs9bmJhcjp1eThIXgowMDJmc2lnbmF0dXJlIE4x0sbUS9lN-fi0KjJmEmpx6_wpYzgvk4k2Eugtkva7Cg",
|
|
Name: "TestBot",
|
|
Owner: "@stryan:saintnet.tech",
|
|
Prefix: "!tb",
|
|
}
|
|
b := botlib.NewBot(c)
|
|
tb := &TestBot{
|
|
Bot: b,
|
|
Conf: c,
|
|
Jobs: make(chan *mautrix.Event, 100),
|
|
}
|
|
tb.InitActions()
|
|
syncer := botlib.NewCustomSyncer("@testbot:saintnet.tech", b.Client.Store)
|
|
syncer.OnEventType(mautrix.EventMessage, tb.QueueMessage)
|
|
syncer.OnEventType(mautrix.StateMember, b.DefaultHandleMember)
|
|
|
|
b.Client.Syncer = syncer
|
|
|
|
wg := new(sync.WaitGroup)
|
|
|
|
go func() {
|
|
wg.Add(1)
|
|
err := b.Client.Sync()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
wg.Done()
|
|
}()
|
|
log.Println("Syncing enabled")
|
|
err := b.LeaveEmptyRooms()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
tb.LoadState()
|
|
_, err = b.CreateManagementRoom()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
log.Println("Begining main phase")
|
|
cancelChan := make(chan bool)
|
|
for i := 0; i < 4; i++ {
|
|
go func() {
|
|
wg.Add(1)
|
|
tb.MessageHandler(cancelChan)
|
|
wg.Done()
|
|
}()
|
|
}
|
|
sigs := make(chan os.Signal, 1)
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
|
go func() {
|
|
sig := <-sigs
|
|
log.Printf("Received sig %v", sig)
|
|
cancelChan <- true
|
|
tb.Shutdown()
|
|
}()
|
|
|
|
wg.Wait()
|
|
}
|