52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
|
package discord
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
|
||
|
"gitea.dwysokinski.me/twhelp/dcbot/internal/discord/internal/discordi18n"
|
||
|
"github.com/bwmarrin/discordgo"
|
||
|
)
|
||
|
|
||
|
type choiceService struct {
|
||
|
localizer *discordi18n.Localizer
|
||
|
choiceSvc ChoiceService
|
||
|
}
|
||
|
|
||
|
func (s *choiceService) versions(ctx context.Context) ([]*discordgo.ApplicationCommandOptionChoice, error) {
|
||
|
choices, err := s.choiceSvc.Versions(ctx)
|
||
|
if err != nil {
|
||
|
return nil, fmt.Errorf("ChoiceService.Versions: %w", err)
|
||
|
}
|
||
|
|
||
|
dcChoices := make([]*discordgo.ApplicationCommandOptionChoice, 0, len(choices))
|
||
|
for _, v := range choices {
|
||
|
dcChoices = append(dcChoices, &discordgo.ApplicationCommandOptionChoice{
|
||
|
Name: v.Name,
|
||
|
Value: v.Value,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
return dcChoices, nil
|
||
|
}
|
||
|
|
||
|
func (s *choiceService) languages() ([]*discordgo.ApplicationCommandOptionChoice, error) {
|
||
|
tags := s.localizer.LanguageTags()
|
||
|
|
||
|
choices := make([]*discordgo.ApplicationCommandOptionChoice, 0, len(tags))
|
||
|
for _, tag := range tags {
|
||
|
lang, langLocalizations, err := s.localizer.LocalizeDiscord(buildLangMessageID(tag.String()))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
choices = append(choices, &discordgo.ApplicationCommandOptionChoice{
|
||
|
Name: lang,
|
||
|
NameLocalizations: langLocalizations,
|
||
|
Value: tag.String(),
|
||
|
})
|
||
|
}
|
||
|
|
||
|
return choices, nil
|
||
|
}
|