aboutsummaryrefslogtreecommitdiff
path: root/telegram/commands.go
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2023-06-01 23:37:38 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2023-06-01 23:37:38 +0300
commit8663a29e157aae6e68cc880a86b3a666da37bfc9 (patch)
tree8071a4381276bf743ca21a5a5b8da4930054fd5d /telegram/commands.go
parent75f0532193440294f4bbf7cd687174b5e9a16249 (diff)
Add /vcard command
Diffstat (limited to 'telegram/commands.go')
-rw-r--r--telegram/commands.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/telegram/commands.go b/telegram/commands.go
index 2a72219..ec06f36 100644
--- a/telegram/commands.go
+++ b/telegram/commands.go
@@ -64,6 +64,7 @@ var chatCommands = map[string]command{
"silent": command{"message", "send a message without sound"},
"schedule": command{"{online | 2006-01-02T15:04:05 | 15:04:05} message", "schedules a message either to timestamp or to whenever the user goes online"},
"forward": command{"message_id target_chat", "forwards a message"},
+ "vcard": command{"", "print vCard as text"},
"add": command{"@username", "add @username to your chat list"},
"join": command{"https://t.me/invite_link", "join to chat via invite link or @publicname"},
"group": command{"title", "create groupchat «title» with current user"},
@@ -172,6 +173,10 @@ func rawCmdArguments(cmdline string, start uint8) string {
return ""
}
+func keyValueString(key, value string) string {
+ return fmt.Sprintf("%s: %s", key, value)
+}
+
func (c *Client) unsubscribe(chatID int64) error {
return gateway.SendPresence(
c.xmpp,
@@ -636,6 +641,21 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
c.ProcessIncomingMessage(targetChatId, message)
}
}
+ // print vCard
+ case "vcard":
+ info, err := c.GetVcardInfo(chatID)
+ if err != nil {
+ return err.Error(), true
+ }
+ _, link := c.PermastoreFile(info.Photo, true)
+ entries := []string{
+ keyValueString("Chat title", info.Fn),
+ keyValueString("Photo", link),
+ keyValueString("Username", info.Nickname),
+ keyValueString("Full name", info.Given + " " + info.Family),
+ keyValueString("Phone number", info.Tel),
+ }
+ return strings.Join(entries, "\n"), true
// add @contact
case "add":
return c.cmdAdd(args), true