diff --git a/data/lang/de.yaml b/data/lang/de.yaml index 7774ac3..3093515 100644 --- a/data/lang/de.yaml +++ b/data/lang/de.yaml @@ -103,6 +103,11 @@ discord.command: msg.announce.with_age: "%s (wird %s)" msg.next: Nächster Geburtstag + faq: + base: faq + base.description: Häufig gestellte Fragen + display: FAQ + info: base: info base.description: Zeigt ein paar Infos über den Bot diff --git a/data/lang/en.yaml b/data/lang/en.yaml index ab84f87..33311ae 100644 --- a/data/lang/en.yaml +++ b/data/lang/en.yaml @@ -103,6 +103,11 @@ discord.command: msg.announce.with_age: "%s (turns %s)" msg.next: Next birthday + faq: + base: faq + base.description: Frequently Asked Questions + display: FAQ + info: base: info base.description: Displays some infos about the bot diff --git a/event/command/commandBase.go b/event/command/commandBase.go index 351e77a..837500a 100644 --- a/event/command/commandBase.go +++ b/event/command/commandBase.go @@ -22,6 +22,7 @@ import ( "github.com/cake4everyone/cake4everybot/logger" "github.com/cake4everyone/cake4everybot/modules/adventcalendar" "github.com/cake4everyone/cake4everybot/modules/birthday" + "github.com/cake4everyone/cake4everybot/modules/faq" "github.com/cake4everyone/cake4everybot/modules/info" "github.com/cake4everyone/cake4everybot/modules/random" "github.com/cake4everyone/cake4everybot/modules/secretsanta" @@ -70,13 +71,14 @@ func Register(s *discordgo.Session, guildID string) error { var commandsList []Command // chat (slash) commands + commandsList = append(commandsList, &adventcalendar.Chat{}) commandsList = append(commandsList, &birthday.Chat{}) + commandsList = append(commandsList, &faq.Chat{}) commandsList = append(commandsList, &info.Chat{}) - commandsList = append(commandsList, &adventcalendar.Chat{}) commandsList = append(commandsList, &random.Chat{}) commandsList = append(commandsList, &secretsanta.Chat{}) - commandsList = append(commandsList, &secretsanta.MsgCmd{}) // messsage commands + commandsList = append(commandsList, &secretsanta.MsgCmd{}) // user commands commandsList = append(commandsList, &birthday.UserShow{}) diff --git a/modules/faq/chatCommand.go b/modules/faq/chatCommand.go new file mode 100644 index 0000000..731a7a9 --- /dev/null +++ b/modules/faq/chatCommand.go @@ -0,0 +1,51 @@ +package faq + +import ( + "github.com/bwmarrin/discordgo" + "github.com/cake4everyone/cake4everybot/data/lang" + "github.com/cake4everyone/cake4everybot/util" +) + +// The Chat (slash) command of the faq package. +type Chat struct { + faqBase + ID string +} + +const ( + // Prefix for translation key, i.e.: + // key := tp+"base" // => faq + tp = "discord.command.faq." +) + +// AppCmd (ApplicationCommand) returns the definition of the chat command +func (cmd Chat) AppCmd() *discordgo.ApplicationCommand { + return &discordgo.ApplicationCommand{ + Name: lang.GetDefault(tp + "base"), + NameLocalizations: util.TranslateLocalization(tp + "base"), + Description: lang.GetDefault(tp + "base.description"), + DescriptionLocalizations: util.TranslateLocalization(tp + "base.description"), + } +} + +// Handle handles the functionality of a command +func (cmd Chat) Handle(s *discordgo.Session, i *discordgo.InteractionCreate) { + cmd.InteractionUtil = util.InteractionUtil{Session: s, Interaction: i} + cmd.member = i.Member + cmd.user = i.User + if i.Member != nil { + cmd.user = i.Member.User + } else if i.User != nil { + cmd.member = &discordgo.Member{User: i.User} + } +} + +// SetID sets the registered command ID for internal uses after uploading to discord +func (cmd *Chat) SetID(id string) { + cmd.ID = id +} + +// GetID gets the registered command ID +func (cmd Chat) GetID() string { + return cmd.ID +} diff --git a/modules/faq/component.go b/modules/faq/component.go new file mode 100644 index 0000000..69eb69c --- /dev/null +++ b/modules/faq/component.go @@ -0,0 +1,43 @@ +package faq + +import ( + "strings" + + "github.com/bwmarrin/discordgo" + "github.com/cake4everyone/cake4everybot/util" +) + +// The Component of the faq package. +type Component struct { + faqBase + data discordgo.MessageComponentInteractionData +} + +// Handle handles the functionality of a component. +func (c Component) Handle(s *discordgo.Session, i *discordgo.InteractionCreate) { + c.InteractionUtil = util.InteractionUtil{Session: s, Interaction: i} + c.member = i.Member + c.user = i.User + if i.Member != nil { + c.user = i.Member.User + } else if i.User != nil { + c.member = &discordgo.Member{User: i.User} + } + //lint:ignore SA4005 currently not used but will be when implementing the component + c.data = i.MessageComponentData() + + ids := strings.Split(c.data.CustomID, ".") + // pop the first level identifier + util.ShiftL(ids) + + switch util.ShiftL(ids) { + default: + log.Printf("Unknown component interaction ID: %s", c.data.CustomID) + } + +} + +// ID returns the custom ID of the modal to identify the module +func (c Component) ID() string { + return "faq" +} diff --git a/modules/faq/faqBase.go b/modules/faq/faqBase.go new file mode 100644 index 0000000..6072f6c --- /dev/null +++ b/modules/faq/faqBase.go @@ -0,0 +1,15 @@ +package faq + +import ( + "github.com/bwmarrin/discordgo" + "github.com/cake4everyone/cake4everybot/logger" + "github.com/cake4everyone/cake4everybot/util" +) + +var log = logger.New("FAQ") + +type faqBase struct { + util.InteractionUtil + member *discordgo.Member + user *discordgo.User +}