start parsing commands
This commit is contained in:
parent
4607074cc1
commit
9d76a55e70
@ -35,8 +35,10 @@ func (d *Dealer) ConnectToMatrix(homeserver, uname, passwd string) {
|
|||||||
}
|
}
|
||||||
fmt.Println("Login successful")
|
fmt.Println("Login successful")
|
||||||
d.Client = client
|
d.Client = client
|
||||||
//Set up event handlers
|
}
|
||||||
syncer := client.Syncer.(*mautrix.DefaultSyncer)
|
|
||||||
|
func (d *Dealer) RegisterHandlers() {
|
||||||
|
syncer := d.Client.Syncer.(*mautrix.DefaultSyncer)
|
||||||
syncer.OnEventType(event.StateMember, func(source mautrix.EventSource, evt *event.Event) {
|
syncer.OnEventType(event.StateMember, func(source mautrix.EventSource, evt *event.Event) {
|
||||||
if evt.Sender == d.Client.UserID {
|
if evt.Sender == d.Client.UserID {
|
||||||
return
|
return
|
||||||
@ -93,6 +95,7 @@ func (d *Dealer) ConnectToMatrix(homeserver, uname, passwd string) {
|
|||||||
log.Println("ignoring message event from non player")
|
log.Println("ignoring message event from non player")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//parse as game command
|
||||||
resp := match.ParseAction(evt.Content.AsMessage().Body)
|
resp := match.ParseAction(evt.Content.AsMessage().Body)
|
||||||
if resp.Private {
|
if resp.Private {
|
||||||
//respond privately
|
//respond privately
|
||||||
@ -113,7 +116,6 @@ func (d *Dealer) ConnectToMatrix(homeserver, uname, passwd string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dealer) SetupRooms(domain string) {
|
func (d *Dealer) SetupRooms(domain string) {
|
||||||
|
1
main.go
1
main.go
@ -30,6 +30,7 @@ func main() {
|
|||||||
dealer.ConnectToMatrix(homeserver, username, password)
|
dealer.ConnectToMatrix(homeserver, username, password)
|
||||||
//create room #tomequeue:homeserver
|
//create room #tomequeue:homeserver
|
||||||
dealer.SetupRooms(homeserverDomain)
|
dealer.SetupRooms(homeserverDomain)
|
||||||
|
dealer.RegisterHandlers()
|
||||||
err = dealer.Client.Sync()
|
err = dealer.Client.Sync()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
15
match.go
15
match.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.saintnet.tech/tomecraft/tome_game"
|
"git.saintnet.tech/tomecraft/tome_game"
|
||||||
@ -36,7 +37,19 @@ func NewMatch() *Match {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Match) ParseAction(msg string) MatchResp {
|
func (m *Match) ParseAction(msg string) MatchResp {
|
||||||
panic("PARSEACTION UNIMPLEMENTED")
|
var cmd *tome_lib.Command
|
||||||
|
err := json.Unmarshal([]byte(msg), cmd)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error unmarshaling gamecommand %v", err)
|
||||||
|
return MatchResp{Body: "", Private: false}
|
||||||
|
}
|
||||||
|
res := m.Game.Parse(cmd)
|
||||||
|
match_res := MatchResp{
|
||||||
|
Body: res.String(),
|
||||||
|
Private: (cmd.Type == tome_lib.ActCmd && cmd.String() == "d"),
|
||||||
|
}
|
||||||
|
return match_res
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Match) JoinOrLeave(gameRoom *mautrix.Room, evt *event.Event) {
|
func (m *Match) JoinOrLeave(gameRoom *mautrix.Room, evt *event.Event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user