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