This commit is contained in:
shoopea 2019-07-09 15:48:21 +08:00
parent 0da3fcf241
commit 4c1f81db80
2 changed files with 37 additions and 6 deletions

35
bot.go
View File

@ -39,6 +39,7 @@ func BotHandlers(b *tb.Bot) {
b.Handle("/help", botHelp) b.Handle("/help", botHelp)
b.Handle("/get_item_id", botGetItemId) b.Handle("/get_item_id", botGetItemId)
b.Handle("/clients", botGetClients)
b.Handle(tb.OnPhoto, botPhoto) b.Handle(tb.OnPhoto, botPhoto)
b.Handle(tb.OnChannelPost, botChannelPost) b.Handle(tb.OnChannelPost, botChannelPost)
@ -102,7 +103,9 @@ func botHelp(m *tb.Message) {
/timer <ETA> "msg" - schedule msg for client in ETA /timer <ETA> "msg" - schedule msg for client in ETA
/g_stock - check guild's vault /g_stock - check guild's vault
/backup_export - export message database /backup_export - export message database
/backup_import <URL> - import message database from URL`, /backup_import <URL> - import message database from URL
/get_item_id <string> - identify item_id from string
/clients - list all connected clients`,
FromMsgID64: int64(m.ID), FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID, FromChatID64: m.Chat.ID,
} }
@ -158,6 +161,36 @@ func botTest(m *tb.Message) {
return 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) { func botMsgRescan(m *tb.Message) {
if !m.Private() { if !m.Private() {
return return

View File

@ -118,11 +118,9 @@ func clientMsgGRolesAck(m *ChatWarsMessageGRolesAck) {
} }
func clientGetUserID64(tgUserID64 int64) (int64, error) { func clientGetUserID64(tgUserID64 int64) (int64, error) {
if _, ok := clientsQueue[tgUserID64]; ok { if v, ok := clientsCW.Load(tgUserID64); ok {
if v, ok := clientsCW.Load(tgUserID64); ok { c := v.(*ChatWarsClient)
c := v.(*ChatWarsClient) return c.UserID64, nil
return c.UserID64, nil
}
} }
return 0, errors.New("Unknown user_id.") return 0, errors.New("Unknown user_id.")
} }