Skip to content

Commit

Permalink
Merge pull request #19 from cake4everyone/feat/faq
Browse files Browse the repository at this point in the history
Adding FAQ
  • Loading branch information
Kesuaheli authored Jan 6, 2025
2 parents 1a407d4 + 717e3b3 commit a785b82
Show file tree
Hide file tree
Showing 13 changed files with 497 additions and 12 deletions.
17 changes: 13 additions & 4 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,22 @@ event:
name: 🔁
#id:
#animated: true
generic.back:
name: ↩️
#id:
#animated: true
generic.delete:
name: 🗑️
#id:
#animated: true

adventcalendar:
# Emoji for entering the advent calendar giveaway
enter: vote.check

faq:
all_questions: generic.back

random.coin:
heads:
name: 👤
Expand Down Expand Up @@ -129,10 +141,7 @@ event:
name: 🏠
#id:
#animated: true
invite.delete:
name: 🗑️
#id:
#animated: true
invite.delete: generic.delete
invite.nudge_match:
name: 👉
#id:
Expand Down
21 changes: 21 additions & 0 deletions data/lang/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ discord.command:
msg.self_hidden: Warum ist das unsichtbar?
msg.self_hidden.desc: Da du deinen Geburtstag als nicht sichtbar eingetragen hast, kannst diese Nachricht nur du sehen. Du kannst diese Nachricht nun schließen.
msg.page: Seite %d/%d
msg.button.delete: Schließen
msg.error.not_author: Das ist die Nachricht von %s. Du kannst das nicht verwenden!

birthday:
base: geburtstag
Expand Down Expand Up @@ -103,6 +105,25 @@ 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

option.question: frage
option.question.description: Die Frage, nach der gesucht werden soll

msg.button.all_questions: Alle Fragen
msg.no_questions: Es hier noch keine häufig gestellten Fragen.
#TODO: Link slash command
msg.question_not_found: |-
Die Frage, nach der du gesucht hast, konnte nicht gefunden werden.
> %s
Versuche es erneut oder schau dir alle Fragen an indem du keine Frage in der suche angibst.
msg.error: |-
Es gab einen Fehler beim Laden aller Fragen :(
Bitte rufen sie ihren lokalen Administrator, falls der Fehler weiterhin auftreten sollte.
info:
base: info
base.description: Zeigt ein paar Infos über den Bot
Expand Down
21 changes: 21 additions & 0 deletions data/lang/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ discord.command:
msg.self_hidden: Why is this invisible?
msg.self_hidden.desc: Since you've set your birthday to not be visible, this message is also only visible to you. You can close this message now.
msg.page: Page %d/%d
msg.button.delete: Close
msg.error.not_author: This is the message of %s. You can't use this here!

birthday:
base: birthday
Expand Down Expand Up @@ -103,6 +105,25 @@ discord.command:
msg.announce.with_age: "%s (turns %s)"
msg.next: Next birthday

faq:
base: faq
base.description: Frequently Asked Questions
display: FAQ

option.question: question
option.question.description: The question you want to ask

msg.button.all_questions: All questions
msg.no_questions: There are no frequently asked questions yet
#TODO: Link slash command
msg.question_not_found: |-
The question you searched for was not found.
> %s
Check again or list all questions by not searching anything.
msg.error: |-
There was an error while loading all questions :(
Please contact your local administrator if this problem persists.
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
3 changes: 3 additions & 0 deletions event/component/componentBase.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/bwmarrin/discordgo"
"github.com/cake4everyone/cake4everybot/logger"
"github.com/cake4everyone/cake4everybot/modules/adventcalendar"
"github.com/cake4everyone/cake4everybot/modules/faq"
"github.com/cake4everyone/cake4everybot/modules/random"
"github.com/cake4everyone/cake4everybot/modules/secretsanta"
)
Expand Down Expand Up @@ -34,6 +35,8 @@ func Register() {
var componentList []Component

componentList = append(componentList, adventcalendar.Component{})
componentList = append(componentList, faq.Component{})
componentList = append(componentList, GenericComponents{})
componentList = append(componentList, random.Component{})
componentList = append(componentList, secretsanta.Component{})

Expand Down
64 changes: 64 additions & 0 deletions event/component/handleGenericComponents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package component

import (
"strings"

"github.com/bwmarrin/discordgo"
"github.com/cake4everyone/cake4everybot/util"
)

// GenericComponents is the Component handler for generic components
type GenericComponents struct {
util.InteractionUtil
member *discordgo.Member
user *discordgo.User
originalAuthor *discordgo.User
data discordgo.MessageComponentInteractionData
}

// Handle handles the functionality of a component interaction
func (gc GenericComponents) Handle(s *discordgo.Session, i *discordgo.InteractionCreate) {
gc.InteractionUtil = util.InteractionUtil{Session: s, Interaction: i}
gc.member = i.Member
gc.user = i.User
if i.Member != nil {
gc.user = i.Member.User
} else if i.User != nil {
gc.member = &discordgo.Member{User: i.User}
}
gc.data = i.MessageComponentData()

if gc.Interaction.Message.Type == discordgo.MessageTypeChatInputCommand {
gc.originalAuthor = gc.Interaction.Message.Interaction.User
} else {
gc.originalAuthor = gc.Interaction.Message.Author
}

ids := strings.Split(gc.data.CustomID, ".")
// pop the first level identifier
util.ShiftL(ids)

switch util.ShiftL(ids) {
case "delete":
if gc.RequireOriginalAuthor() {
gc.handleDelete()
}
return
default:
log.Printf("Unknown component interaction ID: %s", gc.data.CustomID)
gc.ReplyError()
}
}

// ID returns the component ID to identify the module
func (gc GenericComponents) ID() string {
return "generic"
}

func (gc GenericComponents) handleDelete() {
err := gc.Session.ChannelMessageDelete(gc.Interaction.ChannelID, gc.Interaction.Message.ID)
if err != nil {
log.Printf("ERROR: could not delete message %s/%s: %+v", gc.Interaction.ChannelID, gc.Interaction.Message.ID, err)
gc.ReplyError()
}
}
78 changes: 78 additions & 0 deletions modules/faq/chatCommand.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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"),
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: lang.GetDefault(tp + "option.question"),
Description: lang.GetDefault(tp + "option.question.description"),
Required: false,
Autocomplete: true,
},
},
}
}

// 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}
}

data := i.ApplicationCommandData()
var question string
for _, option := range data.Options {
switch option.Name {
case lang.GetDefault(tp + "option.question"):
question = option.StringValue()
}
}

if i.Type == discordgo.InteractionApplicationCommandAutocomplete {
cmd.handleAutocomplete(question)
} else if question == "" {
cmd.ReplyComplex(cmd.getAllFAQsMessage())
return
} else {
cmd.ReplyComplex(cmd.getFAQMessage(question))
}
}

// 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
}
53 changes: 53 additions & 0 deletions modules/faq/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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}
}
c.data = i.MessageComponentData()

ids := strings.Split(c.data.CustomID, ".")
// pop the first level identifier
util.ShiftL(ids)

switch util.ShiftL(ids) {
case "show_question":
if c.RequireOriginalAuthor() {
question := strings.Join(ids[:len(ids)-2], ".")
c.ReplyComplexUpdate(c.getFAQMessage(question))
}
return
case "all_questions":
if c.RequireOriginalAuthor() {
c.ReplyComplexUpdate(c.getAllFAQsMessage())
}
return
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"
}
Loading

0 comments on commit a785b82

Please sign in to comment.