Skip to content

Commit

Permalink
fix: reactions and nsfw settings don't work
Browse files Browse the repository at this point in the history
  • Loading branch information
VTGare committed Nov 18, 2024
1 parent 094d8d5 commit 620f321
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
16 changes: 13 additions & 3 deletions commands/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ func set(b *bot.Bot) func(*gumi.Ctx) error {

guild.Repost = store.GuildRepost(applySetting(guild.Repost, newSetting.Raw).(string))

// guild.Repost = store.GuildRepost(newSetting.Raw)
case "repost.expiration":
dur, err := time.ParseDuration(newSetting.Raw)
if err != nil {
Expand All @@ -251,76 +250,87 @@ func set(b *bot.Bot) func(*gumi.Ctx) error {
}

guild.RepostExpiration = applySetting(guild.RepostExpiration, dur).(time.Duration)

case "nsfw":
enable, err := parseBool(newSetting.Raw)
if err != nil {
return err
}

applySetting(guild.NSFW, enable)
guild.NSFW = applySetting(guild.NSFW, enable).(bool)

case "crosspost":
enable, err := parseBool(newSetting.Raw)
if err != nil {
return err
}

guild.Crosspost = applySetting(guild.Crosspost, enable).(bool)

case "reactions":
enable, err := parseBool(newSetting.Raw)
if err != nil {
return err
}

applySetting(guild.Reactions, enable)
guild.Reactions = applySetting(guild.Reactions, enable).(bool)

case "pixiv":
enable, err := parseBool(newSetting.Raw)
if err != nil {
return err
}

guild.Pixiv = applySetting(guild.Pixiv, enable).(bool)

case "bluesky":
enable, err := parseBool(newSetting.Raw)
if err != nil {
return err
}

guild.Bluesky = applySetting(guild.Bluesky, enable).(bool)

case "twitter":
enable, err := parseBool(newSetting.Raw)
if err != nil {
return err
}

guild.Twitter = applySetting(guild.Twitter, enable).(bool)

case "deviant":
enable, err := parseBool(newSetting.Raw)
if err != nil {
return err
}

guild.Deviant = applySetting(guild.Deviant, enable).(bool)

case "tags":
enable, err := parseBool(newSetting.Raw)
if err != nil {
return err
}

guild.Tags = applySetting(guild.Tags, enable).(bool)

case "footer":
enable, err := parseBool(newSetting.Raw)
if err != nil {
return err
}

guild.FlavorText = applySetting(guild.FlavorText, enable).(bool)

case "twitter.skip":
enable, err := parseBool(newSetting.Raw)
if err != nil {
return err
}

guild.SkipFirst = applySetting(guild.SkipFirst, enable).(bool)

default:
return messages.ErrUnknownSetting(settingName.Raw)
}
Expand Down
17 changes: 5 additions & 12 deletions repost/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func (rd redisDetector) Find(ctx context.Context, channelID, artworkID string) (
}

_, err := rd.client.Pipelined(ctx, func(pipe redis.Pipeliner) error {
err := rd.client.HGetAll(ctx, key).Scan(&rep)
err := pipe.HGetAll(ctx, key).Scan(&rep)
if err != nil {
return err
}

ttl, err = rd.client.TTL(ctx, key).Result()
ttl, err = pipe.TTL(ctx, key).Result()
if err != nil {
return err
}
Expand All @@ -74,7 +74,7 @@ func (rd redisDetector) Find(ctx context.Context, channelID, artworkID string) (
func (rd redisDetector) Create(ctx context.Context, repost *Repost, duration time.Duration) error {
key := fmt.Sprintf("channel:%v:artwork:%v", repost.ChannelID, repost.ID)
_, err := rd.client.Pipelined(ctx, func(pipe redis.Pipeliner) error {
if _, err := rd.client.HSet(ctx, key, map[string]any{
if _, err := pipe.HSet(ctx, key, map[string]any{
"id": repost.ID,
"url": repost.URL,
"guild_id": repost.GuildID,
Expand All @@ -84,7 +84,7 @@ func (rd redisDetector) Create(ctx context.Context, repost *Repost, duration tim
return err
}

if _, err := rd.client.ExpireAt(ctx, key, time.Now().Add(duration)).Result(); err != nil {
if _, err := pipe.ExpireAt(ctx, key, time.Now().Add(duration)).Result(); err != nil {
return err
}

Expand All @@ -104,14 +104,7 @@ func (rd redisDetector) Delete(ctx context.Context, channelID, artworkID string)
return err
}

_, err := rd.client.Pipelined(ctx, func(pipe redis.Pipeliner) error {
if _, err := rd.client.Del(ctx, key).Result(); err != nil {
return err
}

return nil
})
if err != nil {
if _, err := rd.client.Del(ctx, key).Result(); err != nil {
return err
}

Expand Down

0 comments on commit 620f321

Please sign in to comment.