Add puzzle parser and config
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package exts
|
||||
|
||||
import (
|
||||
"djpianalto.com/goff/djpianalto.com/goff/utils"
|
||||
"fmt"
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"strings"
|
||||
|
||||
"djpianalto.com/goff/djpianalto.com/goff/utils"
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
)
|
||||
|
||||
// Guild management commands
|
||||
@@ -203,3 +204,87 @@ func addGuildCommand(ctx disgoman.Context, args []string) {
|
||||
_, _ = ctx.Send("This guild has been added.")
|
||||
|
||||
}
|
||||
|
||||
func puzzleChannel(ctx disgoman.Context, args []string) {
|
||||
var idString string
|
||||
if len(args) > 0 {
|
||||
idString = args[0]
|
||||
if strings.HasPrefix(idString, "<#") && strings.HasSuffix(idString, ">") {
|
||||
idString = idString[2 : len(idString)-1]
|
||||
}
|
||||
} else {
|
||||
idString = ""
|
||||
}
|
||||
fmt.Println(idString)
|
||||
if idString == "" {
|
||||
_, err := utils.Database.Exec("UPDATE guilds SET puzzle_channel='' WHERE id=$1;", ctx.Guild.ID)
|
||||
if err != nil {
|
||||
ctx.ErrorChannel <- disgoman.CommandError{
|
||||
Context: ctx,
|
||||
Message: "Error Updating Database",
|
||||
Error: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
_, _ = ctx.Send("Puzzle Channel Updated.")
|
||||
return
|
||||
}
|
||||
channel, err := ctx.Session.State.Channel(idString)
|
||||
if err != nil {
|
||||
ctx.ErrorChannel <- disgoman.CommandError{
|
||||
Context: ctx,
|
||||
Message: "Can't find that channel.",
|
||||
Error: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
if channel.GuildID != ctx.Guild.ID {
|
||||
ctx.ErrorChannel <- disgoman.CommandError{
|
||||
Context: ctx,
|
||||
Message: "The channel passed is not in this guild.",
|
||||
Error: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
_, err = utils.Database.Exec("UPDATE guilds SET puzzle_channel=$1 WHERE id=$2;", idString, ctx.Guild.ID)
|
||||
if err != nil {
|
||||
ctx.ErrorChannel <- disgoman.CommandError{
|
||||
Context: ctx,
|
||||
Message: "Error Updating Database",
|
||||
Error: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
_, _ = ctx.Send("Puzzle Channel Updated.")
|
||||
}
|
||||
|
||||
func getPuzzleChannel(ctx disgoman.Context, _ []string) {
|
||||
var channelID string
|
||||
row := utils.Database.QueryRow("SELECT puzzle_channel FROM guilds where id=$1", ctx.Guild.ID)
|
||||
err := row.Scan(&channelID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
ctx.ErrorChannel <- disgoman.CommandError{
|
||||
Context: ctx,
|
||||
Message: "Error getting data from the database.",
|
||||
Error: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
if channelID == "" {
|
||||
_, _ = ctx.Send("The puzzle channel is not set.")
|
||||
return
|
||||
}
|
||||
channel, err := ctx.Session.State.GuildChannel(ctx.Guild.ID, channelID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
ctx.ErrorChannel <- disgoman.CommandError{
|
||||
Context: ctx,
|
||||
Message: "I got the channel ID but it does not appear to be a valid channel in this guild.",
|
||||
Error: err,
|
||||
}
|
||||
return
|
||||
}
|
||||
_, _ = ctx.Send(fmt.Sprintf("The puzzle channel is currently %s", channel.Mention()))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -186,4 +186,22 @@ func AddCommandHandlers(h *disgoman.CommandManager) {
|
||||
RequiredPermissions: 0,
|
||||
Invoke: deinterleave,
|
||||
})
|
||||
_ = h.AddCommand(&disgoman.Command{
|
||||
Name: "set-puzzle-channel",
|
||||
Aliases: []string{"spc"},
|
||||
Description: "Set the channel puzzle messages will be sent to.",
|
||||
OwnerOnly: false,
|
||||
Hidden: false,
|
||||
RequiredPermissions: disgoman.PermissionManageServer,
|
||||
Invoke: puzzleChannel,
|
||||
})
|
||||
_ = h.AddCommand(&disgoman.Command{
|
||||
Name: "get-puzzle-channel",
|
||||
Aliases: []string{"gpc"},
|
||||
Description: "Gets the channel puzzle messages will be sent to.",
|
||||
OwnerOnly: false,
|
||||
Hidden: false,
|
||||
RequiredPermissions: disgoman.PermissionManageServer,
|
||||
Invoke: getPuzzleChannel,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user