Documentation ¶
Overview ¶
Package redis implements a type-safe redis database client.
Index ¶
- type DB
- func (db *DB) AutoreplyAllowed(ctx context.Context, channel string, id int64, expiry time.Duration) (bool, error)
- func (db *DB) CheckAndMarkCooldown(ctx context.Context, channel, key string, expiry time.Duration) (bool, error)
- func (db *DB) Confirm(ctx context.Context, channel, user, key string, expiry time.Duration) (bool, error)
- func (db *DB) DedupeCheck(ctx context.Context, id string, expiry time.Duration) (bool, error)
- func (db *DB) DedupeCheckAndMark(ctx context.Context, id string, expiry time.Duration) (bool, error)
- func (db *DB) DedupeMark(ctx context.Context, id string, expiry time.Duration) error
- func (db *DB) FilterWarned(ctx context.Context, channel, user, filter string, expiry time.Duration) (bool, error)
- func (db *DB) GetActionUsageStats(ctx context.Context) (map[string]string, error)
- func (db *DB) GetAuthState(ctx context.Context, key string, v any) (bool, error)
- func (db *DB) GetBuiltinUsageStats(ctx context.Context) (map[string]string, error)
- func (db *DB) GetUserState(ctx context.Context, botName, ircChannel string) (bool, error)
- func (db *DB) HasLinkPermit(ctx context.Context, channel, user string) (bool, error)
- func (db *DB) IncrementActionUsageStat(ctx context.Context, name string) error
- func (db *DB) IncrementBuiltinUsageStat(ctx context.Context, name string) error
- func (db *DB) LinkPermit(ctx context.Context, channel, user string, expiry time.Duration) error
- func (db *DB) MarkCooldown(ctx context.Context, channel, key string, expiry time.Duration) error
- func (db *DB) RaffleAdd(ctx context.Context, channel, user string) error
- func (db *DB) RaffleCount(ctx context.Context, channel string) (int64, error)
- func (db *DB) RaffleReset(ctx context.Context, channel string) error
- func (db *DB) RaffleWinner(ctx context.Context, channel string) (string, bool, error)
- func (db *DB) RaffleWinners(ctx context.Context, channel string, n int64) ([]string, error)
- func (db *DB) RepeatAllowed(ctx context.Context, channel string, id int64, expiry time.Duration) (bool, error)
- func (db *DB) ScheduledAllowed(ctx context.Context, channel string, id int64, expiry time.Duration) (bool, error)
- func (db *DB) SendMessageAllowed(ctx context.Context, botName, target string, limitSlow, limitFast int, ...) (bool, error)
- func (db *DB) SetAuthState(ctx context.Context, key string, value any, expiry time.Duration) error
- func (db *DB) SetUserState(ctx context.Context, botName, ircChannel string, fast bool, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a redis client wrapper, consolidating the common schema in one place.
func New ¶
func New(client *redis.Client) *DB
New creates a new redis client DB wrapper. The user is expected to close the client itself; DB is just a wrapper and does not manage the connection.
func (*DB) AutoreplyAllowed ¶
func (db *DB) AutoreplyAllowed(ctx context.Context, channel string, id int64, expiry time.Duration) (bool, error)
AutoreplyAllowed returns true if a certain autoreply is allowed to run, preventing future runs of this ID from running until expiring.
func (*DB) CheckAndMarkCooldown ¶
func (db *DB) CheckAndMarkCooldown(ctx context.Context, channel, key string, expiry time.Duration) (bool, error)
CheckAndMarkCooldown checks that a command is on cooldown, and marks it.
func (*DB) Confirm ¶
func (db *DB) Confirm(ctx context.Context, channel, user, key string, expiry time.Duration) (bool, error)
Confirm checks that a user has confirmed something (keyed on "key").
func (*DB) DedupeCheck ¶
DedupeCheck checks if an ID has been seen, and if seen refreshes its expiry.
func (*DB) DedupeCheckAndMark ¶
func (db *DB) DedupeCheckAndMark(ctx context.Context, id string, expiry time.Duration) (bool, error)
DedupeCheckAndMark checks if an ID has been seen, and if it not, marks it as seen.
func (*DB) DedupeMark ¶
DedupeMark marks a given ID as seen.
func (*DB) FilterWarned ¶
func (db *DB) FilterWarned(ctx context.Context, channel, user, filter string, expiry time.Duration) (bool, error)
FilterWarned chceks if a user has already been warned for a given filter.
func (*DB) GetActionUsageStats ¶
GetActionUsageStats gets all usage statistics.
func (*DB) GetAuthState ¶
GetAuthState gets the arbitrary authentication state for the login workflow.
func (*DB) GetBuiltinUsageStats ¶
GetBuiltinUsageStats gets all usage statistics.
func (*DB) GetUserState ¶
GetUserState returns the current user state of the bot in the given IRC channel.
func (*DB) HasLinkPermit ¶
HasLinkPermit returns true if a user has a link permit, invalidating the permit.
func (*DB) IncrementActionUsageStat ¶
IncrementActionUsageStat increments a usage statistic by one.
func (*DB) IncrementBuiltinUsageStat ¶
IncrementBuiltinUsageStat increments a usage statistic by one.
func (*DB) LinkPermit ¶
LinkPermit checks marks a user as having a single link permit.
func (*DB) MarkCooldown ¶
MarkCooldown marks that a command is on cooldown.
func (*DB) RaffleAdd ¶
RaffleAdd adds a user to the current raffle. Duplicate entries are not allowed.
func (*DB) RaffleCount ¶
RaffleCount returns the number of entries in the current raffle.
func (*DB) RaffleReset ¶
RaffleReset removes all entires from the current raffle.
func (*DB) RaffleWinner ¶
RaffleWinner removes a user from the raffle entries and returns them.
func (*DB) RaffleWinners ¶
RaffleWinners removes N users from the raffle entries and returns them.
func (*DB) RepeatAllowed ¶
func (db *DB) RepeatAllowed(ctx context.Context, channel string, id int64, expiry time.Duration) (bool, error)
RepeatAllowed returns true if a certain repeat is allowed to run, preventing future repeats of this ID from running until expiring.
func (*DB) ScheduledAllowed ¶
func (db *DB) ScheduledAllowed(ctx context.Context, channel string, id int64, expiry time.Duration) (bool, error)
ScheduledAllowed returns true if a certain schedule is allowed to run, preventing future schedules of this ID from running until expiring.
func (*DB) SendMessageAllowed ¶
func (db *DB) SendMessageAllowed(ctx context.Context, botName, target string, limitSlow, limitFast int, window time.Duration) (bool, error)
SendMessageAllowed limits the rate of sent message, based on the user state of the bot in the targeted IRC channel.
func (*DB) SetAuthState ¶
SetAuthState sets an arbitrary authentication state for the login workflow.