/
guild.go
68 lines (55 loc) · 1.48 KB
/
guild.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package statefdb
import (
"context"
"github.com/apple/foundationdb/bindings/go/src/fdb"
)
func (db *DB) SetGuild(_ context.Context, id int64, raw []byte) (bool, error) {
return false, db.Transact(func(t fdb.Transaction) error {
t.Set(db.fmtGuildKey(id), raw)
return nil
})
}
func (db *DB) GetGuild(_ context.Context, id int64) ([]byte, error) {
var g []byte
err := db.Transact(func(t fdb.Transaction) error {
g = t.Get(db.fmtGuildKey(id)).MustGet()
return nil
})
if err != nil {
return nil, err
}
return g, nil
}
func (db *DB) GetGuildCount(_ context.Context) (int, error) {
rr, _ := fdb.PrefixRange(db.fmtGuildPrefix())
return db.keyCountForPrefix(rr)
}
func (db *DB) DeleteGuild(_ context.Context, id int64) error {
return db.Transact(func(t fdb.Transaction) error {
t.Clear(db.fmtGuildKey(id))
return nil
})
}
func (db *DB) SetGuildBan(_ context.Context, guild, user int64, raw []byte) error {
return db.Transact(func(t fdb.Transaction) error {
t.Set(db.fmtGuildBanKey(guild, user), raw)
return nil
})
}
func (db *DB) GetGuildBan(_ context.Context, guild, user int64) ([]byte, error) {
var gb []byte
err := db.Transact(func(t fdb.Transaction) error {
gb = t.Get(db.fmtGuildBanKey(guild, user)).MustGet()
return nil
})
if err != nil {
return nil, err
}
return gb, nil
}
func (db *DB) DeleteGuildBan(_ context.Context, guild, user int64) error {
return db.Transact(func(t fdb.Transaction) error {
t.Clear(db.fmtGuildBanKey(guild, user))
return nil
})
}