Add /invite command

calls
bodqhrohro 4 years ago
parent 4679c01a99
commit 9f54309b30

@ -3,6 +3,7 @@ package telegram
import (
"fmt"
"github.com/pkg/errors"
"math"
"regexp"
"strconv"
"strings"
@ -443,6 +444,37 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool)
return err.Error(), true
}
}
// invite @username to current groupchat
case "invite":
if len(args) < 1 {
return notEnoughArguments, true
}
if chatID < 0 {
userID, err := strconv.ParseInt(args[0], 10, 32)
// couldn't parse the id, try to lookup as a username
if err != nil {
chat, err := c.client.SearchPublicChat(&client.SearchPublicChatRequest{
Username: args[0],
})
if err != nil {
return err.Error(), true
}
userID = chat.Id
if userID <= 0 || userID > math.MaxInt32 {
return "Not a user", true
}
}
_, err = c.client.AddChatMember(&client.AddChatMemberRequest{
ChatId: chatID,
UserId: int32(userID),
})
if err != nil {
return err.Error(), true
}
}
case "help":
return helpString(helpTypeChat), true
default:

Loading…
Cancel
Save