aboutsummaryrefslogtreecommitdiff
path: root/telegram
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-12-08 16:32:43 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-12-08 16:32:43 +0300
commit9f54309b3037fd963f711093536da1068e7093b8 (patch)
treebfdca95ed627ede81f84a7aaf7296ad1c676590f /telegram
parent4679c01a994872da24d2f653d968db576b1b109a (diff)
Add /invite command
Diffstat (limited to 'telegram')
-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: