Skip to content

Commit

Permalink
feat: add admin action for eventsub subscribe (#733)
Browse files Browse the repository at this point in the history
* feat: add admin action for eventsub subscribe

* wires

* kruto

* kruto

* kruto

* kruto

* kruto

* kruto

* kruto

* kruto

* kruto

* kruto

* kruto

* kruto

* kruto

* kruto

* kruto

---------

Co-authored-by: Vitalij Ryndin <crashmax.dev@gmail.com>
  • Loading branch information
Satont and crashmax-dev authored May 31, 2024
1 parent 051842e commit 1a3590b
Show file tree
Hide file tree
Showing 121 changed files with 1,264 additions and 1,198 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ indent_style = tab
indent_size = 2
max_line_length = 100

[*.{yaml,yml}]
[*.{yaml,yml,json}]
indent_style = space
ident_size = 2
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SEVENTV_TOKEN=

CDN_PUBLIC_URL=http://localhost:8000
CDN_HOST=localhost:8000
CDN_BUCKET=
CDN_BUCKET=twir
CDN_REGION=
CDN_ACCESS_TOKEN=
CDN_SECRET_TOKEN=
Expand Down
63 changes: 63 additions & 0 deletions apps/api-gql/internal/gql/resolvers/admin-actions.resolver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package resolvers

import (
"fmt"

model "github.com/satont/twir/libs/gomodels"
"github.com/twirapp/twir/apps/api-gql/internal/gql/gqlmodel"
)

func (r *mutationResolver) eventSubGqlToCondition(
input gqlmodel.EventsubSubscribeConditionInput,
) (model.EventsubConditionType, error) {
switch input {
case gqlmodel.EventsubSubscribeConditionInputChannel:
return model.EventsubConditionTypeBroadcasterUserID, nil
case gqlmodel.EventsubSubscribeConditionInputUser:
return model.EventsubConditionTypeUserID, nil
case gqlmodel.EventsubSubscribeConditionInputChannelWithModeratorID:
return model.EventsubConditionTypeBroadcasterWithModeratorID, nil
case gqlmodel.EventsubSubscribeConditionInputChannelWithBotID:
return model.EventsubConditionTypeBroadcasterWithUserID, nil
default:
return "", fmt.Errorf("unknown input type")
}
}
32 changes: 6 additions & 26 deletions apps/api-gql/internal/gql/resolvers/notifications.resolver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions apps/api-gql/schema/admin-actions.graphqls
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
extend type Mutation {
dropAllAuthSessions: Boolean! @isAuthenticated @isAdmin
eventsubSubscribe(opts: EventsubSubscribeInput!): Boolean! @isAuthenticated @isAdmin
}

input EventsubSubscribeInput {
type: String! @validate(constraint: "max=50")
version: String! @validate(constraint: "max=50")
condition: EventsubSubscribeConditionInput!
}

enum EventsubSubscribeConditionInput {
CHANNEL
USER
CHANNEL_WITH_MODERATOR_ID
CHANNEL_WITH_BOT_ID
}
58 changes: 2 additions & 56 deletions apps/api/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"log/slog"
"net/http"
"time"

"github.com/alexedwards/scs/v2"
"github.com/redis/go-redis/v9"
Expand All @@ -21,7 +20,7 @@ import (
"github.com/satont/twir/apps/api/internal/webhooks"
cfg "github.com/satont/twir/libs/config"
"github.com/satont/twir/libs/logger"
internalSentry "github.com/satont/twir/libs/sentry"
"github.com/twirapp/twir/libs/baseapp"
buscore "github.com/twirapp/twir/libs/bus-core"
"github.com/twirapp/twir/libs/grpc/clients"
"github.com/twirapp/twir/libs/grpc/discord"
Expand All @@ -32,26 +31,11 @@ import (
"github.com/twirapp/twir/libs/grpc/websockets"
"github.com/twirapp/twir/libs/uptrace"
"go.uber.org/fx"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)

var App = fx.Options(
baseapp.CreateBaseApp("api"),
fx.Provide(
func() cfg.Config {
config, err := cfg.New()
if err != nil {
panic(err)
}
return *config
},
internalSentry.NewFx(
internalSentry.NewFxOpts{
Service: "api",
},
),
logger.NewFx(logger.Opts{Service: "api"}),
uptrace.NewFx("api"),
func(c cfg.Config) tokens.TokensClient {
return clients.NewTokens(c.AppEnv)
},
Expand All @@ -70,47 +54,9 @@ var App = fx.Options(
func(c cfg.Config) discord.DiscordClient {
return clients.NewDiscord(c.AppEnv)
},
func(config cfg.Config, lc fx.Lifecycle) (*redis.Client, error) {
redisOpts, err := redis.ParseURL(config.RedisUrl)
if err != nil {
return nil, err
}
client := redis.NewClient(redisOpts)
lc.Append(
fx.Hook{
OnStop: func(ctx context.Context) error {
return client.Close()
},
},
)

return client, nil
},
func(r *redis.Client) *scs.SessionManager {
return sessions.New(r)
},
func(config cfg.Config, lc fx.Lifecycle) (*gorm.DB, error) {
db, err := gorm.Open(
postgres.Open(config.DatabaseUrl),
)
if err != nil {
return nil, err
}
d, _ := db.DB()
d.SetMaxIdleConns(1)
d.SetMaxOpenConns(10)
d.SetConnMaxLifetime(time.Hour)

lc.Append(
fx.Hook{
OnStop: func(_ context.Context) error {
return d.Close()
},
},
)

return db, nil
},
buscore.NewNatsBusFx("api"),
interceptors.New,
impl_protected.New,
Expand Down
21 changes: 2 additions & 19 deletions apps/discord/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,31 @@ package app

import (
"github.com/satont/twir/apps/discord/internal/discord_go"
"github.com/satont/twir/apps/discord/internal/gorm"
"github.com/satont/twir/apps/discord/internal/grpc"
"github.com/satont/twir/apps/discord/internal/messages_updater"
"github.com/satont/twir/apps/discord/internal/redis"
"github.com/satont/twir/apps/discord/internal/sended_messages_store"
cfg "github.com/satont/twir/libs/config"
"github.com/satont/twir/libs/logger"
twirsentry "github.com/satont/twir/libs/sentry"
"github.com/twirapp/twir/libs/baseapp"
buscore "github.com/twirapp/twir/libs/bus-core"
"github.com/twirapp/twir/libs/grpc/clients"
"github.com/twirapp/twir/libs/grpc/tokens"
"github.com/twirapp/twir/libs/uptrace"
"go.uber.org/fx"
)

var App = fx.Module(
"discord",
baseapp.CreateBaseApp("discord"),
fx.Provide(
cfg.NewFx,
gorm.New,
redis.New,
buscore.NewNatsBusFx("discord"),
sended_messages_store.New,
messages_updater.New,
discord_go.New,
twirsentry.NewFx(twirsentry.NewFxOpts{Service: "discord"}),
uptrace.NewFx("discord"),
logger.NewFx(
logger.Opts{
Service: "discord",
},
),
func(config cfg.Config) tokens.TokensClient {
return clients.NewTokens(config.AppEnv)
},
grpc.New,
),
fx.Invoke(
uptrace.NewFx("discord"),
redis.New,
gorm.New,
// discord_go.New,
messages_updater.New,
grpc.New,
),
Expand Down
41 changes: 0 additions & 41 deletions apps/discord/internal/gorm/gorm.go

This file was deleted.

Loading

0 comments on commit 1a3590b

Please sign in to comment.