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 authored Feb 26, 2024
2 parents e85e0c2 + 857b942 commit 713d481
Show file tree
Hide file tree
Showing 85 changed files with 6,944 additions and 1,256 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/action-image-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
echo 'sendNotification=${{ inputs.sendNotification }}'
- name: Setup CUE
uses: cue-lang/setup-cue@1713281ae501e533ff06108005dffeab9e2e5203
uses: cue-lang/setup-cue@a93fa358375740cd8b0078f76355512b9208acb1

- name: Validate Image Metadata
shell: bash
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Generate Token
uses: actions/[email protected].0
uses: actions/[email protected].1
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/[email protected].0
uses: actions/[email protected].1
id: generate-token
with:
app-id: "${{ secrets.APP_ID }}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/charts-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
chart: "charts/${{ matrix.chart }}"

- name: Install Kubernetes tools
uses: yokawasa/action-setup-kube-tools@v0.10.0
uses: yokawasa/action-setup-kube-tools@v0.11.0
with:
setup-tools: |
helmv3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/charts-release-oci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
fetch-depth: 0

- name: Install Kubernetes tools
uses: yokawasa/action-setup-kube-tools@v0.10.0
uses: yokawasa/action-setup-kube-tools@v0.11.0
with:
setup-tools: |
helmv3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/charts-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
ref: ${{ inputs.checkoutCommit }}

- name: Install Kubernetes tools
uses: yokawasa/action-setup-kube-tools@v0.10.0
uses: yokawasa/action-setup-kube-tools@v0.11.0
with:
setup-tools: |
helmv3
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
ref: ${{ inputs.checkoutCommit }}

- name: Install Kubernetes tools
uses: yokawasa/action-setup-kube-tools@v0.10.0
uses: yokawasa/action-setup-kube-tools@v0.11.0
with:
setup-tools: |
helmv3
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 @@ -15,13 +15,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Generate Token
uses: actions/[email protected].0
uses: actions/[email protected].1
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@31b3f3ccdc584546fc445612dec3f38ff5edb41c # v0.5.0
- uses: actions/add-to-project@0609a2702eefb44781da00f8e04901d6e5cd2b92 # v0.6.0
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/[email protected].0
uses: actions/[email protected].1
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/[email protected].0
uses: actions/[email protected].1
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/[email protected].1
uses: renovatebot/[email protected].2
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/[email protected].0
uses: actions/[email protected].1
id: app-token
with:
app-id: "${{ secrets.APP_ID }}"
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.helm:
image:
name: alpine/helm:latest@sha256:b8b29460fecb0e64c0adbab2f506382056f1a9105e771595bc6871ad859b65a5
name: alpine/helm:latest@sha256:d5c9eb012f56aa79360f3c88a51356bca842b989594f714ea9595f2250a18186
entrypoint: [""]
variables:
CHART_NAME: bloopyboi
Expand Down
1 change: 1 addition & 0 deletions .task/checksum/schemas-ent
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7a84e7b94ef638a7872f95af2c6744d9
2 changes: 1 addition & 1 deletion .task/checksum/schemas-proto
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e037fb995fe0efe88a7c8c1862eb3a64
5e02ea3dfd6b9c111ff93e1f51888f99
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RUN go mod download
RUN go build -ldflags="-w -s" .
RUN echo $(ls .)

FROM gcr.io/distroless/static@sha256:a43abc840a7168c833a8b3e4eae0f715f7532111c9227ba17f49586a63a73848
FROM gcr.io/distroless/static@sha256:072d78bc452a2998929a9579464e55067db4bf6d2c5f9cde582e33c10a415bd1

COPY --from=build /build/bloopyboi /

Expand Down
4 changes: 3 additions & 1 deletion bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func (bot *BloopyBoi) Run(ctx context.Context) error {

func (bot *BloopyBoi) initializeDiscord(ctx context.Context) error {

discordClient, err := discord.NewDiscordManager(bot.log.With(zapcore.Field{
discordConfig := config.GetConfig().DiscordConfig

discordClient, err := discord.NewDiscordManager(discordConfig, bot.log.With(zapcore.Field{
Key: botLogFieldKey,
Type: zapcore.StringType,
String: "Discord",
Expand Down
20 changes: 18 additions & 2 deletions bot/discord/commands/user_mentions.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package commands

import (
"github.com/bwmarrin/discordgo"
"fmt"
)
"math/rand"
"strings"

"github.com/bwmarrin/discordgo"
)

// Listens for messages specifically addressing bot
func DirectedMessageReceive(s *discordgo.Session, m *discordgo.MessageCreate) {
Expand All @@ -19,13 +21,27 @@ func DirectedMessageReceive(s *discordgo.Session, m *discordgo.MessageCreate) {
botMentioned := false
// Filter only commands we care about
if len(m.Mentions) > 0 {
// Just react to some mentions mysteriously
if rand.Float32()<0.5 {
err := s.MessageReactionAdd(m.ChannelID, m.ID, "👁‍🗨")
if err != nil {
logger.Warn(fmt.Sprintf("Error adding reaction to message %s from user %s", m.ID, m.Author.Username))
}
}
for _, user := range m.Mentions {
if user.ID == s.State.User.ID {
botMentioned = true
break
}
}
}
if strings.Contains(strings.ToLower(m.Content), "bloopyboi") {
logger.Sugar().Debug("Detected BloopyBoi in message from ", m.Author.Username)
err := s.MessageReactionAdd(m.ChannelID, m.ID, "👀")
if err != nil {
logger.Sugar().Warn(err)
}
}

if !directMessage && botMentioned {
logger.Sugar().Debug(fmt.Sprintf("Detected Channel Mention in message from %s with UserID %s and Content: ", m.Author.Username, m.Author.ID), m.Content)
Expand Down
26 changes: 15 additions & 11 deletions bot/discord/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/bwmarrin/discordgo"
bloopyCommands "github.com/h3mmy/bloopyboi/bot/discord/commands"
"github.com/h3mmy/bloopyboi/bot/handlers"
"github.com/h3mmy/bloopyboi/bot/internal/config"
"github.com/h3mmy/bloopyboi/bot/internal/models"
"github.com/h3mmy/bloopyboi/bot/providers"
"github.com/h3mmy/bloopyboi/bot/services"
Expand All @@ -28,31 +29,31 @@ const (
type DiscordManager struct {
botMentionRegex *regexp.Regexp
log *zap.Logger
botId string
botId int64
discordSvc *services.DiscordService
discordCfg *config.DiscordConfig
}

// Constructs new Discord Manager
func NewDiscordManager(logger *zap.Logger) (*DiscordManager, error) {
// Get token
token := providers.GetBotToken()
botID := providers.GetBotName()
func NewDiscordManager(cfg *config.DiscordConfig,logger *zap.Logger) (*DiscordManager, error) {
botID := cfg.GetAppID()

botMentionRegex, err := regexp.Compile(fmt.Sprintf(discordBotMentionRegexFmt, botID))
botMentionRegex, err := regexp.Compile(fmt.Sprintf(discordBotMentionRegexFmt, fmt.Sprintf("%d",botID)))
if err != nil {
return nil, fmt.Errorf("while compiling bot mention regex: %w", err)
}

// Create a new Discord session using the provided bot token.
s, err := providers.NewDiscordServiceWithToken(token)
s, err := providers.NewDiscordServiceWithConfig(cfg)
if err != nil {
return nil, fmt.Errorf("Error Creating Discord Session: %w", err)
return nil, fmt.Errorf("Error Creating Discord Service: %w", err)
}
return &DiscordManager{
botId: botID,
discordSvc: s,
log: logger,
botMentionRegex: botMentionRegex,
discordCfg: cfg,
}, nil
}

Expand All @@ -63,9 +64,11 @@ func (d *DiscordManager) Start(ctx context.Context) error {
d.discordSvc.AddHandler(bloopyCommands.DirectMessageCreate)
d.discordSvc.AddHandler(bloopyCommands.DirectedMessageReceive)

d.log.Debug("Using config", zap.Any("config", d.discordCfg))

d.log.Debug("Registered some Handlers... and the proxy")

d.discordSvc.GetSession().Identify.Intents = discordgo.IntentsGuildMessages | discordgo.IntentsDirectMessages | discordgo.IntentDirectMessageReactions | discordgo.IntentGuildMessageReactions | discordgo.IntentGuildEmojis
d.discordSvc.SetIntents(discordgo.IntentsGuildMessages | discordgo.IntentsDirectMessages | discordgo.IntentDirectMessageReactions | discordgo.IntentGuildMessageReactions | discordgo.IntentGuildEmojis)
// Open a websocket connection to Discord and begin listening.
d.log.Info("Opening Websocket Connection")
err := d.discordSvc.GetSession().Open()
Expand All @@ -74,15 +77,16 @@ func (d *DiscordManager) Start(ctx context.Context) error {
}

d.log.Info("Registering App Commands")
for _, v := range providers.GetDiscordAppCommands() {
for _, v := range providers.GetDiscordAppCommands(d.discordCfg.GuildConfigs) {
d.log.Debug("Registering command", zap.Any("command", v.GetAppCommand()))
_, err := d.discordSvc.RegisterAppCommand(v)
if err != nil {
d.log.Sugar().Panicf("Cannot create '%v' command: %v", v.GetAppCommand().Name, err)
}
if v.GetMessageComponentHandlers() != nil {
err = d.discordSvc.RegisterMessageComponentHandlers(v.GetMessageComponentHandlers())
if err != nil {
d.log.Error("wasnt expecting this to be possible", zap.Error(err))
d.log.Error("wasn't expecting this to be possible", zap.Error(err))
}
}
}
Expand Down
45 changes: 43 additions & 2 deletions bot/gateway.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,69 @@
package bot

import (
"context"

"github.com/h3mmy/bloopyboi/bot/internal/models"
"github.com/h3mmy/bloopyboi/bot/servers"
pmodels "github.com/h3mmy/bloopyboi/internal/models"
"github.com/labstack/echo/v4"
"github.com/uptrace/opentelemetry-go-extra/otelzap"
"go.uber.org/zap"
)

var defaultGatewayConfig = &pmodels.GatewayConfig{
HttpPort: 8080,
GrpcPort: 8081,
}

type AppInfoServer struct {
servers.UnimplementedInfoServiceServer
}

type Gateway struct {
logger *otelzap.Logger
meta models.BloopyMeta
echoServ *echo.Echo
config *pmodels.GatewayConfig
}

func NewGateway() *Gateway {
func NewGateway(cfg *pmodels.GatewayConfig) *Gateway {
echoServ := echo.New()
lgr := otelzap.New(zap.L())
return &Gateway{
meta: models.NewBloopyMeta(),
echoServ: echoServ,
config: cfg,
logger: lgr,
}
}

func NewDefaultGateway() *Gateway {
return NewGateway(defaultGatewayConfig)
}

func (g *Gateway) Start() error {
return nil
g.echoServ.GET("/info", GetAppInfo)

return g.echoServ.Start(":8080")
}

func (g *Gateway) Shutdown(ctx context.Context) error {
return g.echoServ.Shutdown(ctx)
}

func GetAppInfo(c echo.Context) error {
return c.JSON(200, "Hello World")
}

// func (g *Gateway) startGRPC() error {
// lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", g.config.GrpcPort))
// if err != nil {
// g.logger.Error("failed to listen", zap.Error(err))
// return err
// }

// gserv := grpc.NewServer()
// servers.RegisterInfoServiceServer(gserv, &AppInfoServer{})
// return gserv.Serve(lis)
// }
24 changes: 24 additions & 0 deletions bot/handlers/blissfest.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type BlissfestCommand struct {
Description string
logger *zap.Logger
blissSvc *services.BlissfestService
// GuildID for which this command will be active
// For global commands, set to ""
guildId string
roles []int64
}

func NewBlissfestCommand(svc *services.BlissfestService) *BlissfestCommand {
Expand All @@ -27,9 +31,25 @@ func NewBlissfestCommand(svc *services.BlissfestService) *BlissfestCommand {
Description: "Gets blissfest related information",
logger: log.NewZapLogger().Named("blissfest_command"),
blissSvc: svc,
guildId: "",
roles: []int64{},
}
}

func (p *BlissfestCommand) WithGuild(guildId string) *BlissfestCommand {
p.guildId = guildId
return p
}

func (p *BlissfestCommand) WithRoles(roles ...int64) *BlissfestCommand {
p.roles = roles
return p
}

func (p *BlissfestCommand) GetAllowedRoles() []int64 {
return p.roles
}

func (p *BlissfestCommand) GetAppCommand() *discordgo.ApplicationCommand {
return &discordgo.ApplicationCommand{
Name: strings.ToLower(p.Name),
Expand Down Expand Up @@ -95,3 +115,7 @@ func (p *BlissfestCommand) GetAppCommandHandler() func(s *discordgo.Session, i *
func (p *BlissfestCommand) GetMessageComponentHandlers() map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate) {
return nil
}

func (p *BlissfestCommand) GetGuildID() string {
return p.guildId
}
Loading

0 comments on commit 713d481

Please sign in to comment.