From 7fffdf24f1e7b1b5bb6f6419da3dce58bc5db501 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Thu, 22 Aug 2019 11:28:43 +0200 Subject: [PATCH] Separate lib and client --- draftbot/{ => cmd/cgdraftbot}/main.go | 3 ++- draftbot/cube.go | 2 +- draftbot/draftbot.go | 12 +++++++----- draftbot/draftbot.messages.go | 2 +- draftbot/draftbot_test.go | 2 +- draftbot/session.go | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) rename draftbot/{ => cmd/cgdraftbot}/main.go (95%) diff --git a/draftbot/main.go b/draftbot/cmd/cgdraftbot/main.go similarity index 95% rename from draftbot/main.go rename to draftbot/cmd/cgdraftbot/main.go index 58fcc04..f0279dc 100644 --- a/draftbot/main.go +++ b/draftbot/cmd/cgdraftbot/main.go @@ -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") diff --git a/draftbot/cube.go b/draftbot/cube.go index 2e0ce25..d08793b 100644 --- a/draftbot/cube.go +++ b/draftbot/cube.go @@ -1,4 +1,4 @@ -package main +package draftbot import ( "encoding/json" diff --git a/draftbot/draftbot.go b/draftbot/draftbot.go index 8edb342..5084f51 100644 --- a/draftbot/draftbot.go +++ b/draftbot/draftbot.go @@ -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) } diff --git a/draftbot/draftbot.messages.go b/draftbot/draftbot.messages.go index 9319441..6575468 100644 --- a/draftbot/draftbot.messages.go +++ b/draftbot/draftbot.messages.go @@ -1,4 +1,4 @@ -package main +package draftbot import ( "fmt" diff --git a/draftbot/draftbot_test.go b/draftbot/draftbot_test.go index 82a01a0..d68105c 100644 --- a/draftbot/draftbot_test.go +++ b/draftbot/draftbot_test.go @@ -1,4 +1,4 @@ -package main_test +package draftbot_test import ( "fmt" diff --git a/draftbot/session.go b/draftbot/session.go index 9eb85e4..cd8c04c 100644 --- a/draftbot/session.go +++ b/draftbot/session.go @@ -1,4 +1,4 @@ -package main +package draftbot import ( "errors"