93 lines
2.1 KiB
Go
93 lines
2.1 KiB
Go
package handler
|
||
|
||
import (
|
||
"log"
|
||
|
||
"github.com/bwmarrin/discordgo"
|
||
)
|
||
|
||
func (h *router) CreateExternalTask() CommandRoute {
|
||
return CommandRoute{
|
||
|
||
Command: discordgo.ApplicationCommand{
|
||
Name: "test",
|
||
Description: "Buttons test",
|
||
},
|
||
|
||
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)
|
||
|
||
// go func() {
|
||
// h.controller.InitTask("something like a default description")
|
||
// }()
|
||
},
|
||
}
|
||
}
|
||
|
||
func (h *router) StartTask() ComponentRoute {
|
||
return ComponentRoute{
|
||
Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||
|
||
h.controller.UpdateTask(i.Message.ID, 0)
|
||
|
||
newMsg := discordgo.MessageEdit{
|
||
Channel: i.ChannelID,
|
||
ID: i.Message.ID,
|
||
Components: []discordgo.MessageComponent{
|
||
discordgo.ActionsRow{
|
||
Components: []discordgo.MessageComponent{
|
||
discordgo.Button{
|
||
Label: "Close",
|
||
Style: discordgo.DangerButton,
|
||
Disabled: false,
|
||
CustomID: "task_close",
|
||
},
|
||
},
|
||
},
|
||
},
|
||
}
|
||
|
||
editedM, err := s.ChannelMessageEditComplex(&newMsg)
|
||
if err != nil {
|
||
log.Println("edition NOT complete, ", err)
|
||
}
|
||
|
||
log.Print(editedM)
|
||
|
||
},
|
||
}
|
||
}
|
||
|
||
func (h *router) CloseTask() ComponentRoute {
|
||
return ComponentRoute{
|
||
Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||
|
||
h.controller.UpdateTask(i.Message.ID, 1)
|
||
|
||
newMsg := discordgo.MessageEdit{
|
||
Channel: i.ChannelID,
|
||
ID: i.Message.ID,
|
||
Components: []discordgo.MessageComponent{},
|
||
}
|
||
|
||
editedM, err := s.ChannelMessageEditComplex(&newMsg)
|
||
if err != nil {
|
||
log.Println("edition NOT complete, ", err)
|
||
}
|
||
|
||
log.Print(editedM)
|
||
|
||
},
|
||
}
|
||
}
|