aboutsummaryrefslogtreecommitdiff
path: root/telegram
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2022-06-22 21:03:18 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2022-06-22 21:03:18 +0300
commitebc2f244d75edf338142f9f023d984b3c9605a67 (patch)
tree4e1e83b1d5d3557f849577814d60a8e92da38edb /telegram
parent5698ce62c0c78066150e5c52650fe25e7ebcc3c7 (diff)
Support /join @publicgroup syntax
Diffstat (limited to 'telegram')
-rw-r--r--telegram/commands.go32
1 files changed, 25 insertions, 7 deletions
diff --git a/telegram/commands.go b/telegram/commands.go
index b2396b8..bd9f0f8 100644
--- a/telegram/commands.go
+++ b/telegram/commands.go
@@ -61,7 +61,7 @@ var chatCommands = map[string]command{
"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"},
"add": command{"@username", "add @username to your chat list"},
- "join": command{"https://t.me/invite_link", "join to chat via invite link"},
+ "join": command{"https://t.me/invite_link", "join to chat via invite link or @publicname"},
"group": command{"title", "create groupchat «title» with current user"},
"supergroup": command{"title description", "create new supergroup «title» with «description»"},
"channel": command{"title description", "create new channel «title» with «description»"},
@@ -623,17 +623,35 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
}
c.subscribeToID(chat.Id, chat)
- // join https://t.me/publichat
+ // join https://t.me/publichat or @publicchat
case "join":
if len(args) < 1 {
return notEnoughArguments, true
}
- _, err := c.client.JoinChatByInviteLink(&client.JoinChatByInviteLinkRequest{
- InviteLink: args[0],
- })
- if err != nil {
- return err.Error(), true
+ if strings.HasPrefix(args[0], "@") {
+ chat, err := c.client.SearchPublicChat(&client.SearchPublicChatRequest{
+ Username: args[0],
+ })
+ if err != nil {
+ return err.Error(), true
+ }
+ if chat == nil {
+ return "No error, but chat is nil", true
+ }
+ _, err = c.client.JoinChat(&client.JoinChatRequest{
+ ChatId: chat.Id,
+ })
+ if err != nil {
+ return err.Error(), true
+ }
+ } else {
+ _, err := c.client.JoinChatByInviteLink(&client.JoinChatByInviteLinkRequest{
+ InviteLink: args[0],
+ })
+ if err != nil {
+ return err.Error(), true
+ }
}
// create new supergroup
case "supergroup":