ticket-pimp/client/discord/handler/handler.go

80 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package handler
import (
"fmt"
"ticket-pimp/internal/controller"
"ticket-pimp/internal/domain"
"github.com/bwmarrin/discordgo"
)
type router struct {
Commands []CommandRoute
Components []ComponentRoute
Tags []discordgo.ForumTag
controller controller.WorkflowController
conf *domain.DiscordConfig
}
// Подключение роутов к Discord боту
func InitRouter(wc controller.WorkflowController, conf *domain.DiscordConfig) *router {
var r router
r.Commands = append(r.Commands,
// r.CreateRepoHandler(3),
// r.CreateFolderHandler(3),
r.Ping(),
// r.CreateTicketHandler(3),
// r.InitProjectFromChannel(3),
// r.GetInfo(),
r.CreateExternalTask(),
)
r.Components = append(r.Components,
r.StartTask(),
r.CloseTask(),
)
r.controller = wc
r.conf = conf
r.Tags = append(
r.Tags,
discordgo.ForumTag{
Name: "В работе",
Moderated: true,
EmojiName: "👩‍🍳",
},
discordgo.ForumTag{
Name: "Готово",
Moderated: true,
EmojiName: "✅",
})
return &r
}
type CommandRoute struct {
Command discordgo.ApplicationCommand
Handler func(s *discordgo.Session, i *discordgo.InteractionCreate)
}
type ComponentRoute struct {
Component discordgo.MessageComponent
Handler func(s *discordgo.Session, i *discordgo.InteractionCreate)
}
func (h *router) defaultFollowUp(answer string, s *discordgo.Session, i *discordgo.InteractionCreate) {
// Sending result:
_, err := s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
Content: answer,
})
if err != nil {
s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
Content: fmt.Sprintf("Something went wrong: %v", err),
})
return
}
}