add userlist/whois commands

This commit is contained in:
mappu 2018-06-03 19:15:16 +12:00
parent 246d2f12c8
commit dd5fa7f900
3 changed files with 59 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"html"
"log"
"sort"
"strings"
"sync"
"time"
@ -542,6 +543,51 @@ func (this *NTFServer) HandleDirectMessage(update telegram.Update) error {
return respond("You are either already joined (try /quit first), or not yet registered (try /join first).")
}
} else if strings.HasPrefix(msg, "/userlist") {
conn, ok := this.conns[hubNick]
if !ok {
return respond("Can't get userlist for you (No upstream hub connection)")
}
usernames := make([]string, 0)
err := conn.Users(func(umap *map[string]libnmdc.UserInfo) error {
for k, _ := range *umap {
usernames = append(usernames, k)
}
return nil
})
if err != nil {
log.Printf("Error retrieving userlist: %s", err.Error())
return respond("Can't get userlist for you (internal error)")
}
sort.Strings(usernames)
return respond("Online users: " + strings.Join(usernames, " "))
} else if strings.HasPrefix(msg, "/whois ") {
target := msg[7:]
conn, ok := this.conns[hubNick]
if !ok {
return respond("Can't get user details for you (No upstream hub connection)")
}
var userinfo libnmdc.UserInfo
var exists bool
err := conn.Users(func(umap *map[string]libnmdc.UserInfo) error {
userinfo, exists = (*umap)[target]
return nil
})
if err != nil {
log.Printf("Error retrieving userlist: %s", err.Error())
return respond("Can't get user details for you (internal error)")
}
if !exists {
return respond(fmt.Sprintf("There is no online user '%s'.", target))
}
return respond(fmt.Sprintf("Description: %s\nShare size: %d\nClient: %s %s", userinfo.Description, userinfo.ShareSize, userinfo.ClientTag, userinfo.ClientVersion))
} else if strings.HasPrefix(msg, "/quit") {
this.kickAndDrop(userID)
@ -568,6 +614,8 @@ Available commands:
/join [hubnick] - Register as 'hubnick' and join ` + this.config.HubDescription + `
/rejoin - Re-invite if you are already registered
/pm [recipient] [message] - Send a native PM (if connected)
/userlist - List native online users
/whois [hubnick] - Check if native user is online, and read their description
/quit - Unregister your nick and leave the group chat
`

View File

@ -14,6 +14,13 @@ Written in Go
Create a new telegram bot
- Use BotFather to create a new bot
- Use BotFather to disable its privacy mode for group chats
- Use BotFather to add commands. Recommendation:
`
setup - List available commands
userlist - List native online users
quit - Leave the group chat
`
Create a telegram group
- Manually create a group chat and add the bot to it

View File

@ -32,9 +32,9 @@
[ ] Editing Messages support
[ ] Extra DM commands
[ ] Get native userlist
[ ] Check if native user is online
[ ] Get native user description / sharesize / ...
[X] Extra DM commands
[X] Get native userlist
[X] Check if native user is online
[X] Get native user description / sharesize / ...
[ ] Publish