// CreateScope creates a scope, i.e. for _global or #channel. func (b *BotDB) CreateScope(scope string) error { return b.db.Batch(func(tx *bolt.Tx) error { bucket, err := helpers.CreateBucketIfNotExistsWrap(tx, []byte(scope)) if err != nil { return err } return defaults.InitializeBucket(bucket) }) }
// InitializeBucket initializes a bucket as a scope. func InitializeBucket(b *bolt.Bucket) error { for i := 0; i < len(defaultKV)-1; i += 2 { k, v := defaultKV[i], defaultKV[i+1] if currentValue := b.Get(k); currentValue == nil { if err := helpers.PutWrap(b, k, v); err != nil { return err } } } for _, name := range defaultBuckets { if _, err := helpers.CreateBucketIfNotExistsWrap(b, []byte(name)); err != nil { return err } } return nil }