discordkvs

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2020 License: MIT Imports: 11 Imported by: 0

README

discordkvs

Discord storage library for bots

PkgGoDev

Install

go get github.com/ethanent/discordkvs

Features

  • Store key-value pairs within a Discord channel in a server, rather than storing data in your own database.
  • Cleans up data periodically, based on random chance for performance.
  • Can store data larger than a Discord message by automatically switching to attachment files rather than inline text. (Higher latency, but can store larger values.)
  • Encrypt values, so if you keep your secure KVS Application ID a secret (eg. by keeping codebase private), the data should be reasonably difficult for others to access.
    • Encryption fails early, so there should generally not be encryption errors after Application is initialized.
  • Optionally, Application may be allowed to read data from other bots / users sharing the same Application ID.

Usage

// Assuming you already have a *discordgo.Session called s...

app, err = discordkvs.NewApplication(s, "MyApp-ID891173")

if err != nil {/* handle error, probably panic during startup */}

// Once bot is open, you can begin saving / reading data.

err = app.Set("732134812499836941", "myKey", []byte("myValue"))

// Read value for myKey in guild 732134812499836941:

data, err := app.Get("732134812499836941", "myKey")

Documentation

Index

Constants

View Source
const KVSChannelName = "discordkvs_donotremove"

Variables

View Source
var ErrEmptyKey = errors.New("empty keys are not permitted")
View Source
var ErrNoExist = errors.New("pair does not exist")

Functions

func AcceptDataFromOtherUsers

func AcceptDataFromOtherUsers(a *Application)

Types

type Application

type Application struct {
	// contains filtered or unexported fields
}

func NewApplication

func NewApplication(s *discordgo.Session, id string, opts ...ApplicationConfigOption) (*Application, error)

func (*Application) Del added in v1.1.0

func (a *Application) Del(guildID string, key string) error

Del deletes a key-value pair.

func (*Application) Get

func (a *Application) Get(guildID string, key string) ([]byte, error)

Get gets the corresponding value given a key.

func (*Application) GetKVSChannelID added in v1.1.0

func (a *Application) GetKVSChannelID(guildID string) (string, error)

Gets the KVS channel for guild, creating one if it doesn't already exist.

func (*Application) Set

func (a *Application) Set(guildID string, key string, value []byte) error

Set writes a key-value pair.

type ApplicationConfigOption

type ApplicationConfigOption func(*Application)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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