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

86 lines
1.8 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 client struct {
Commands []Command
Components []Component
Tags []discordgo.ForumTag
controller controller.WorkflowController
conf *domain.DiscordConfig
tgConf *domain.TelegramConfig
}
// Подключение роутов к Discord боту
func InitRouter(wc controller.WorkflowController, conf *domain.DiscordConfig, tgConf *domain.TelegramConfig) *client {
var r client
r.controller = wc
r.conf = conf
r.Commands = append(r.Commands,
r.CreateRepoHandler(3),
r.CreateFolderHandler(3),
r.Ping(),
r.CreateTicketHandler(3),
r.InitProjectFromChannel(3),
r.GetInfo(),
)
r.Components = append(r.Components,
r.HandleTaskButtons(),
)
r.Tags = append(
r.Tags,
discordgo.ForumTag{
Name: "В работе",
Moderated: true,
EmojiName: "👩‍🍳",
},
discordgo.ForumTag{
Name: "Готово",
Moderated: true,
EmojiName: "✅",
})
r.tgConf = tgConf
return &r
}
//
// Подключение роутов к Discord боту
type Command struct {
Command discordgo.ApplicationCommand
Handler func(s *discordgo.Session, i *discordgo.InteractionCreate)
}
type Component struct {
Component discordgo.MessageComponent
Handler func(s *discordgo.Session, i *discordgo.InteractionCreate)
}
func (h *client) 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
}
}