From 1dcbd5afa8d8a13bb0f70a41640eccb8c1f468c9 Mon Sep 17 00:00:00 2001 From: Dusty Pianalto Date: Sun, 19 Apr 2020 21:59:00 -0800 Subject: [PATCH] Add command to add a guild to the DB --- djpianalto.com/goff/exts/guild.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/djpianalto.com/goff/exts/guild.go b/djpianalto.com/goff/exts/guild.go index 2fac6b0..1b43481 100644 --- a/djpianalto.com/goff/exts/guild.go +++ b/djpianalto.com/goff/exts/guild.go @@ -176,3 +176,30 @@ func getWelcomeChannel(ctx disgoman.Context, _ []string) { } _, _ = ctx.Send(fmt.Sprintf("The welcome channel is currently %s", channel.Mention())) } + +func addGuild(ctx disgoman.Context, args []string) { + var guildID string + row := utils.Database.QueryRow("SELECT id FROM guilds where id=$1", ctx.Guild.ID) + err := row.Scan(&guildID) + if err == nil { + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "This guild is already in my database", + Error: err, + } + return + } + + _, err = utils.Database.Query("INSERT INTO guilds (id) VALUES ($1)", ctx.Guild.ID) + if err != nil { + fmt.Println(err) + ctx.ErrorChannel <- disgoman.CommandError{ + Context: ctx, + Message: "There was a problem inserting this guild into the database", + Error: err, + } + return + } + _, _ = ctx.Send("This guild has been added.") + +}