-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitbot.go
More file actions
40 lines (31 loc) · 707 Bytes
/
initbot.go
File metadata and controls
40 lines (31 loc) · 707 Bytes
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
package main
import (
"io/ioutil"
"log"
"strings"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
)
const token = "token.txt"
func GetToken(filename string) string {
token, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
tokenRep := strings.Replace(string(token), "\n", "", 1)
return tokenRep
}
func InitBot() (*tgbotapi.BotAPI, tgbotapi.UpdatesChannel) {
bot, err := tgbotapi.NewBotAPI(GetToken(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)
if err != nil {
log.Panic(err)
}
return bot, updates
}