bolt

package module
v0.0.0-...-7cca953 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

README

Joe Bot - Bolt Memory

Integration Joe with Bolt. https://github.com/go-joe/joe


This repository contains a module for the Joe Bot library. Built using etcd-io/bbolt.

Getting Started

This library is packaged using Go modules. You can get it via:

go get github.com/thomaseitler/joe-bolt-memory

Example usage

package main

import (
	"github.com/go-joe/joe"
	"github.com/thomaseitler/joe-bolt-memory"
)

func main() {
	b := joe.New("example-bot",
		bolt.Memory(os.Getenv("DB_PATH")),
		…
	)
	
	b.Respond("remember (.+) is (.+)", b.Remember)
	b.Respond("what is (.+)", b.WhatIs)

	err := b.Run()
	if err != nil {
		b.Logger.Fatal(err.Error())
	}
}

func (b *Bot) Remember(msg joe.Message) error {
	key, value := msg.Matches[0], msg.Matches[1]
	msg.Respond("OK, I'll remember %s is %s", key, value)
	return b.Store.Set(key, value)
}

func (b *Bot) WhatIs(msg joe.Message) error {
	key := msg.Matches[0]
	var value string
	ok, err := b.Store.Get(key, &value)
	if err != nil {
		return errors.Wrapf(err, "failed to retrieve key %q from brain", key)
	}
	if ok {
		msg.Respond("%s is %s", key, value)
	} else {
		msg.Respond("I do not remember %q", key)
	}
	return nil
}

License

BSD-3-Clause

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BucketkeyFromString

func BucketkeyFromString(in string) *bucketkey

func Memory

func Memory(path string) joe.Module

func NewMemory

func NewMemory(path string, opts ...Option) (joe.Memory, error)

Types

type Option

type Option func(*memory) error

func WithFileMode

func WithFileMode(mode os.FileMode) Option

func WithLogger

func WithLogger(logger *zap.Logger) Option

func WithOptions

func WithOptions(opts *bolt.Options) Option

Jump to

Keyboard shortcuts

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