factoids

package
v0.0.0-...-efa4d4d Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package factoids implemets a simple factoid get/set system for the bot

Index

Constants

View Source
const (
	DefaultConfFile = "conf/factoids.yml"
	DefaultDBPath   = "db/factoids.yml"
)

Variables

View Source
var ErrAmbiguousKey = errors.New("ambiguous key")
View Source
var ErrFactAlreadyExists = errors.New("fact already exists")
View Source
var ErrInvalidUTF8 = errors.New("invalid UTF-8")
View Source
var ErrNoSuchFact = errors.New("factoid not found")

Functions

func Delete

func Delete(key, substr string) error

Delete removes a value from a key matching substring `substr`. If more than one match, return error

func Lastfact

func Lastfact() fullfactoid

func List

func List(start string) (string, error)

func Lookup

func Lookup(ctx context.Context, nick, msg string) (string, bool)

Lookup returns a string to output to the channel, and a bool indicating if it's an action ('/me blabla'). Nick is the nickname of the asker.

func NewReplyString

func NewReplyString(ctx *context.Context, msg string) string

NewReplyString adds a custom reply string to the list of reply strings TODO: generalize config file read/write/parse TODO: switch to toml for config

func RandomKey

func RandomKey() string

func SaveToFile

func SaveToFile(filename string, c Config) error
func Search(rex string, maxresults int) ([]string, error)

Search will look through the entire database, both keywords and facts, for the regular expression in rex. It will return a formatted string to output toi a channel, and an error if something went wrong. It is not an error that nothing was found

func Store

func Store(msg string, from string) string

Store saves a factoid to the database

Types

type Config

type Config struct {
	DatabaseFile string              `yaml:"database"`
	ReplyStrings helpers.StringSlice `yaml:"replystrings"`
}

func FromContext

func FromContext(ctx context.Context) Config

func ParseConfFile

func ParseConfFile(filename string) (Config, error)

ParseConfFile parses configuration in `filename` and returns a configuration and an error

func (Config) Context

func (c Config) Context(ctx context.Context) context.Context

Context returns a new context from ctx with c attached

type FactoidSet

type FactoidSet map[string]factoid

func NewFactoidSet

func NewFactoidSet(values ...factoid) FactoidSet

func (FactoidSet) Add

func (f FactoidSet) Add(values ...factoid)

func (FactoidSet) Delete

func (f FactoidSet) Delete(val string)

Remove removes a value from the set.

func (FactoidSet) Exists

func (f FactoidSet) Exists(value factoid) bool

func (FactoidSet) Random

func (f FactoidSet) Random() factoid

func (FactoidSet) Slice

func (f FactoidSet) Slice() []factoid

Slice returns the values of the set as a slice.

func (FactoidSet) StringSlice

func (f FactoidSet) StringSlice() []string

Slice returns the values of the set as a slice.

Jump to

Keyboard shortcuts

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