From 251446d6e45d7b42af6a7995c4568183ea794dc7 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Fri, 24 Sep 2021 22:53:00 -0500 Subject: [PATCH] Do jam showcase stuff --- src/config/types.go | 9 +- src/discord/gateway.go | 11 +- src/discord/showcase.go | 12 +- .../2021-09-25T023810Z_AddJamSnippetField.go | 52 ++++++++ src/templates/src/wheeljam_index.html | 122 ++++++++++++++++++ src/website/feed.go | 2 + src/website/jam.go | 51 +++++++- src/website/landing.go | 2 + src/website/showcase.go | 2 + 9 files changed, 253 insertions(+), 10 deletions(-) create mode 100644 src/migration/migrations/2021-09-25T023810Z_AddJamSnippetField.go diff --git a/src/config/types.go b/src/config/types.go index 20b1292..eccd2d0 100644 --- a/src/config/types.go +++ b/src/config/types.go @@ -72,10 +72,11 @@ type DiscordConfig struct { OAuthClientID string OAuthClientSecret string - GuildID string - MemberRoleID string - ShowcaseChannelID string - LibraryChannelID string + GuildID string + MemberRoleID string + ShowcaseChannelID string + LibraryChannelID string + JamShowcaseChannelID string } type EpisodeGuide struct { diff --git a/src/discord/gateway.go b/src/discord/gateway.go index 1e63d22..45d7351 100644 --- a/src/discord/gateway.go +++ b/src/discord/gateway.go @@ -582,7 +582,7 @@ func (bot *botInstance) messageCreateOrUpdate(ctx context.Context, msg *Message) } if msg.ChannelID == config.Config.Discord.ShowcaseChannelID { - err := bot.processShowcaseMsg(ctx, msg) + err := bot.processShowcaseMsg(ctx, msg, false) if err != nil { logging.ExtractLogger(ctx).Error().Err(err).Msg("failed to process showcase message") return nil @@ -590,6 +590,15 @@ func (bot *botInstance) messageCreateOrUpdate(ctx context.Context, msg *Message) return nil } + if msg.ChannelID == config.Config.Discord.JamShowcaseChannelID { + err := bot.processShowcaseMsg(ctx, msg, true) + if err != nil { + logging.ExtractLogger(ctx).Error().Err(err).Msg("failed to process jam showcase message") + return nil + } + return nil + } + if msg.ChannelID == config.Config.Discord.LibraryChannelID { err := bot.processLibraryMsg(ctx, msg) if err != nil { diff --git a/src/discord/showcase.go b/src/discord/showcase.go index f2c26c4..185c0e3 100644 --- a/src/discord/showcase.go +++ b/src/discord/showcase.go @@ -25,7 +25,8 @@ var reDiscordMessageLink = regexp.MustCompile(`https?://.+?(\s|$)`) var errNotEnoughInfo = errors.New("Discord didn't send enough info in this event for us to do this") -func (bot *botInstance) processShowcaseMsg(ctx context.Context, msg *Message) error { +// TODO: Turn this ad-hoc isJam parameter into a tag or something +func (bot *botInstance) processShowcaseMsg(ctx context.Context, msg *Message, isJam bool) error { switch msg.Type { case MessageTypeDefault, MessageTypeReply, MessageTypeApplicationCommand: default: @@ -57,10 +58,17 @@ func (bot *botInstance) processShowcaseMsg(ctx context.Context, msg *Message) er return err } if doSnippet, err := AllowedToCreateMessageSnippet(ctx, tx, newMsg.UserID); doSnippet && err == nil { - _, err := CreateMessageSnippet(ctx, tx, msg.ID) + snippet, err := CreateMessageSnippet(ctx, tx, msg.ID) if err != nil { return oops.New(err, "failed to create snippet in gateway") } + + if isJam { + _, err := tx.Exec(ctx, `UPDATE handmade_snippet SET is_jam = TRUE WHERE id = $1`, snippet.ID) + if err != nil { + return oops.New(err, "failed to mark snippet as a jam snippet") + } + } } else if err != nil { return oops.New(err, "failed to check snippet permissions in gateway") } diff --git a/src/migration/migrations/2021-09-25T023810Z_AddJamSnippetField.go b/src/migration/migrations/2021-09-25T023810Z_AddJamSnippetField.go new file mode 100644 index 0000000..a5a8a30 --- /dev/null +++ b/src/migration/migrations/2021-09-25T023810Z_AddJamSnippetField.go @@ -0,0 +1,52 @@ +package migrations + +import ( + "context" + "time" + + "git.handmade.network/hmn/hmn/src/migration/types" + "git.handmade.network/hmn/hmn/src/oops" + "github.com/jackc/pgx/v4" +) + +func init() { + registerMigration(AddJamSnippetField{}) +} + +type AddJamSnippetField struct{} + +func (m AddJamSnippetField) Version() types.MigrationVersion { + return types.MigrationVersion(time.Date(2021, 9, 25, 2, 38, 10, 0, time.UTC)) +} + +func (m AddJamSnippetField) Name() string { + return "AddJamSnippetField" +} + +func (m AddJamSnippetField) Description() string { + return "Add a special field for jam snippets" +} + +func (m AddJamSnippetField) Up(ctx context.Context, tx pgx.Tx) error { + _, err := tx.Exec(ctx, ` + ALTER TABLE handmade_snippet + ADD is_jam BOOLEAN NOT NULL DEFAULT FALSE; + `) + if err != nil { + return oops.New(err, "failed to add jam column") + } + + return nil +} + +func (m AddJamSnippetField) Down(ctx context.Context, tx pgx.Tx) error { + _, err := tx.Exec(ctx, ` + ALTER TABLE handmade_snippet + DROP is_jam; + `) + if err != nil { + return oops.New(err, "failed to drop jam column") + } + + return nil +} diff --git a/src/templates/src/wheeljam_index.html b/src/templates/src/wheeljam_index.html index 22c8e02..194e6fe 100644 --- a/src/templates/src/wheeljam_index.html +++ b/src/templates/src/wheeljam_index.html @@ -22,12 +22,19 @@ Handmade Network {{ end }} + + +