dash command
This commit is contained in:
parent
1beb950e13
commit
955e3f1d46
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
testing/
|
testing/
|
||||||
bin/
|
bin/
|
||||||
|
start.sh
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"mazesolver/internal/solvemaze"
|
"mazesolver/internal/solvemaze"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
@ -28,7 +29,7 @@ func Run(BotToken string) {
|
|||||||
Options: []*discordgo.ApplicationCommandOption {
|
Options: []*discordgo.ApplicationCommandOption {
|
||||||
{
|
{
|
||||||
Type: discordgo.ApplicationCommandOptionString,
|
Type: discordgo.ApplicationCommandOptionString,
|
||||||
Name: "image-link",
|
Name: "message-link",
|
||||||
Description: "link to maze image",
|
Description: "link to maze image",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
@ -49,19 +50,8 @@ func Run(BotToken string) {
|
|||||||
|
|
||||||
switch data.Name {
|
switch data.Name {
|
||||||
case "solve-maze":
|
case "solve-maze":
|
||||||
maze, err := getMaze.GetMaze(i.ApplicationCommandData().Options[0].Value.(string))
|
|
||||||
if err != nil {
|
}
|
||||||
responseData = "You must provide an image! Select the maze, click \"open in browser\", and copy the link of the image"
|
|
||||||
} else {
|
|
||||||
if (len(maze) < 1) {
|
|
||||||
responseData = "You must provide an image! Select the maze, click \"open in browser\", and copy the link of the image"
|
|
||||||
} else {
|
|
||||||
points := solvemaze.FindPath(maze)
|
|
||||||
if (len(points) < 1) {
|
|
||||||
responseData = "You must provide an image! Select the maze, click \"open in browser\", and copy the link of the image"
|
|
||||||
} else {
|
|
||||||
outputmaze.EditMaze(points, "/tmp/maze.png", "/tmp/outputmaze.png")
|
|
||||||
}}}}
|
|
||||||
|
|
||||||
if responseData != "" {
|
if responseData != "" {
|
||||||
err = s.InteractionRespond(
|
err = s.InteractionRespond(
|
||||||
@ -74,9 +64,9 @@ func Run(BotToken string) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
} else {
|
||||||
fileName := "/tmp/outputmaze.png"
|
fileName := "/tmp/outputmaze.png"
|
||||||
f, err := os.Open(fileName)
|
f, _ := os.Open(fileName)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
err = s.InteractionRespond(
|
err = s.InteractionRespond(
|
||||||
i.Interaction,
|
i.Interaction,
|
||||||
@ -92,19 +82,60 @@ func Run(BotToken string) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
discord.AddHandler( func(
|
discord.AddHandler(func (
|
||||||
s *discordgo.Session,
|
s *discordgo.Session,
|
||||||
m *discordgo.MessageCreate,
|
m *discordgo.MessageCreate,
|
||||||
) {
|
) {
|
||||||
listOfGuilds := discord.State.Guilds
|
if (m.Content == "-solve") {
|
||||||
for _, v := range listOfGuilds {
|
if (m.MessageReference == nil) {
|
||||||
fmt.Println(v.Name)
|
s.ChannelMessageSendReply(m.ChannelID, "Please reply to a message with a maze", m.Reference())
|
||||||
|
} else {
|
||||||
|
reply, err := s.ChannelMessage(m.MessageReference.ChannelID, m.MessageReference.MessageID)
|
||||||
|
if (err != nil) {
|
||||||
|
s.ChannelMessageSendReply(m.ChannelID, "Please reply to a message with a maze", m.Reference())
|
||||||
|
} else {
|
||||||
|
if (len(reply.Attachments) < 1) {
|
||||||
|
s.ChannelMessageSendReply(m.ChannelID, "Reply does not contain a maze", m.Reference())
|
||||||
|
} else if (len(reply.Attachments) > 1) {
|
||||||
|
s.ChannelMessageSendReply(m.ChannelID, "Too many images!", m.Reference())
|
||||||
|
} else {
|
||||||
|
maze, err := getMaze.GetMaze(reply.Attachments[0].URL)
|
||||||
|
if (err != nil) {
|
||||||
|
s.ChannelMessageSendReply(m.ChannelID, "Send a valid maze", m.Reference())
|
||||||
|
} else {
|
||||||
|
points := solvemaze.FindPath(maze)
|
||||||
|
_, err := outputmaze.EditMaze(points, "/tmp/maze.png", "/tmp/outputmaze.png")
|
||||||
|
if err != nil {
|
||||||
|
s.ChannelMessageSendReply(m.ChannelID, "server error", m.Reference())
|
||||||
|
}
|
||||||
|
f, _ := os.Open("/tmp/outputmaze.png")
|
||||||
|
_, err = s.ChannelMessageSendComplex(m.ChannelID, &discordgo.MessageSend{
|
||||||
|
Files: []*discordgo.File{
|
||||||
|
{
|
||||||
|
Name: "/tmp/outputmaze.png",
|
||||||
|
Reader: f,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Reference: &discordgo.MessageReference{
|
||||||
|
MessageID: m.Reference().MessageID,
|
||||||
|
ChannelID: m.Reference().ChannelID,
|
||||||
|
GuildID: m.Reference().GuildID,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -119,3 +150,14 @@ func Run(BotToken string) {
|
|||||||
err = discord.Close()
|
err = discord.Close()
|
||||||
if err != nil { log.Fatal(err) }
|
if err != nil { log.Fatal(err) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseMessageLink(link string) (string, string, string, error) {
|
||||||
|
parts := strings.Split(link, "/")
|
||||||
|
if len(parts) < 7 {
|
||||||
|
return "", "", "", fmt.Errorf("invalid message link format")
|
||||||
|
}
|
||||||
|
guildID := parts[4]
|
||||||
|
channelID := parts[5]
|
||||||
|
messageID := parts[6]
|
||||||
|
return guildID, channelID, messageID, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user