This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
/
main.go
72 lines (60 loc) · 2.68 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"log"
"github.com/bwmarrin/discordgo"
botPkg "github.com/trickybestia/flopper/internal/bot"
"github.com/trickybestia/flopper/internal/musicplayer"
)
func main() {
args := parseArgs()
config := loadConfig(args.Config)
log.SetFlags(config.GetLoggerFlags())
bot, err := botPkg.New(config.Token)
if err != nil {
log.Fatalln(err)
}
bot.Session.AddHandler(func(s *discordgo.Session, event *discordgo.Ready) {
switch config.StatusType {
case "none":
break
case "listening":
bot.Session.UpdateListeningStatus(config.Status)
case "watching":
bot.Session.UpdateWatchStatus(0, config.Status)
case "playing":
bot.Session.UpdateGameStatus(0, config.Status)
case "streaming":
bot.Session.UpdateStreamingStatus(0, config.Status, config.StreamingUrl)
default:
log.Fatalf("`%s` is invalid value for StatusType", config.StatusType)
}
})
bot.CommandPrefix = config.CommandPrefix
bot.CommandSuccessReaction = config.CommandSuccessReaction
bot.CommandFailReaction = config.CommandFailReaction
musicPlayer := musicplayer.New(bot)
registerCommand := func(command botPkg.CommandEntry) {
bot.Commands = append(bot.Commands, command)
}
registerCommand(botPkg.CommandEntry{Command: bot.HelpCommand, Aliases: config.HelpCommandAliases,
Description: "выводит список доступных команд"})
registerCommand(botPkg.CommandEntry{Command: musicPlayer.PlayCommand, Aliases: config.PlayCommandAliases,
Description: "ставит трек в очередь",
ArgsDescription: "<название или ссылка>"})
registerCommand(botPkg.CommandEntry{Command: musicPlayer.ShowCommand, Aliases: config.ShowCommandAliases,
Description: "показывает очередь треков"})
registerCommand(botPkg.CommandEntry{Command: musicPlayer.ClearCommand, Aliases: config.ClearCommandAliases,
Description: "очищает очередь треков"})
registerCommand(botPkg.CommandEntry{Command: musicPlayer.RemoveCommand, Aliases: config.RemoveCommandAliases,
Description: "удаляет трек из очереди",
ArgsDescription: "<номер трека>"})
registerCommand(botPkg.CommandEntry{Command: musicPlayer.SkipCommand, Aliases: config.SkipCommandAliases,
Description: "пропускает текущий трек"})
registerCommand(botPkg.CommandEntry{Command: musicPlayer.PauseCommand, Aliases: config.PauseCommandAliases,
Description: "ставит трек на паузу"})
registerCommand(botPkg.CommandEntry{Command: musicPlayer.ResumeCommand, Aliases: config.ResumeCommandAliases,
Description: "снимает трек с паузы"})
if err = bot.Run(); err != nil {
log.Fatalln(err)
}
}