/
telegram.go
61 lines (53 loc) · 1.11 KB
/
telegram.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
package main
import (
"log"
"time"
tb "gopkg.in/tucnak/telebot.v2"
)
func initTelegramBot() *tb.Bot {
b, err := tb.NewBot(tb.Settings{
Token: conf.TelegramAPIKey,
Poller: &tb.LongPoller{Timeout: TelPollerTimeout * time.Second},
Verbose: conf.Debug,
ParseMode: tb.ModeHTML,
})
if err != nil {
log.Fatal(err)
}
return b
}
func logTelegram(message string) {
group := &tb.Chat{ID: TelAnonOps}
if _, err := bot.Send(group, message); err != nil {
log.Println(err)
}
}
func messageTelegram(message string, groupId int) {
var group *tb.Chat
if conf.Dev {
group = &tb.Chat{ID: TelAnonOps}
} else {
group = &tb.Chat{ID: int64(groupId)}
}
if _, err := bot.Send(group, message); err != nil {
log.Println(err)
}
}
func messageTelegramPin(message string, groupId int) {
var group *tb.Chat
if conf.Dev {
group = &tb.Chat{ID: TelAnonOps}
} else {
group = &tb.Chat{ID: int64(groupId)}
}
if m, err := bot.Send(group, message); err != nil {
log.Println(err)
logTelegram(err.Error())
} else {
err := bot.Pin(m)
if err != nil {
log.Println(err)
logTelegram(err.Error())
}
}
}