Skip to content

Commit

Permalink
feat(FAQ): added FAQ command base
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesuaheli committed Jan 4, 2025
1 parent a382865 commit 328c7a0
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 2 deletions.
5 changes: 5 additions & 0 deletions data/lang/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions data/lang/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions event/command/commandBase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})

Expand Down
51 changes: 51 additions & 0 deletions modules/faq/chatCommand.go
Original file line number Diff line number Diff line change
@@ -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
}
43 changes: 43 additions & 0 deletions modules/faq/component.go
Original file line number Diff line number Diff line change
@@ -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"
}
15 changes: 15 additions & 0 deletions modules/faq/faqBase.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 328c7a0

Please sign in to comment.