-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (42 loc) · 1.27 KB
/
main.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
package main
import (
"log"
"math/rand"
"regexp"
"strings"
"time"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
func main() {
bot, err := tgbotapi.NewBotAPI("YOUR_TOKEN")
if err != nil {
log.Panic(err)
}
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates := bot.GetUpdatesChan(u)
insertPart := []string{"Baka", "Jhonny", "Voody", "Gregory"}
templates := []string{"##insert sit on chair", "I love ##insert and ##insert!!", "##insert killed ##insert"}
insertPartReg := regexp.MustCompile(`##insert\b`)
for update := range updates {
if update.Message != nil {
if strings.HasPrefix(update.Message.Text, "/gen") {
rand.Seed(time.Now().UnixNano())
text := replace(templates[rand.Intn(len(templates))], insertPartReg, insertPart)
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
msg := tgbotapi.NewMessage(update.Message.Chat.ID, text)
msg.ReplyToMessageID = update.Message.MessageID
bot.Send(msg)
}
}
}
}
func replace(text string, reg *regexp.Regexp, textArr []string) string {
s := reg.ReplaceAllStringFunc(text, func(x string) string {
var r string = textArr[rand.Intn(len(textArr))]
return r
})
return s
}