parent
3f365a715f
commit
4e2ec953f8
|
|
@ -30,7 +30,7 @@ func Run(conf domain.Config, opts DiscordOptions) error {
|
|||
|
||||
session := initBotWith(token)
|
||||
|
||||
router := handler.InitRouter(*opts.Controller)
|
||||
router := handler.InitRouter(*opts.Controller, &conf.Discord)
|
||||
|
||||
commandHandlers := map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){}
|
||||
for _, handler := range router.Routes {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"ticket-pimp/internal/controller"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
|
|
@ -36,7 +35,7 @@ func (h *router) CreateFolderHandler(nameMinLenght int) route {
|
|||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
Content: "Cooking your query..",
|
||||
Content: "👩🍳 Cooking your query..",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -62,7 +61,7 @@ func (h *router) CreateFolderHandler(nameMinLenght int) route {
|
|||
log.Printf("error while identifying channel: %v", err)
|
||||
} else {
|
||||
|
||||
if dchan.ParentID == strconv.Itoa(1150719794853716028) {
|
||||
if dchan.ParentID == h.conf.ProjectsChannelID {
|
||||
req.ChannelID = dchan.ID
|
||||
if insertedValueNotNil {
|
||||
req.InsertedName = name.StringValue()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"ticket-pimp/internal/controller"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
|
|
@ -54,7 +53,7 @@ func (h *router) CreateRepoHandler(repoNameMinLength int) route {
|
|||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
Content: "Cooking your query..",
|
||||
Content: "👩🍳 Cooking your query..",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +87,7 @@ func (h *router) CreateRepoHandler(repoNameMinLength int) route {
|
|||
log.Printf("error while identifying channel: %v", err)
|
||||
} else {
|
||||
|
||||
if dchan.ParentID == strconv.Itoa(1150719794853716028) {
|
||||
if dchan.ParentID == h.conf.ProjectsChannelID {
|
||||
req.ChannelID = dchan.ID
|
||||
if insertedValueNotNil {
|
||||
req.InsertedName = name.StringValue()
|
||||
|
|
|
|||
|
|
@ -25,6 +25,18 @@ func (h *router) CreateTicketHandler(repoNameMinLength int) route {
|
|||
},
|
||||
},
|
||||
Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
|
||||
// Моментальный ответ для избежания столкновения с протуханием токена
|
||||
initialResponse := discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
Content: "👩🍳 Cooking your query..",
|
||||
},
|
||||
}
|
||||
|
||||
s.InteractionRespond(i.Interaction, &initialResponse)
|
||||
|
||||
var result string
|
||||
// Access options in the order provided by the user.
|
||||
options := i.ApplicationCommandData().Options
|
||||
|
|
@ -45,6 +57,10 @@ func (h *router) CreateTicketHandler(repoNameMinLength int) route {
|
|||
})
|
||||
if err != nil {
|
||||
result = fmt.Sprintf("unable to create project: %v\n", err)
|
||||
_, err := s.ChannelDelete(dchan.ID)
|
||||
if err != nil {
|
||||
result += fmt.Sprintf("\nunable to clean channel: %v\n", err)
|
||||
}
|
||||
} else {
|
||||
edit := discordgo.ChannelEdit{
|
||||
Name: p.ShortName,
|
||||
|
|
@ -66,13 +82,17 @@ func (h *router) CreateTicketHandler(repoNameMinLength int) route {
|
|||
}
|
||||
}
|
||||
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
// Ignore type for now, they will be discussed in "responses"
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: result,
|
||||
},
|
||||
// Sending result:
|
||||
_, err := s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
|
||||
Content: result,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
|
||||
Content: fmt.Sprintf("Something went wrong: %v", err),
|
||||
})
|
||||
return
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package handler
|
|||
|
||||
import (
|
||||
"ticket-pimp/internal/controller"
|
||||
"ticket-pimp/internal/domain"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
|
@ -9,10 +10,11 @@ import (
|
|||
type router struct {
|
||||
Routes []route
|
||||
controller controller.WorkflowController
|
||||
conf *domain.DiscordConfig
|
||||
}
|
||||
|
||||
// Подключение роутов к Discord боту
|
||||
func InitRouter(wc controller.WorkflowController) *router {
|
||||
func InitRouter(wc controller.WorkflowController, conf *domain.DiscordConfig) *router {
|
||||
|
||||
var r router
|
||||
r.Routes = append(
|
||||
|
|
@ -23,6 +25,7 @@ func InitRouter(wc controller.WorkflowController) *router {
|
|||
r.CreateTicketHandler(3),
|
||||
)
|
||||
r.controller = wc
|
||||
r.conf = conf
|
||||
|
||||
return &r
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue