Separate lib and client
All checks were successful
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Hamcha 2019-08-22 11:28:43 +02:00
parent 01f9b3cfd4
commit 7fffdf24f1
6 changed files with 13 additions and 10 deletions

View file

@ -14,6 +14,7 @@ import (
"git.fromouter.space/Artificiale/moa/sd" "git.fromouter.space/Artificiale/moa/sd"
botapi "git.fromouter.space/mcg/cardgage/client/bot" botapi "git.fromouter.space/mcg/cardgage/client/bot"
"git.fromouter.space/mcg/draft/mlp" "git.fromouter.space/mcg/draft/mlp"
bot "git.fromouter.space/mcg/mlp-server-tools/draftbot"
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
) )
@ -89,7 +90,7 @@ func runBot(name string, games, tags []string) error {
return err return err
} }
draftbot := NewDraftBot(wsbot, name) draftbot := bot.NewDraftBot(wsbot, name)
wsbot.Listen(draftbot.OnMessage) wsbot.Listen(draftbot.OnMessage)
return errors.New("eof") return errors.New("eof")

View file

@ -1,4 +1,4 @@
package main package draftbot
import ( import (
"encoding/json" "encoding/json"

View file

@ -1,12 +1,14 @@
package main package draftbot
import ( import (
room "git.fromouter.space/mcg/cardgage/room/api" room "git.fromouter.space/mcg/cardgage/room/api"
"github.com/go-kit/kit/log"
) )
// DraftBot is the functional part of draftbot // DraftBot is the functional part of draftbot
type DraftBot struct { type DraftBot struct {
API BotInterface API BotInterface
Logger log.Logger
Name string Name string
Rooms map[string]roomInfo Rooms map[string]roomInfo
Sessions map[string]*session Sessions map[string]*session
@ -38,8 +40,8 @@ func NewDraftBot(botAPI BotInterface, name string) *DraftBot {
func (d *DraftBot) OnMessage(msg room.ServerMessage) { func (d *DraftBot) OnMessage(msg room.ServerMessage) {
switch msg.Type { switch msg.Type {
case room.MsgMessage: case room.MsgMessage:
if logAll { if d.Logger != nil {
logger.Log("event", "message", d.Logger.Log("event", "message",
"roomid", msg.RoomID, "roomid", msg.RoomID,
"from", msg.Message.From, "from", msg.Message.From,
"to", msg.Message.To, "to", msg.Message.To,
@ -50,8 +52,8 @@ func (d *DraftBot) OnMessage(msg room.ServerMessage) {
d.handleMessage(msg.RoomID, *msg.Message) d.handleMessage(msg.RoomID, *msg.Message)
} }
case room.MsgEvent: case room.MsgEvent:
if logAll { if d.Logger != nil {
logger.Log("event", "event", d.Logger.Log("event", "event",
"roomid", msg.RoomID, "roomid", msg.RoomID,
"content", msg.Event.Message) "content", msg.Event.Message)
} }

View file

@ -1,4 +1,4 @@
package main package draftbot
import ( import (
"fmt" "fmt"

View file

@ -1,4 +1,4 @@
package main_test package draftbot_test
import ( import (
"fmt" "fmt"

View file

@ -1,4 +1,4 @@
package main package draftbot
import ( import (
"errors" "errors"