aboutsummaryrefslogtreecommitdiff
path: root/telegram/commands.go
diff options
context:
space:
mode:
Diffstat (limited to 'telegram/commands.go')
-rw-r--r--telegram/commands.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/telegram/commands.go b/telegram/commands.go
index b26a971..5f02c26 100644
--- a/telegram/commands.go
+++ b/telegram/commands.go
@@ -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: