test
This commit is contained in:
parent
0da3fcf241
commit
4c1f81db80
35
bot.go
35
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 <ETA> "msg" - schedule msg for client in ETA
|
||||
/g_stock - check guild's vault
|
||||
/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),
|
||||
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
|
||||
|
@ -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.")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user