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