redis

package
v0.0.0-...-fb49ba0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package redis implements a type-safe redis database client.

Index

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

func (db *DB) DedupeCheck(ctx context.Context, id string, expiry time.Duration) (bool, error)

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

func (db *DB) DedupeMark(ctx context.Context, id string, expiry time.Duration) error

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

func (db *DB) GetActionUsageStats(ctx context.Context) (map[string]string, error)

GetActionUsageStats gets all usage statistics.

func (*DB) GetAuthState

func (db *DB) GetAuthState(ctx context.Context, key string, v any) (bool, error)

GetAuthState gets the arbitrary authentication state for the login workflow.

func (*DB) GetBuiltinUsageStats

func (db *DB) GetBuiltinUsageStats(ctx context.Context) (map[string]string, error)

GetBuiltinUsageStats gets all usage statistics.

func (*DB) GetUserState

func (db *DB) GetUserState(ctx context.Context, botName, ircChannel string) (bool, error)

GetUserState returns the current user state of the bot in the given IRC channel.

func (*DB) HasLinkPermit

func (db *DB) HasLinkPermit(ctx context.Context, channel, user string) (bool, error)

HasLinkPermit returns true if a user has a link permit, invalidating the permit.

func (*DB) IncrementActionUsageStat

func (db *DB) IncrementActionUsageStat(ctx context.Context, name string) error

IncrementActionUsageStat increments a usage statistic by one.

func (*DB) IncrementBuiltinUsageStat

func (db *DB) IncrementBuiltinUsageStat(ctx context.Context, name string) error

IncrementBuiltinUsageStat increments a usage statistic by one.

func (*DB) LinkPermit

func (db *DB) LinkPermit(ctx context.Context, channel, user string, expiry time.Duration) error

LinkPermit checks marks a user as having a single link permit.

func (*DB) MarkCooldown

func (db *DB) MarkCooldown(ctx context.Context, channel, key string, expiry time.Duration) error

MarkCooldown marks that a command is on cooldown.

func (*DB) RaffleAdd

func (db *DB) RaffleAdd(ctx context.Context, channel, user string) error

RaffleAdd adds a user to the current raffle. Duplicate entries are not allowed.

func (*DB) RaffleCount

func (db *DB) RaffleCount(ctx context.Context, channel string) (int64, error)

RaffleCount returns the number of entries in the current raffle.

func (*DB) RaffleReset

func (db *DB) RaffleReset(ctx context.Context, channel string) error

RaffleReset removes all entires from the current raffle.

func (*DB) RaffleWinner

func (db *DB) RaffleWinner(ctx context.Context, channel string) (string, bool, error)

RaffleWinner removes a user from the raffle entries and returns them.

func (*DB) RaffleWinners

func (db *DB) RaffleWinners(ctx context.Context, channel string, n int64) ([]string, error)

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

func (db *DB) SetAuthState(ctx context.Context, key string, value any, expiry time.Duration) error

SetAuthState sets an arbitrary authentication state for the login workflow.

func (*DB) SetUserState

func (db *DB) SetUserState(ctx context.Context, botName, ircChannel string, fast bool, expiry time.Duration) error

SetUserState sets the current bot user state as either fast or slow for a given IRC channel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL