- check private messages into separate function;
This commit is contained in:
parent
d42b590a14
commit
6e69c64c42
|
|
@ -1,6 +1,7 @@
|
|||
package discord
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
|
@ -25,6 +26,24 @@ type DiscordOptions struct {
|
|||
Controller *controller.WorkflowController
|
||||
}
|
||||
|
||||
func checkPrivateMessaging(s *discordgo.Session, i *discordgo.InteractionCreate) error {
|
||||
dchan, err := s.Channel(i.ChannelID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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 errors.New("no private messages! lol")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Run(conf domain.Config, opts DiscordOptions) error {
|
||||
token := conf.Discord.Token
|
||||
|
||||
|
|
@ -42,46 +61,21 @@ func Run(conf domain.Config, opts DiscordOptions) error {
|
|||
"task_close": router.Components[0].Handler,
|
||||
}
|
||||
|
||||
s.AddHandler(router.ListenPostsHandler)
|
||||
s.AddHandler(router.ListenPosts)
|
||||
|
||||
s.AddHandler(func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
err := checkPrivateMessaging(s, i)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
switch i.Type {
|
||||
case discordgo.InteractionApplicationCommand:
|
||||
if h, ok := commandHandlers[i.ApplicationCommandData().Name]; ok {
|
||||
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
|
||||
}
|
||||
|
||||
h(s, i)
|
||||
}
|
||||
case discordgo.InteractionMessageComponent:
|
||||
if h, ok := componentsHandlers[i.MessageComponentData().CustomID]; ok {
|
||||
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
|
||||
}
|
||||
|
||||
h(s, i)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue