Skip to content

Commit

Permalink
Fix AndBobsYourUncle#15: not allow to use DM for now
Browse files Browse the repository at this point in the history
  • Loading branch information
shtrih committed Mar 2, 2023
1 parent ddcf708 commit 525dfbb
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions discord_bot/discord_bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"errors"
"fmt"
"log"
"stable_diffusion_bot/imagine_queue"
"strconv"
"strings"

"stable_diffusion_bot/imagine_queue"

"github.com/bwmarrin/discordgo"
)

Expand Down Expand Up @@ -301,6 +302,7 @@ func (b *botImpl) processImagineVariation(s *discordgo.Session, i *discordgo.Int
}
}

// TODO: add option to enable usage in DM
func (b *botImpl) processImagineCommand(s *discordgo.Session, i *discordgo.InteractionCreate) {
options := i.ApplicationCommandData().Options

Expand All @@ -313,29 +315,43 @@ func (b *botImpl) processImagineCommand(s *discordgo.Session, i *discordgo.Inter
var queueError error
var prompt string

// Do not allow DM usage
isDM := i.GuildID == ""

if option, ok := optionMap["prompt"]; ok {
prompt = option.StringValue()

position, queueError = b.imagineQueue.AddImagine(&imagine_queue.QueueItem{
Prompt: prompt,
Type: imagine_queue.ItemTypeImagine,
DiscordInteraction: i.Interaction,
})
if queueError != nil {
log.Printf("Error adding imagine to queue: %v\n", queueError)
if !isDM {
position, queueError = b.imagineQueue.AddImagine(&imagine_queue.QueueItem{
Prompt: prompt,
Type: imagine_queue.ItemTypeImagine,
DiscordInteraction: i.Interaction,
})
if queueError != nil {
log.Printf("Error adding imagine to queue: %v\n", queueError)
}
}
}

s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
message := "DM usage is not allowed."
if !isDM {
message = fmt.Sprintf(
"I'm dreaming something up for you. You are currently #%d in line.\n<@%s> asked me to imagine \"%s\".",
position,
i.Member.User.ID,
prompt,
)
}

err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: fmt.Sprintf(
"I'm dreaming something up for you. You are currently #%d in line.\n<@%s> asked me to imagine \"%s\".",
position,
i.Member.User.ID,
prompt),
Content: message,
},
})
if err != nil {
log.Printf("Error send interaction resp: %v\n", err)
}
}

func (b *botImpl) processImagineSettingsCommand(s *discordgo.Session, i *discordgo.InteractionCreate) {
Expand Down

0 comments on commit 525dfbb

Please sign in to comment.