✨ Created simple line tool
This commit is contained in:
parent
4844174303
commit
7a97fa48ba
|
@ -0,0 +1,77 @@
|
|||
package discord
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
func NewHandler(logger *log.Logger) *Handler {
|
||||
return &Handler{
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) ServeReady(s *discordgo.Session, r *discordgo.Ready) {
|
||||
for i := range r.Guilds {
|
||||
if _, err := s.ApplicationCommandCreate(s.State.User.ID, r.Guilds[i].ID, &discordgo.ApplicationCommand{
|
||||
Name: "line",
|
||||
NameLocalizations: &map[discordgo.Locale]string{
|
||||
discordgo.Russian: "линия",
|
||||
},
|
||||
Description: "request a complete content ban",
|
||||
DescriptionLocalizations: &map[discordgo.Locale]string{
|
||||
discordgo.Russian: "запросить полный запрет контента",
|
||||
},
|
||||
Options: []*discordgo.ApplicationCommandOption{{
|
||||
Type: discordgo.ApplicationCommandOptionString,
|
||||
Name: "description",
|
||||
NameLocalizations: map[discordgo.Locale]string{
|
||||
discordgo.Russian: "описание",
|
||||
},
|
||||
Description: "description of the content to be banned",
|
||||
DescriptionLocalizations: map[discordgo.Locale]string{
|
||||
discordgo.Russian: "описание контента который требуется запретить",
|
||||
},
|
||||
Required: true,
|
||||
}},
|
||||
}); err != nil {
|
||||
h.logger.Println("cannot register command:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) ServeInteraction(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
data := i.ApplicationCommandData()
|
||||
|
||||
if data.Name != "line" {
|
||||
return
|
||||
}
|
||||
|
||||
if len(data.Options) == 0 {
|
||||
if err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "You must describe your line.",
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
}); err != nil {
|
||||
h.logger.Println("cannot make interaction response:", err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "(Line: " + data.Options[0].StringValue() + ")",
|
||||
},
|
||||
}); err != nil {
|
||||
h.logger.Println("cannot make interaction response:", err)
|
||||
}
|
||||
}
|
4
main.go
4
main.go
|
@ -16,6 +16,7 @@ import (
|
|||
searchdiscorddelivery "source.toby3d.me/toby3d/alice/internal/search/delivery/discord"
|
||||
searchfsrepo "source.toby3d.me/toby3d/alice/internal/search/repository/memory"
|
||||
searchusecase "source.toby3d.me/toby3d/alice/internal/search/usecase"
|
||||
linediscorddelivery "source.toby3d.me/toby3d/alice/internal/line/delivery/discord"
|
||||
voicemaildiscorddelivery "source.toby3d.me/toby3d/alice/internal/voicemail/delivery/discord"
|
||||
voicemailfsrepo "source.toby3d.me/toby3d/alice/internal/voicemail/repository/fs"
|
||||
voicemailusecase "source.toby3d.me/toby3d/alice/internal/voicemail/usecase"
|
||||
|
@ -51,6 +52,7 @@ func main() {
|
|||
voicemailDiscordHandler := voicemaildiscorddelivery.NewHandler(voicemailsService, assets, logger, *config)
|
||||
xDiscordHandler := xdiscorddelivery.NewHandler(assets, logger)
|
||||
characterDiscordDelivery := characterdiscorddelivery.NewHandler(logger)
|
||||
lineDiscordHandler := linediscorddelivery.NewHandler(logger)
|
||||
|
||||
searches := searchfsrepo.NewMemorySearchRepository()
|
||||
searchService := searchusecase.NewSearchUseCase(searches, rand.NewSource(time.Now().UnixNano()))
|
||||
|
@ -58,11 +60,13 @@ func main() {
|
|||
|
||||
for _, h := range []any{
|
||||
xDiscordHandler.ServeReady,
|
||||
lineDiscordHandler.ServeReady,
|
||||
searchDiscordDelivery.ServeReady,
|
||||
voicemailDiscordHandler.ServeReady,
|
||||
characterDiscordDelivery.ServeReady,
|
||||
voicemailDiscordHandler.ServeMessage,
|
||||
xDiscordHandler.ServeInteraction,
|
||||
lineDiscordHandler.ServeInteraction,
|
||||
voicemailDiscordHandler.ServeInteraction,
|
||||
characterDiscordDelivery.ServeInteraction,
|
||||
searchDiscordDelivery.ServeInteraction,
|
||||
|
|
Loading…
Reference in New Issue