-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (47 loc) · 1.05 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
package main
import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"log"
"os"
"strings"
)
var (
bot, err = tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_TOKEN"))
)
func processQuery(update *tgbotapi.Update) {
location, err := downloadyou(update.Message.Text)
if err == nil {
path := strings.Split(location, "\n")[0]
audio := tgbotapi.NewAudio(update.Message.Chat.ID, tgbotapi.FilePath(path))
_, err = bot.Send(audio)
if err != nil {
log.Print(err)
return
}
e := os.Remove(path)
if e != nil {
log.Print("Failed to remove: " + path)
}
} else {
log.Print(err)
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Couldn't process your request")
bot.Send(msg)
}
}
func main() {
if err != nil {
return
}
bot.Debug = true
updateConfig := tgbotapi.NewUpdate(0)
updateConfig.Timeout = 30
updates := bot.GetUpdatesChan(updateConfig)
for update := range updates {
if update.Message == nil {
continue
}
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Loading...")
bot.Send(msg)
go processQuery(&update)
}
}