-
Notifications
You must be signed in to change notification settings - Fork 0
/
telegram.go
70 lines (53 loc) · 1.41 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
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"log"
"time"
"gopkg.in/telegram-bot-api.v4"
)
func formatMessage(tracks []track, period timeframe, from, to time.Time) string {
var s string
if debug {
s += fmt.Sprint("/// SENT IN DEBUG MODE ///\n\n")
}
s += fmt.Sprintf("*%s*\n", periodToTitle[period])
s += fmt.Sprintf("%v - %v\n\n", from.Format(outputTimeFormat), to.Format(outputTimeFormat))
for _, tr := range tracks {
s += fmt.Sprintf("[🎵](%v) %v : [%v](%v)\n", produceYandexMusicLink(tr.Artist, tr.Name), tr.Artist, tr.Name, tr.URL)
}
s += "\nlistened accordingly by:\n\n"
for i, tr := range tracks {
s += fmt.Sprintf("%v. *%v* - %v %v\n", i+1, names[tr.username], tr.Playcount, func() string {
if i == 0 {
return "times"
}
return ""
}())
}
s += fmt.Sprintf("\n[👾](%v) ваш бот", "https://github.com/uladbohdan/music504")
if *enableTips {
s += fmt.Sprintf("\ntip: emojis are clickable!")
}
return s
}
func publishTracks(message string) error {
bot, err := tgbotapi.NewBotAPI(telegramBotToken)
if err != nil {
return err
}
if debug {
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
}
var channelName string
if debug {
channelName = channelDebugName
} else {
channelName = channelOfficialName
}
msg := tgbotapi.NewMessageToChannel(channelName, message)
msg.ParseMode = "Markdown"
msg.DisableWebPagePreview = true
bot.Send(msg)
return nil
}