Separate lib and client
This commit is contained in:
parent
01f9b3cfd4
commit
7fffdf24f1
6 changed files with 13 additions and 10 deletions
|
@ -14,6 +14,7 @@ import (
|
|||
"git.fromouter.space/Artificiale/moa/sd"
|
||||
botapi "git.fromouter.space/mcg/cardgage/client/bot"
|
||||
"git.fromouter.space/mcg/draft/mlp"
|
||||
bot "git.fromouter.space/mcg/mlp-server-tools/draftbot"
|
||||
"github.com/go-kit/kit/log"
|
||||
)
|
||||
|
||||
|
@ -89,7 +90,7 @@ func runBot(name string, games, tags []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
draftbot := NewDraftBot(wsbot, name)
|
||||
draftbot := bot.NewDraftBot(wsbot, name)
|
||||
wsbot.Listen(draftbot.OnMessage)
|
||||
|
||||
return errors.New("eof")
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package draftbot
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package main
|
||||
package draftbot
|
||||
|
||||
import (
|
||||
room "git.fromouter.space/mcg/cardgage/room/api"
|
||||
"github.com/go-kit/kit/log"
|
||||
)
|
||||
|
||||
// DraftBot is the functional part of draftbot
|
||||
type DraftBot struct {
|
||||
API BotInterface
|
||||
Logger log.Logger
|
||||
Name string
|
||||
Rooms map[string]roomInfo
|
||||
Sessions map[string]*session
|
||||
|
@ -38,8 +40,8 @@ func NewDraftBot(botAPI BotInterface, name string) *DraftBot {
|
|||
func (d *DraftBot) OnMessage(msg room.ServerMessage) {
|
||||
switch msg.Type {
|
||||
case room.MsgMessage:
|
||||
if logAll {
|
||||
logger.Log("event", "message",
|
||||
if d.Logger != nil {
|
||||
d.Logger.Log("event", "message",
|
||||
"roomid", msg.RoomID,
|
||||
"from", msg.Message.From,
|
||||
"to", msg.Message.To,
|
||||
|
@ -50,8 +52,8 @@ func (d *DraftBot) OnMessage(msg room.ServerMessage) {
|
|||
d.handleMessage(msg.RoomID, *msg.Message)
|
||||
}
|
||||
case room.MsgEvent:
|
||||
if logAll {
|
||||
logger.Log("event", "event",
|
||||
if d.Logger != nil {
|
||||
d.Logger.Log("event", "event",
|
||||
"roomid", msg.RoomID,
|
||||
"content", msg.Event.Message)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package draftbot
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package main_test
|
||||
package draftbot_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package draftbot
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
|
Loading…
Reference in a new issue