From 4c1f81db804ca6215a0f71ccafa5588a128b1cf1 Mon Sep 17 00:00:00 2001 From: shoopea Date: Tue, 9 Jul 2019 15:48:21 +0800 Subject: [PATCH] test --- bot.go | 35 ++++++++++++++++++++++++++++++++++- client.go | 8 +++----- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/bot.go b/bot.go index 214bd4f..bb3f7e4 100644 --- a/bot.go +++ b/bot.go @@ -39,6 +39,7 @@ func BotHandlers(b *tb.Bot) { b.Handle("/help", botHelp) b.Handle("/get_item_id", botGetItemId) + b.Handle("/clients", botGetClients) b.Handle(tb.OnPhoto, botPhoto) b.Handle(tb.OnChannelPost, botChannelPost) @@ -102,7 +103,9 @@ func botHelp(m *tb.Message) { /timer "msg" - schedule msg for client in ETA /g_stock - check guild's vault /backup_export - export message database -/backup_import - import message database from URL`, +/backup_import - import message database from URL +/get_item_id - identify item_id from string +/clients - list all connected clients`, FromMsgID64: int64(m.ID), FromChatID64: m.Chat.ID, } @@ -158,6 +161,36 @@ func botTest(m *tb.Message) { return } +func botGetClients(m *tb.Message) { + if !m.Private() { + return + } + if _, ok := clientsKeepAlive.Load(m.Chat.ID); ok { + var string ret + clientsCW.Range(func(k, v interface{}) bool { + c := v.(*ChatWarsClient) + ret := fmt.Sprintf("%s%s | UserID : %d | TelegramID : %d\n", ret, c.UserID64, c.TelegramID64) + return true + }) + c := TGCommand{ + Type: commandReplyMsg, + Text: ret, + FromMsgID64: int64(m.ID), + FromChatID64: m.Chat.ID, + } + TGCmdQueue <- c + } else { + c := TGCommand{ + Type: commandReplyMsg, + Text: "Client not registered", + FromMsgID64: int64(m.ID), + FromChatID64: m.Chat.ID, + } + TGCmdQueue <- c + } + return +} + func botMsgRescan(m *tb.Message) { if !m.Private() { return diff --git a/client.go b/client.go index 92d32f0..b39e387 100644 --- a/client.go +++ b/client.go @@ -118,11 +118,9 @@ func clientMsgGRolesAck(m *ChatWarsMessageGRolesAck) { } func clientGetUserID64(tgUserID64 int64) (int64, error) { - if _, ok := clientsQueue[tgUserID64]; ok { - if v, ok := clientsCW.Load(tgUserID64); ok { - c := v.(*ChatWarsClient) - return c.UserID64, nil - } + if v, ok := clientsCW.Load(tgUserID64); ok { + c := v.(*ChatWarsClient) + return c.UserID64, nil } return 0, errors.New("Unknown user_id.") }