This repository was archived by the owner on Oct 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfsub.go
More file actions
101 lines (82 loc) · 2.17 KB
/
Copy pathfsub.go
File metadata and controls
101 lines (82 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
"log"
"sync"
"time"
"github.com/PaulSonOfLars/gotgbot/v2"
)
var (
chatInviteLinks = make(map[int64]string)
chatCacheMutex sync.RWMutex
memberStatuses = map[string]bool{
"member": true,
"administrator": true,
"creator": true,
}
)
func retryMarkup(b *gotgbot.Bot, args, link string) *gotgbot.InlineKeyboardMarkup {
buttons := [][]gotgbot.InlineKeyboardButton{
{
{Text: "Jᴏɪɴ", Url: link},
},
}
if args != "" {
buttons = append(buttons, []gotgbot.InlineKeyboardButton{
{Text: "Tʀʏ ᴀɢᴀɪɴ", Url: fmt.Sprintf("https://t.me/%s?start=%s", b.Username, args)},
})
}
return &gotgbot.InlineKeyboardMarkup{
InlineKeyboard: buttons,
}
}
func fetchInviteLink(b *gotgbot.Bot, chatID int64) (string, error) {
chatCacheMutex.RLock()
if link, found := chatInviteLinks[chatID]; found {
chatCacheMutex.RUnlock()
return link, nil
}
chatCacheMutex.RUnlock()
chatCacheMutex.Lock()
defer chatCacheMutex.Unlock()
if link, found := chatInviteLinks[chatID]; found {
return link, nil
}
chat, err := b.GetChat(chatID, nil)
if err != nil {
log.Printf("Error getting chat: %s", err)
return "", err
}
chatInviteLinks[chatID] = chat.InviteLink
return chat.InviteLink, nil
}
func fSub(b *gotgbot.Bot, userId int64, arg string) (bool, error) {
chats := FSubIds
if len(chats) == 0 {
log.Print("FSub IDs not set")
return true, nil
}
for _, chatID := range chats {
userMember, err := b.GetChatMember(chatID, userId, nil)
if err != nil {
return false, fmt.Errorf("error getting chat member: %s", err)
}
mem := userMember.MergeChatMember()
if !memberStatuses[mem.Status] {
inviteLink, err := fetchInviteLink(b, chatID)
if err != nil || inviteLink == "" {
return false, fmt.Errorf("invite link not available")
}
btn := retryMarkup(b, arg, inviteLink)
_, err = b.SendMessage(userId, "❌ You must be a member of the channel to use this bot.\nPlease join the channel and try again.", &gotgbot.SendMessageOpts{
ReplyMarkup: btn,
})
if err != nil {
log.Printf("Error sending message: %s", err)
}
return false, nil
}
time.Sleep(500 * time.Millisecond)
}
return true, nil
}