-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from cake4everyone/feat/faq
Adding FAQ
- Loading branch information
Showing
13 changed files
with
497 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Oops, something went wrong.