diff --git a/commands/settings.go b/commands/settings.go index 36c3b08..a27738d 100644 --- a/commands/settings.go +++ b/commands/settings.go @@ -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 { @@ -251,13 +250,15 @@ 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 { @@ -265,13 +266,15 @@ func set(b *bot.Bot) func(*gumi.Ctx) error { } 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 { @@ -279,6 +282,7 @@ func set(b *bot.Bot) func(*gumi.Ctx) error { } guild.Pixiv = applySetting(guild.Pixiv, enable).(bool) + case "bluesky": enable, err := parseBool(newSetting.Raw) if err != nil { @@ -286,6 +290,7 @@ func set(b *bot.Bot) func(*gumi.Ctx) error { } guild.Bluesky = applySetting(guild.Bluesky, enable).(bool) + case "twitter": enable, err := parseBool(newSetting.Raw) if err != nil { @@ -293,6 +298,7 @@ func set(b *bot.Bot) func(*gumi.Ctx) error { } guild.Twitter = applySetting(guild.Twitter, enable).(bool) + case "deviant": enable, err := parseBool(newSetting.Raw) if err != nil { @@ -300,6 +306,7 @@ func set(b *bot.Bot) func(*gumi.Ctx) error { } guild.Deviant = applySetting(guild.Deviant, enable).(bool) + case "tags": enable, err := parseBool(newSetting.Raw) if err != nil { @@ -307,6 +314,7 @@ func set(b *bot.Bot) func(*gumi.Ctx) error { } guild.Tags = applySetting(guild.Tags, enable).(bool) + case "footer": enable, err := parseBool(newSetting.Raw) if err != nil { @@ -314,6 +322,7 @@ func set(b *bot.Bot) func(*gumi.Ctx) error { } guild.FlavorText = applySetting(guild.FlavorText, enable).(bool) + case "twitter.skip": enable, err := parseBool(newSetting.Raw) if err != nil { @@ -321,6 +330,7 @@ func set(b *bot.Bot) func(*gumi.Ctx) error { } guild.SkipFirst = applySetting(guild.SkipFirst, enable).(bool) + default: return messages.ErrUnknownSetting(settingName.Raw) } diff --git a/repost/redis.go b/repost/redis.go index ff2f711..24e161d 100644 --- a/repost/redis.go +++ b/repost/redis.go @@ -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 } @@ -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, @@ -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 } @@ -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 }