Support /join @publicgroup syntax

This commit is contained in:
Bohdan Horbeshko 2022-06-22 14:03:18 -04:00
parent 5698ce62c0
commit ebc2f244d7

View file

@ -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,18 +623,36 @@ 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
}
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":
if len(args) < 1 {