-
Notifications
You must be signed in to change notification settings - Fork 2
/
storage.go
77 lines (66 loc) · 1.58 KB
/
storage.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
69
70
71
72
73
74
75
76
77
package main
import "github.com/asdine/storm"
type Muted struct {
UserId int `storm:"id"`
}
func (m Muted) Mute() error {
if err := storage.Save(&m); err != nil {
log.Debugf("Failed to save data to storage, error: %s", err)
return err
}
return nil
}
func (m Muted) Unmute() error {
if err := storage.DeleteStruct(&m); (err != nil) && (err != storm.ErrNotFound) {
log.Debugf("Failed to remove data from storage, error: %s", err)
return err
}
return nil
}
func (m Muted) IsMuted() (bool, error) {
err := storage.One("UserId", m.UserId, &m)
if err == storm.ErrNotFound {
return false, nil
} else if err != nil {
log.Debugf("Can not get data from storage, error: %s", err)
return false, err
}
return true, nil
}
type LastChanMessage struct {
ChatID int64 `storm:"id"`
MessageID int
Sender int
}
func (m LastChanMessage) Save() error {
if err := storage.Save(&m); err != nil {
log.Debugf("Can not save last messageID, error: %s", err)
return err
}
return nil
}
type Integration struct {
ChatID int64 `storm:"id"`
}
func (i Integration) Add() error {
if err := storage.Save(&i); err != nil {
log.Debugf("Can not add integration, error: %s", err)
return err
}
return nil
}
func (i Integration) Remove() error {
if err := storage.DeleteStruct(&i); err != nil {
log.Debugf("Can not add integration, error: %s", err)
return err
}
return nil
}
func (i Integration) GetAll() ([]Integration, error) {
var itg []Integration
if err := storage.All(&itg); err != nil {
log.Debugf("Can not get integrations, error: %s", err)
return nil, err
}
return itg, nil
}