83 lines
2.1 KiB
Go
83 lines
2.1 KiB
Go
package discord_handler
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
"github.com/bwmarrin/discordgo"
|
||
)
|
||
|
||
func (h *Handler) 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
|
||
}
|
||
}
|
||
|
||
func (h *Handler) AllInteractions(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||
|
||
dchan, err := s.Channel(i.ChannelID)
|
||
if err != nil {
|
||
return
|
||
}
|
||
|
||
if dchan.Type == discordgo.ChannelTypeDM {
|
||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||
Data: &discordgo.InteractionResponseData{
|
||
Content: "Yo, fella! I'm not working in private!",
|
||
},
|
||
})
|
||
return
|
||
}
|
||
|
||
// Моментальный ответ для избежания столкновения с протуханием токена
|
||
initialResponse := discordgo.InteractionResponse{
|
||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||
Data: &discordgo.InteractionResponseData{
|
||
Flags: discordgo.MessageFlagsEphemeral,
|
||
Content: "👩🍳 Cooking your query..",
|
||
},
|
||
}
|
||
|
||
s.InteractionRespond(i.Interaction, &initialResponse)
|
||
}
|
||
|
||
// setFlag
|
||
// sets tag with In progress and Done text to discords channel;
|
||
func (h *Handler) setFlag(s *discordgo.Session, i *discordgo.InteractionCreate, tag *discordgo.ForumTag) error {
|
||
|
||
th, err := s.Channel(i.ChannelID)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
|
||
forum, err := s.Channel(th.ParentID)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
|
||
// Проверка на существование тега в списке тегов:
|
||
if len(forum.AvailableTags) != 0 {
|
||
for _, some := range forum.AvailableTags {
|
||
if some.Name == tag.Name {
|
||
_, err := s.ChannelEditComplex(i.ChannelID, &discordgo.ChannelEdit{
|
||
AppliedTags: &[]string{some.ID},
|
||
})
|
||
if err != nil {
|
||
return err
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return nil
|
||
}
|