/
golyrics-tgbot.go
52 lines (41 loc) · 1.04 KB
/
golyrics-tgbot.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
package main
import (
"os"
"github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/joho/godotenv"
"github.com/mamal72/golyrics"
)
func lyrics(input string) string {
if input == "help" || input == "/help" {
return "Type your song name like this example: Blackfield:Some Day"
}
suggestions, err := golyrics.SearchTrack(input)
if err != nil || len(suggestions) == 0 {
return "Couldn't find your requested song"
}
track := suggestions[0]
err = track.FetchLyrics()
if err != nil {
panic(err)
}
result := "===" + track.Name + " by " + track.Artist + "===" + "\n\n " + track.Lyrics
return result
}
func main() {
err := godotenv.Load()
bot, err := tgbotapi.NewBotAPI(os.Getenv("TG_TOKEN"))
if err != nil {
panic(err)
}
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, err := bot.GetUpdatesChan(u)
for update := range updates {
if update.Message == nil {
continue
}
msg := tgbotapi.NewMessage(update.Message.Chat.ID, lyrics(update.Message.Text))
msg.ReplyToMessageID = update.Message.MessageID
bot.Send(msg)
}
}