- move initial response to middleware;

- projects parent channel as conf var;
- finish moving Interfaces to the middleware;
This commit is contained in:
naudachu 2023-11-22 16:07:11 +05:00
parent 98f401c6f4
commit e668e0b50d
10 changed files with 24 additions and 85 deletions

View File

@ -28,6 +28,17 @@ type DiscordOptions struct {
}
func checkPrivateMessaging(s *discordgo.Session, i *discordgo.InteractionCreate) error {
// Моментальный ответ для избежания столкновения с протуханием токена
initialResponse := discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral,
Content: "👩‍🍳 Cooking your query..",
},
}
s.InteractionRespond(i.Interaction, &initialResponse)
dchan, err := s.Channel(i.ChannelID)
if err != nil {
return err

View File

@ -117,12 +117,6 @@ func (c *client) HandleTaskButtons() Component {
func (c *client) handleTaskButton(s *discordgo.Session, i *discordgo.InteractionCreate) {
// Send an empty interaction response; ----------------------------------------------------------------
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseUpdateMessage,
Data: &discordgo.InteractionResponseData{},
})
// Get assignee value; ---------------------------------------------------------------------------------
user := i.Member.User.Mention()

View File

@ -37,17 +37,6 @@ func (c *client) createFolderHandler(s *discordgo.Session, i *discordgo.Interact
nameOption string = "folder_name"
)
// Моментальный ответ для избежания столкновения с протуханием токена
initialResponse := discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral,
Content: "👩‍🍳 Cooking your query..",
},
}
s.InteractionRespond(i.Interaction, &initialResponse)
// Определение переменной для ответа
var result string = "unexpected result"

View File

@ -57,16 +57,6 @@ func (c *client) createRepoHandler(s *discordgo.Session, i *discordgo.Interactio
buildRepo = "build_repo"
nameOption = "repo_name"
)
// Моментальный ответ для избежания столкновения с протуханием токена
initialResponse := discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral,
Content: "👩‍🍳 Cooking your query..",
},
}
s.InteractionRespond(i.Interaction, &initialResponse)
// Определение переменной для ответа
var result string = "unexpected result"

View File

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"ticket-pimp/internal/domain"
"ticket-pimp/internal/helpers"
"github.com/bwmarrin/discordgo"
)
@ -21,17 +22,6 @@ func (c *client) GetInfo() Command {
func (c *client) getInfo(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
// Get channel from the request
@ -79,17 +69,6 @@ func (c *client) InitProjectFromChannel(minLength int) Command {
func (c *client) initProjectFromChannel(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
// Get channel from the request
@ -160,17 +139,6 @@ func (c *client) CreateTicketHandler(repoNameMinLength int) Command {
func (c *client) createTicketHandler(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
@ -197,8 +165,8 @@ func (c *client) createTicketHandler(s *discordgo.Session, i *discordgo.Interact
}
} else {
edit := discordgo.ChannelEdit{
Name: p.ShortName,
ParentID: "1150719794853716028",
Name: p.ShortName + "-" + helpers.Cut(option.StringValue()),
ParentID: c.conf.IsProjectChannel,
}
dchan, err = s.ChannelEdit(dchan.ID, &edit)
@ -210,7 +178,7 @@ func (c *client) createTicketHandler(s *discordgo.Session, i *discordgo.Interact
if err != nil {
log.Printf("message send problem: %v\n", err)
}
result = "Project " + p.ShortName + "Was created"
result = "Project " + p.ShortName + " was created"
}
}
}

View File

@ -27,12 +27,12 @@ func InitRouter(wc controller.WorkflowController, conf *domain.DiscordConfig, tg
r.conf = conf
r.Commands = append(r.Commands,
// r.CreateRepoHandler(3),
// r.CreateFolderHandler(3),
r.CreateRepoHandler(3),
r.CreateFolderHandler(3),
r.Ping(),
// r.CreateTicketHandler(3),
// r.InitProjectFromChannel(3),
// r.GetInfo(),
r.CreateTicketHandler(3),
r.InitProjectFromChannel(3),
r.GetInfo(),
)
r.Components = append(r.Components,
r.HandleTaskButtons(),

View File

@ -3,11 +3,10 @@ package handler
import (
"ticket-pimp/adapters"
"ticket-pimp/internal/controller"
"ticket-pimp/internal/services"
)
type Handler struct {
git services.IGit
git adapters.IGit
cloud adapters.ICloud
coda adapters.ICoda
key string
@ -16,7 +15,7 @@ type Handler struct {
}
func NewHandler(
git services.IGit,
git adapters.IGit,
cloud adapters.ICloud,
coda adapters.ICoda,
controller *controller.WorkflowController,

View File

@ -3,7 +3,6 @@ package controller
import (
"ticket-pimp/adapters"
"ticket-pimp/internal/domain"
"ticket-pimp/internal/services"
"ticket-pimp/internal/storage/db"
"github.com/bwmarrin/discordgo"
@ -11,7 +10,7 @@ import (
)
type WorkflowController struct {
IGit services.IGit
IGit adapters.IGit
ICloud adapters.ICloud
ICoda adapters.ICoda
pool *pgxpool.Pool
@ -20,7 +19,7 @@ type WorkflowController struct {
}
func NewWorkflowController(
git services.IGit,
git adapters.IGit,
cloud adapters.ICloud,
coda adapters.ICoda,
pool *pgxpool.Pool,

View File

@ -14,13 +14,6 @@ type Coda struct {
Config domain.CodaConfig
}
type ICoda interface {
ListDocs()
CreateApp(task domain.CodaApplication)
CreateTask(title string, desc string, creatorName string, creatorID string) (string, error)
GetRowLink(id string) (string, error)
}
func NewCodaClient(conf domain.CodaConfig) *Coda {
client := NewClient().

View File

@ -13,10 +13,6 @@ type Git struct {
conf *domain.GitConfig
}
type IGit interface {
CreateRepo(name string) (*domain.Git, error)
}
func NewGit(conf domain.GitConfig) *Git {
headers := map[string]string{
"Accept": "application/vnd.github+json",