From bd215b8e47ce68ca32ec828f60bd8856347fded4 Mon Sep 17 00:00:00 2001 From: shoopea Date: Mon, 6 May 2019 15:25:57 +0800 Subject: [PATCH] upd --- def.go | 4 ++++ main.go | 18 +++++++++--------- workers.go | 7 ++++++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/def.go b/def.go index d9c15c5..9c9a40f 100644 --- a/def.go +++ b/def.go @@ -23,4 +23,8 @@ const ( objSubTypeMessageHero = 7 objSubTypeMessageMe = 8 objSubTypeMessageInventory = 9 + + MQGetMsgWorkers = 3 + SQLCWMsgWorkers = 6 + SQLIdentifyMsgWorkers = 6 ) diff --git a/main.go b/main.go index 3c68703..6948145 100644 --- a/main.go +++ b/main.go @@ -43,9 +43,9 @@ var ( db *sql.DB - cfg Config - MQCWMsgQueue chan ChatWarsMessage - SQLMsgIdQueue chan int64 + cfg Config + MQCWMsgQueue chan ChatWarsMessage + SQLMsgIdentifyQueue chan int64 ) func PrintText(m *tb.Message) { @@ -90,16 +90,16 @@ func main() { go StartBot() MQCWMsgQueue = make(chan ChatWarsMessage, 100) - SQLMsgIdQueue = make(chan int64, 100) + SQLMsgIdentifyQueue = make(chan int64, 100) - for w := 1; w <= 3; w++ { + for w := 1; w <= MQGetMsgWorkers; w++ { go MQGetMsgWorker(w, MQCWMsgQueue) } - for w := 1; w <= 6; w++ { - go SQLCWMsgWorker(w, MQCWMsgQueue, SQLMsgIdQueue) + for w := 1; w <= SQLCWMsgWorkers; w++ { + go SQLCWMsgWorker(w, MQCWMsgQueue, SQLMsgIdentifyQueue) } - for w := 1; w <= 6; w++ { - go SQLIdentifyMsgWorker(w, SQLMsgIdQueue) + for w := 1; w <= SQLIdentifyMsgWorkers; w++ { + go SQLIdentifyMsgWorker(w, SQLMsgIdentifyQueue) } fmt.Println("Started !") diff --git a/workers.go b/workers.go index 1a202dd..34d9ab9 100644 --- a/workers.go +++ b/workers.go @@ -74,7 +74,12 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) { m, err := getMsg(objId) logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Retrieving message.") if err == nil { - log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Message retrieved\n%s\n", m.Text) + log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Message retrieved (%d)\n%s\n", objId, m.Text) + // War reports + r := regexp.MustCompile(`^(?P[.]{1})(?P(\[[A-Z]{3}\]){0,1})(?P(\[[A-Za-z0-9 ]*\]){1}) ⚔:(?P[0-9]+) ?:(?P[0-9]+) Lvl: (?P[0-9]+)(?s:.*)$`) + if r.FindStringSubmatch(item) != nil { + log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : War report identified (%d)\n", objId) + } } } log.Printf("SQLIdentifyMsgWorker[" + strconv.Itoa(id) + "] : Closing.")