Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
h3mmy committed Apr 14, 2024
2 parents a4c69a8 + 8409b31 commit b9ffd88
Show file tree
Hide file tree
Showing 26 changed files with 399 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
source .config.test
source .config.dev
4 changes: 2 additions & 2 deletions .github/workflows/action-image-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Generate Token
uses: actions/create-github-app-token@v1.9.1
uses: actions/create-github-app-token@v1.9.3
id: generate-token
with:
app-id: "${{ secrets.APP_ID }}"
Expand Down Expand Up @@ -212,7 +212,7 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Generate Token
uses: actions/create-github-app-token@v1.9.1
uses: actions/create-github-app-token@v1.9.3
id: generate-token
with:
app-id: "${{ secrets.APP_ID }}"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/issue-project-sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Generate Token
uses: actions/create-github-app-token@v1.9.1
uses: actions/create-github-app-token@v1.9.3
id: generate-token
with:
app-id: "${{ secrets.APP_ID }}"
private-key: "${{ secrets.APP_PRIVATE_KEY }}"
# https://github.com/actions/add-to-project
- uses: actions/add-to-project@2e5cc851ca7162e9eb510e6da6a5c64022e606a7 # v1.0.0
- uses: actions/add-to-project@9bfe908f2eaa7ba10340b31e314148fcfe6a2458 # v1.0.1
with:
project-url: https://github.com/users/h3mmy/projects/3
# PAT needs repo & project scope
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/meta-sync-labels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Generate Token
uses: actions/create-github-app-token@v1.9.1
uses: actions/create-github-app-token@v1.9.3
id: generate-token
with:
app-id: "${{ secrets.APP_ID }}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/on-merge-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Generate Token
uses: actions/create-github-app-token@v1.9.1
uses: actions/create-github-app-token@v1.9.3
id: generate-token
with:
app-id: "${{ secrets.APP_ID }}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-renovate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
token: "${{ steps.app-token.outputs.token }}"

- name: Renovate
uses: renovatebot/github-action@v40.1.7
uses: renovatebot/github-action@v40.1.9
env:
LOG_LEVEL: ${{ inputs.renovateLogLevel }}
RENOVATE_DRY_RUN: ${{ inputs.dryRun }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tag-charts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: "Generate Short Lived OAuth App Token (ghs_*)"
uses: actions/create-github-app-token@v1.9.1
uses: actions/create-github-app-token@v1.9.3
id: app-token
with:
app-id: "${{ secrets.APP_ID }}"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

*.env.*
*.config.(^sample)
.config.dev
config.yaml
bloopyboi_dev
bloopyboii_dev
Expand Down
14 changes: 7 additions & 7 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.helm:
image:
name: alpine/helm:latest@sha256:4d922280422ca1fc1a10f0358e544c6f04fdacbadf792296b60142915d630514
name: alpine/helm:latest@sha256:31ce11c4ee98c5e1e13628ead9212e665f32c3277cae63bd55ced32989089f3e
entrypoint: [""]
variables:
CHART_NAME: bloopyboi
Expand Down Expand Up @@ -47,10 +47,10 @@ stages:

docker_build:
# Use the official docker image.
image: docker:latest@sha256:016c45d9e31461802186e8e9aaa394f35e173a8ce913ea7195a672cdc97102f2
image: docker:latest@sha256:557204dd876c17dc674d03af9083ad2d19f27848e76b6022d17a289efbd4f9c9
stage: build
services:
- docker:dind@sha256:016c45d9e31461802186e8e9aaa394f35e173a8ce913ea7195a672cdc97102f2
- docker:dind@sha256:557204dd876c17dc674d03af9083ad2d19f27848e76b6022d17a289efbd4f9c9
before_script:
- !reference [.docker, before_script]
script:
Expand Down Expand Up @@ -79,9 +79,9 @@ docker_build:

# Tags only the $CI_DEFAULT_BRANCH as latest
push_latest:
image: docker:latest@sha256:016c45d9e31461802186e8e9aaa394f35e173a8ce913ea7195a672cdc97102f2
image: docker:latest@sha256:557204dd876c17dc674d03af9083ad2d19f27848e76b6022d17a289efbd4f9c9
services:
- docker:dind@sha256:016c45d9e31461802186e8e9aaa394f35e173a8ce913ea7195a672cdc97102f2
- docker:dind@sha256:557204dd876c17dc674d03af9083ad2d19f27848e76b6022d17a289efbd4f9c9
variables:
# Disable fresh pull of source
GIT_STRATEGY: none
Expand All @@ -98,9 +98,9 @@ push_latest:
- docker push $CI_REGISTRY_IMAGE:latest

push_tag:
image: docker:latest@sha256:016c45d9e31461802186e8e9aaa394f35e173a8ce913ea7195a672cdc97102f2
image: docker:latest@sha256:557204dd876c17dc674d03af9083ad2d19f27848e76b6022d17a289efbd4f9c9
services:
- docker:dind@sha256:016c45d9e31461802186e8e9aaa394f35e173a8ce913ea7195a672cdc97102f2
- docker:dind@sha256:557204dd876c17dc674d03af9083ad2d19f27848e76b6022d17a289efbd4f9c9
variables:
GIT_STRATEGY: none
stage: push
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22-alpine@sha256:0466223b8544fb7d4ff04748acc4d75a608234bf4e79563bff208d2060c0dd79 as build
FROM golang:1.22-alpine@sha256:cdc86d9f363e8786845bea2040312b4efa321b828acdeb26f393faa864d887b0 as build

ARG TARGETPLATFORM
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}
Expand Down
2 changes: 1 addition & 1 deletion bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (bot *BloopyBoi) Run(ctx context.Context) error {
}

bot.log.Debug(fmt.Sprintf("FeatureMap contains %d entries", len(providers.GetFeatures())))
bot.log.Debug(fmt.Sprintf("Experimental is enabled: %v", providers.IsFeaturedConfigured("experimental")))
bot.log.Debug(fmt.Sprintf("Experimental is enabled: %v", providers.IsFeatureEnabled("experimental")))

errGroup, ctx := errgroup.WithContext(ctx)
errGroup.Go(func() error {
Expand Down
1 change: 1 addition & 0 deletions bot/discord/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (d *DiscordManager) Start(ctx context.Context) error {
if err != nil {
return fmt.Errorf("While opening a connection: %w", err)
}
// d.discordSvc.GetSession().LogLevel = discordgo.LogDebug

d.log.Info("Registering App Commands")
for _, v := range providers.GetDiscordAppCommands(d.discordCfg.GuildConfigs) {
Expand Down
63 changes: 48 additions & 15 deletions bot/handlers/blissfest.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type BlissfestCommand struct {
blissSvc *services.BlissfestService
// GuildID for which this command will be active
// For global commands, set to ""
guildId string
roles []int64
guildId string
roles []int64
}

func NewBlissfestCommand(svc *services.BlissfestService) *BlissfestCommand {
Expand All @@ -32,11 +32,12 @@ func NewBlissfestCommand(svc *services.BlissfestService) *BlissfestCommand {
logger: log.NewZapLogger().Named("blissfest_command"),
blissSvc: svc,
guildId: "",
roles: []int64{},
roles: []int64{},
}
}

func (p *BlissfestCommand) WithGuild(guildId string) *BlissfestCommand {
p.logger.Debug("setting guild", zap.String("guildId", guildId))
p.guildId = guildId
return p
}
Expand Down Expand Up @@ -67,6 +68,7 @@ func (p *BlissfestCommand) GetAppCommand() *discordgo.ApplicationCommand {

func (p *BlissfestCommand) GetAppCommandHandler() func(s *discordgo.Session, i *discordgo.InteractionCreate) {
return func(s *discordgo.Session, i *discordgo.InteractionCreate) {
p.logger.Debug("received interaction", zap.String("interactionID", i.ID), zap.String("username", GetDiscordUserFromInteraction(i).Username))
getLineUp := false
// Access options in the order provided by the user.
options := i.ApplicationCommandData().Options
Expand All @@ -79,30 +81,61 @@ func (p *BlissfestCommand) GetAppCommandHandler() func(s *discordgo.Session, i *
bsvc := p.blissSvc
var resData discordgo.InteractionResponseData

if getLineUp {
resData = discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{
resEmbeds := []*discordgo.MessageEmbed{}

adultWeekendPriceLevel, err := bsvc.GetAdultWeekendPriceLevel()
var adultWeekendPriceLevelEmbed *discordgo.MessageEmbed
if err != nil {
p.logger.Warn("error getting adult weekend price level. Not including in response", zap.Error(err))
} else {
adultWeekendPriceLevelEmbed = &discordgo.MessageEmbed{
Title: "Adult Weekend (18+) Ticket Info",
Fields: []*discordgo.MessageEmbedField{
{
Author: &discordgo.MessageEmbedAuthor{},
Image: &discordgo.MessageEmbedImage{
URL: bsvc.GetLineupImageURI(),
},
Name: "Active",
Value: fmt.Sprintf("%t", adultWeekendPriceLevel.Active == "1"),
},
{
Name: "Price",
Value: adultWeekendPriceLevel.Price, //fmt.Sprintf("%.2f",adultWeekendPriceLevel.Price),
},
{
Name: "Transaction Limit",
Value: adultWeekendPriceLevel.TransactionLimit, //fmt.Sprintf("%d", adultWeekendPriceLevel.TransactionLimit),
},
},
Title: "Blissfest",
}
resEmbeds = append(resEmbeds, adultWeekendPriceLevelEmbed)
}

if getLineUp {
resEmbeds = append(resEmbeds, &discordgo.MessageEmbed{
Title: fmt.Sprintf("%d Blissfest Lineup", bsvc.GetStartTime().Year()),
Author: &discordgo.MessageEmbedAuthor{},
Image: &discordgo.MessageEmbedImage{
URL: bsvc.GetLineupImageURI(),
},
})
}
if len(resEmbeds) > 0 {
resData = discordgo.InteractionResponseData{
Embeds: resEmbeds,
Title: "Blissfest",
// pending https://github.com/dustin/go-humanize/pull/92
// Content: fmt.Sprintf("%s left", humanize.Time(bsvc.GetTimeUntilStart(nil))),
Content: fmt.Sprintf("%s left", humanize.Time(*bsvc.GetStartTime())),
Content: fmt.Sprintf("blissfest starts %s", humanize.Time(*bsvc.GetStartTime())),
}

} else {
resData = discordgo.InteractionResponseData{
Title: "Blissfest",
Content: fmt.Sprintf("%s left", humanize.Time(*bsvc.GetStartTime())),
// pending https://github.com/dustin/go-humanize/pull/92
// Content: fmt.Sprintf("%s left", humanize.Time(bsvc.GetTimeUntilStart(nil))),
Content: fmt.Sprintf("blissfest start %s", humanize.Time(*bsvc.GetStartTime())),
}
}
p.logger.Debug("finished constructing response", zap.Bool("getLineup", getLineUp))

err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &resData,
})
Expand Down
8 changes: 4 additions & 4 deletions bot/handlers/book_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (b *BookCommand) GetAppCommandHandler() func(s *discordgo.Session, i *disco
discordgo.Button{
Label: blabel,
Style: discordgo.PrimaryButton,
Emoji: discordgo.ComponentEmoji{
Emoji: &discordgo.ComponentEmoji{
Name: "📖",
},
Disabled: false,
Expand All @@ -177,7 +177,7 @@ func (b *BookCommand) GetAppCommandHandler() func(s *discordgo.Session, i *disco
selectOpts = append(selectOpts,
discordgo.SelectMenuOption{
Value: volume.Id,
Emoji: discordgo.ComponentEmoji{
Emoji: &discordgo.ComponentEmoji{
Name: "📖",
},
Label: blabel,
Expand Down Expand Up @@ -370,15 +370,15 @@ func (b *BookCommand) GetMessageComponentHandlers() map[string]func(s *discordgo
Label: "Request",
Style: discordgo.SuccessButton,
CustomID: "request_book",
Emoji: discordgo.ComponentEmoji{
Emoji: &discordgo.ComponentEmoji{
Name: "✅",
},
},
discordgo.Button{
Label: "Ignore",
Style: discordgo.SecondaryButton,
CustomID: "ignore_book",
Emoji: discordgo.ComponentEmoji{
Emoji: &discordgo.ComponentEmoji{
Name: "⭕",
},
},
Expand Down
9 changes: 9 additions & 0 deletions bot/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,12 @@ func (myConfig *AppConfig) GetConfiguredFeatureNames() []string {
}
return names
}

// Checks FeatureConfigs for key
func (myConfig *AppConfig) IsFeaturedEnabled(key string) bool {
fCfg, ok := myConfig.FeatureMap[key]
if !ok {
return false
}
return fCfg.Enabled
}
21 changes: 13 additions & 8 deletions bot/providers/app_command_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/h3mmy/bloopyboi/bot/handlers"
"github.com/h3mmy/bloopyboi/bot/internal/config"
"github.com/h3mmy/bloopyboi/bot/internal/models"
pkgmodels "github.com/h3mmy/bloopyboi/internal/models"
"go.uber.org/zap"
)

Expand All @@ -12,18 +13,18 @@ func GetDiscordAppCommands(cfgs []config.DiscordGuildConfig) []models.DiscordApp
handls = append(handls, handlers.NewInspiroCommand(GetInspiroService()))
handls = append(handls, GetGuildAppCommands(cfgs)...)
logger.Debug("got discord commands", zap.Int("count", len(handls)))
return handls
return handls
}

func GetGuildAppCommands(cfgs []config.DiscordGuildConfig) []models.DiscordAppCommand {
handls := make([]models.DiscordAppCommand, 0, 3)
logger.Debug("getting configs for guilds", zap.Int("count", len(cfgs)))
for _, guild := range cfgs {
logger.Debug("getting guild commands", zap.Int("count", len(guild.GuildCommandConfig)))
for _,v := range guild.GuildCommandConfig {
for _, v := range guild.GuildCommandConfig {
logger.Debug("getting guild command", zap.String("name", v.Name), zap.Bool("enabled", v.Enabled))
if v.Enabled {
cmd := GetCommandWithConfig(guild.GuildId, v)
cmd := GetCommandWithConfig(guild.GuildId, v)
if cmd != nil {
handls = append(handls, cmd)
}
Expand All @@ -35,25 +36,29 @@ func GetGuildAppCommands(cfgs []config.DiscordGuildConfig) []models.DiscordAppCo
}

func GetCommandWithConfig(guildId string, cfg config.GuildCommandConfig) models.DiscordAppCommand {
flogger := logger.With(zap.String("guild_app_command", cfg.Name), zap.String("guild_id", guildId))
// get from repository TODO
if cfg.Name == "blissfest" {
logger.Debug("adding blissfest command")
return handlers.NewBlissfestCommand(GetBlissfestService()).WithGuild(guildId).WithRoles(cfg.Roles...)
flogger.Debug("Checking if feature enabled")
if IsFeatureEnabled(pkgmodels.BlissfestFeatureKey) {
return handlers.NewBlissfestCommand(GetBlissfestService()).WithGuild(guildId).WithRoles(cfg.Roles...)
}
flogger.Warn("blissfest guild command exists but feature is disabled")
} else if cfg.Name == "book" {
bookSvc, err := GetBookService()
if err != nil {
logger.Error("failed to create book svc", zap.Error(err))
flogger.Error("failed to create book svc", zap.Error(err))
} else {
return handlers.NewBookCommand(bookSvc).WithRoles(cfg.Roles...).WithGuild(guildId)
}
} else if cfg.Name == "requests" {
bookSvc, err := GetBookService()
if err != nil {
logger.Error("failed to create book svc", zap.Error(err))
flogger.Error("failed to create book svc", zap.Error(err))
} else {
return handlers.NewUserRequestCommand(bookSvc).WithRoles(cfg.Roles...).WithGuild(guildId)
}
}
logger.Warn("not adding command", zap.String("name", cfg.Name))
flogger.Warn("not adding command", zap.String("name", cfg.Name))
return nil
}
Loading

0 comments on commit b9ffd88

Please sign in to comment.