-
Notifications
You must be signed in to change notification settings - Fork 20
/
preWorks.go
84 lines (76 loc) · 2.58 KB
/
preWorks.go
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
package main
import (
"fmt"
"os"
"strconv"
"github.com/PaulSonOfLars/gotgbot/v2"
"github.com/PaulSonOfLars/gotgbot/v2/ext"
"github.com/StarkBotsIndustries/telegraph/v2"
)
// Change This As Per Convenience
func preWorks(b *gotgbot.Bot, ctx *ext.Context) error {
id := ctx.EffectiveMessage.From.Id
AddUser(id)
if (os.Getenv("MUST_JOIN")) == "" {
return nil
}
c, err := strconv.ParseInt(os.Getenv("MUST_JOIN"), 10, 64)
if err != nil {
fmt.Printf(parseIntFail, "MUST_JOIN")
return nil
}
cm, err := b.GetChatMember(c, id)
if err != nil {
fmt.Println("Failed to send must join message. Please check if MUST_JOIN is a valid Chat ID")
return nil
}
if cm.GetStatus() == "left" {
ch, _ := b.GetChat(c)
_, err = ctx.EffectiveMessage.Reply(
b,
fmt.Sprintf(`You must join <a href="%v">%v</a> to use this bot.`, ch.InviteLink, ch.Title),
&gotgbot.SendMessageOpts{
ParseMode: "html",
// ReplyMarkup: gotgbot.InlineKeyboardMarkup{
// InlineKeyboard: [][]gotgbot.InlineKeyboardButton{{
// {Text: "Join Channel", Url: ""},
// }},
// },
DisableWebPagePreview: true,
},
)
if err != nil {
fmt.Println("Failed to send must join message")
}
return ext.EndGroups
}
return nil
}
func checkForDefaultAccount(b *gotgbot.Bot, ctx *ext.Context) error {
user := ctx.EffectiveMessage.From
uDB := GetUser(user.Id)
if uDB.Account == "" {
shortName := user.FirstName
authorURL := ""
authorName := shortName
if user.Username != "" {
shortName = user.Username
authorURL = "https://t.me/" + user.Username
}
acc, _ := telegraph.CreateAccount(telegraph.CreateAccountOpts{ShortName: shortName, AuthorURL: authorURL, AuthorName: authorName})
SetDefaultAccount(user.Id, acc.AccessToken)
_, err := ctx.EffectiveMessage.Reply(b, defaultAccountMessage, &gotgbot.SendMessageOpts{ParseMode: "html"})
if err != nil {
return fmt.Errorf("failed to send defaultAccount Message: %v", err)
}
return nil
}
return nil
}
// Important for new users
var defaultAccountMessage = `
You seem to be a brand new user. I've created a new account for you which is now the default one. You can see it's info in /accounts message.
Whenever, the bot asks you for an account number to act on, use 0 to specify the default account. The number is same as seen in <code>/accounts</code> message.
But of course, you can create more accounts using the /create command. To use the newly created account while doing things, pass it's number as seen in <code>/accounts</code> message.
So want to create a page? Use <code>/page 0 page_title <in reply to html message></code>
`