-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (50 loc) · 1.49 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
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"log"
"github.com/go-telegram-bot-api/telegram-bot-api"
"regexp"
"bytes"
"strings"
"io/ioutil"
)
func main() {
token, _ := ioutil.ReadFile("token.txt")
bot, err := tgbotapi.NewBotAPI(string(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, err := bot.GetUpdatesChan(u)
r, _ := regexp.Compile("(?i)\\b[a]+lter\\b")
ja, _ := regexp.Compile("(?i)\\b((j[a]+wo(h?)[l]+)|porsche|cayman)\\b")
for update := range updates {
if update.Message == nil {
continue
}
match := r.MatchString(update.Message.Text)
if match {
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
var buffer bytes.Buffer
alter := r.FindAllString(update.Message.Text, 1)
acount := len(alter[0]) - 4
buffer.WriteString(strings.Repeat("a", acount * 2))
buffer.WriteString("lter")
msg := tgbotapi.NewMessage(update.Message.Chat.ID, buffer.String())
msg.ReplyToMessageID = update.Message.MessageID
bot.Send(msg)
}
match = ja.MatchString(update.Message.Text)
if match {
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
var buffer bytes.Buffer
buffer.WriteString("PORSCHE CAYMAN S JUNGS! \r\n")
buffer.WriteString("JAWOLL JAAAAA!")
msg := tgbotapi.NewMessage(update.Message.Chat.ID, buffer.String())
msg.ReplyToMessageID = update.Message.MessageID
bot.Send(msg)
}
}
}