Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
SlashCommands = map[string]Command{}
)
Functions ¶
Types ¶
type Command ¶
type Command struct { Data *discordgo.ApplicationCommand Callback func(s *discordgo.Session, i *discordgo.InteractionCreate, bot *config.Bot) }
var InviteCommand Command = Command{ Data: &discordgo.ApplicationCommand{ Name: "invite", Description: "Invite me to your server", DMPermission: &dmPermissionTrue, }, Callback: func(s *discordgo.Session, i *discordgo.InteractionCreate, bot *config.Bot) { responseEmbed := &discordgo.MessageEmbed{ Author: &discordgo.MessageEmbedAuthor{ Name: "Tomorrowland Bot Invite", IconURL: s.State.User.AvatarURL(""), }, Description: "Bring the party to your server!", Color: config.MainColorHex, Timestamp: time.Now().Format(time.RFC3339), } actionRow := discordgo.ActionsRow{ Components: []discordgo.MessageComponent{ discordgo.Button{ Label: "Invite Tomorrowland 24/7", URL: "https://discord.com/api/oauth2/authorize?client_id=1000497170434236457&permissions=274914618624&scope=bot%20applications.commands", Style: discordgo.LinkButton, }, }, } s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Embeds: []*discordgo.MessageEmbed{ responseEmbed, }, Components: []discordgo.MessageComponent{ actionRow, }, }, }) }, }
var LineupCommand Command = Command{ Data: &discordgo.ApplicationCommand{ Name: "lineup", Description: "View the Tomorrowland lineup for a specific day", DMPermission: &dmPermissionTrue, Options: []*discordgo.ApplicationCommandOption{ { Name: "timetable", Description: "Get the timetable for a specific day", Type: discordgo.ApplicationCommandOptionSubCommand, Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionString, Name: "day", Description: "Select a day", Choices: tmrlweb.GetDayChoices(), Required: true, }, }, }, { Name: "stage", Description: "See the artists playing on a specific stage and day", Type: discordgo.ApplicationCommandOptionSubCommand, Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionString, Name: "stage-name", Description: "Select a stage", Choices: tmrlweb.GetStageChoices(), Required: true, }, { Type: discordgo.ApplicationCommandOptionString, Name: "day", Description: "Select a day", Choices: tmrlweb.GetDayChoices(), Required: true, }, }, }, }, }, Callback: func(s *discordgo.Session, i *discordgo.InteractionCreate, bot *config.Bot) { switch i.ApplicationCommandData().Options[0].Name { case "timetable": getTimetable(s, i, bot) case "stage": getStage(s, i, bot) } }, }
var NowPlayingCommand Command = Command{ Data: &discordgo.ApplicationCommand{ Name: "nowplaying", Description: "Shows the artist currently playing in a stage", DMPermission: &dmPermissionTrue, Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionString, Name: "stage", Description: "Select a stage", Choices: tmrlweb.GetStageChoices(), Required: false, }, }, }, Callback: func(s *discordgo.Session, i *discordgo.InteractionCreate, bot *config.Bot) { loc, _ := time.LoadLocation("Europe/Brussels") nowBelgium := time.Now().In(loc) responseEmbed := &discordgo.MessageEmbed{ Title: "Artist(s) currently playing", Author: &discordgo.MessageEmbedAuthor{ Name: "Tomorrowland Live", IconURL: s.State.User.AvatarURL(""), }, Color: config.MainColorHex, Thumbnail: &discordgo.MessageEmbedThumbnail{ URL: config.OneWorldRadioImg, }, } fields := []*discordgo.MessageEmbedField{} if len(i.ApplicationCommandData().Options) > 0 { selectedStage := i.ApplicationCommandData().Options[0] responseEmbed.Description = selectedStage.StringValue() performances := tmrlweb.GetPerformances(nowBelgium.Format("2006-01-02"), selectedStage.StringValue()) for _, performance := range performances { if tmrlweb.CurrentlyPLaying(performance) { fields = append(fields, &discordgo.MessageEmbedField{ Name: performance.ArtistName, Value: fmt.Sprintf("%v - %v", performance.StartTime.Format("15:04"), performance.EndTime.Format("15:04")), Inline: false, }) } } } else { stages := tmrlweb.GetStages(nowBelgium.Format("2006-01-02")) for _, stage := range stages { for _, performance := range stage { if tmrlweb.CurrentlyPLaying(performance) { fields = append(fields, &discordgo.MessageEmbedField{ Name: fmt.Sprintf("%v | %v", performance.ArtistName, performance.Stage.Name), Value: fmt.Sprintf("%v to %v", performance.StartTime.Format("15:04"), performance.EndTime.Format("15:04")), Inline: false, }) } } } } if len(fields) > 25 { fields = fields[:25] } if len(fields) == 0 { responseEmbed.Description = "There are no artists playing at the moment. Check the line-up" s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Embeds: []*discordgo.MessageEmbed{ responseEmbed, }, }, }) return } responseEmbed.Fields = fields s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Embeds: []*discordgo.MessageEmbed{ responseEmbed, }, }, }) }, }
var PlayCommand Command = Command{ Data: &discordgo.ApplicationCommand{ Name: "play", Description: "Play the tomorrowland livestream", DMPermission: &dmPermissionFalse, }, Callback: func(s *discordgo.Session, i *discordgo.InteractionCreate, bot *config.Bot) { if i.Interaction.Member.Permissions&discordgo.PermissionAdministrator != discordgo.PermissionAdministrator { bot.ErrorInteractionResponse(s, i, config.Content{ Message: "You do not have enough permissions to use this command", }, false, true) return } _, err := s.State.VoiceState(i.Interaction.GuildID, i.Interaction.Member.User.ID) if err != nil { bot.ErrorInteractionResponse(s, i, config.Content{ Message: "You need to be inside a voice channel to execute this command", }, false, true) return } _, ok := s.VoiceConnections[i.Interaction.GuildID] if ok { bot.ErrorInteractionResponse(s, i, config.Content{ Message: "I'm already inside a voice channel, come listen!", Description: "If you manually disconnected me, wait a few seconds before trying again", }, false, true) return } if len(*bot.LiveStreams) == 0 { bot.ErrorMessageResponse(s, i, config.Content{ Message: "I'm sorry, there are no live streams at the moment. Try again later", }) return } selectOptions := make([]discordgo.SelectMenuOption, len(*bot.LiveStreams)) for i, v := range *bot.LiveStreams { selectOptions[i] = discordgo.SelectMenuOption{ Label: v.Title, Description: v.ChannelTitle, Value: strconv.Itoa(i), Emoji: &discordgo.ComponentEmoji{ Name: "🔴", }, } } responseEmbed := &discordgo.MessageEmbed{ Author: &discordgo.MessageEmbedAuthor{ Name: "Tomorrowland Live", IconURL: s.State.User.AvatarURL(""), }, Title: "Select a live stream", Thumbnail: &discordgo.MessageEmbedThumbnail{ URL: config.OneWorldRadioImg, }, Color: config.MainColorHex, } actionRow := discordgo.ActionsRow{ Components: []discordgo.MessageComponent{ discordgo.SelectMenu{ CustomID: "liveSelect", Placeholder: "Choose the livestream you wish to play!", Options: selectOptions, }, }, } s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Embeds: []*discordgo.MessageEmbed{ responseEmbed, }, Components: []discordgo.MessageComponent{ actionRow, }, Flags: discordgo.MessageFlagsEphemeral, }, }) }, }
var StopCommand Command = Command{ Data: &discordgo.ApplicationCommand{ Name: "stop", Description: "Stops the current live stream and disconnects from the voice channel", DMPermission: &dmPermissionFalse, }, Callback: func(s *discordgo.Session, i *discordgo.InteractionCreate, bot *config.Bot) { if i.Interaction.Member.Permissions&discordgo.PermissionAdministrator != discordgo.PermissionAdministrator { bot.ErrorInteractionResponse(s, i, config.Content{ Message: "You do not have enough permissions to use this command", }, false, true) return } _, err := s.State.VoiceState(i.Interaction.GuildID, i.Interaction.Member.User.ID) if err != nil { bot.ErrorInteractionResponse(s, i, config.Content{ Message: "You need to be inside a voice channel to execute this command", }, false, true) return } if _, ok := s.VoiceConnections[i.Interaction.GuildID]; !ok { bot.ErrorInteractionResponse(s, i, config.Content{ Message: "I'm not inside any voice channel currently", }, false, true) return } err = player.Stop(s, i.Interaction.GuildID) if err != nil { bot.Logger.Error(err.Error(), "command", "stop") bot.ErrorInteractionResponse(s, i, config.Content{ Message: "I'm sorry, something went wrong. Try again", Description: "If the bot was disconnected from the voice channel manually, wait a few seconds before trying again", }, false, true) return } responseEmbed := &discordgo.MessageEmbed{ Author: &discordgo.MessageEmbedAuthor{ Name: "Tomorrowland Live", IconURL: s.State.User.AvatarURL(""), }, Title: "Thanks for tuning in. See you next time!", Timestamp: time.Now().Format(time.RFC3339), Color: config.MainColorHex, } s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Embeds: []*discordgo.MessageEmbed{ responseEmbed, }, }, }) }, }
Click to show internal directories.
Click to hide internal directories.