/
Command.go
52 lines (43 loc) · 1.75 KB
/
Command.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
package models
import (
"context"
"github.com/Amazeful/dataful"
"github.com/Amazeful/dataful/models/embeddables"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type Command struct {
dataful.BaseModel `bson:",inline"`
Channel primitive.ObjectID `bson:"channel" json:"channel"`
Name string `bson:"name" json:"name"`
Enabled bool `bson:"enabled" json:"enabled"`
Cooldowns embeddables.Cooldown `bson:"cooldowns" json:"cooldowns"`
Role embeddables.UserRole `bson:"role" json:"role"`
Stream embeddables.StreamStatus `bson:"stream" json:"stream"`
Response string `bson:"response" json:"response"`
Aliases []string `bson:"aliases" json:"aliases"`
HasVar bool `bson:"hasVar" json:"-"`
Attributes embeddables.CommandAttributes `bson:"attributes" json:"attributes"`
Timer embeddables.Timer `bson:"timer" json:"timer"`
}
func NewCommand(r dataful.Repository) *Command {
return &Command{
BaseModel: dataful.NewBaseModel(r),
Enabled: true,
Cooldowns: embeddables.Cooldown{Global: 5, User: 15},
Role: embeddables.UserRoleGlobal,
Stream: embeddables.StreamLive | embeddables.StreamOffline,
}
}
func (c *Command) Create(ctx context.Context) error {
return c.R().InsertOne(ctx, c)
}
func (c *Command) Update(ctx context.Context) error {
return c.R().ReplaceOne(ctx, bson.M{"_id": c.ID}, c)
}
func (c *Command) Delete(ctx context.Context) error {
return c.R().DeleteOne(ctx, bson.M{"_id": c.ID})
}
func (c *Command) LoadBylId(ctx context.Context, id primitive.ObjectID) error {
return c.R().FindOne(ctx, bson.M{"_id": id}, c)
}