diff --git a/internal/command/joke.go b/internal/command/joke.go index 7eff07e..8b1680a 100644 --- a/internal/command/joke.go +++ b/internal/command/joke.go @@ -54,7 +54,9 @@ var ( ) func executeAddJokeCommand(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) { - var j mongo.JokeDB + j := mongo.JokeDB{ + GuildID: i.GuildID, + } for _, o := range i.Data.(discordgo.ApplicationCommandInteractionData).Options { switch o.Name { diff --git a/internal/interaction/joke.go b/internal/interaction/joke.go index 76c2203..736bf01 100644 --- a/internal/interaction/joke.go +++ b/internal/interaction/joke.go @@ -29,6 +29,8 @@ var ( func SendJoke(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate, t types.JokeType, c types.JokeCategory) { var msg *discordgo.InteractionResponseData + ctx = context.WithValue(ctx, "GUILD_ID", i.GuildID) + switch t { case types.Single: j, err := getSingleTypeJokeGenerator()(ctx, c) diff --git a/internal/mongo/joke.go b/internal/mongo/joke.go index 4821792..3d35403 100644 --- a/internal/mongo/joke.go +++ b/internal/mongo/joke.go @@ -17,6 +17,7 @@ type JokeDB struct { ContentRes string `bson:"content"` Type types.JokeType `bson:"type"` Category types.JokeCategory `bson:"category"` + GuildID string `bson:"guild_id"` ExternalID int64 `bson:"externalID"` } @@ -83,9 +84,18 @@ func findRandomJoke(ctx context.Context, j JokeSearch) (JokeDB, error) { }}, }}, {{ - "$match", bson.D{{ - "type", jokeType, - }}, + "$match", bson.D{ + { + "type", jokeType, + }, { + "$or", []bson.D{ + {{ + "guild_id", "", + }}, + {{ + "guild_id", ctx.Value("GUILD_ID"), + }}}, + }}, }}, }