-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
76 lines (74 loc) · 2.16 KB
/
context.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
package cmds
import (
"github.com/Clinet/clinet_services"
"github.com/JoshuaDoes/json"
)
type CmdCtx struct {
Alias string //Alias that triggered command
Args []*CmdArg //Arguments for command handler
Edited bool //True when called in response to edited call
User *services.User //User who called the command
Channel *services.Channel //Channel where command was called
Server *services.Server //Server where command was called
Message *services.Message //Message that called this command
Attachments []*services.MessageAttachment //Attachments to the message that called this command
Service services.Service `json:"-"` //Service client for service callbacks
}
func NewCmdCtx() *CmdCtx {
return &CmdCtx{}
}
func (ctx *CmdCtx) String() string {
jsonData, err := json.Marshal(ctx, true)
if err != nil {
return err.Error()
}
return string(jsonData)
}
func (ctx *CmdCtx) SetAlias(alias string) *CmdCtx {
ctx.Alias = alias
return ctx
}
func (ctx *CmdCtx) SetQuery(alias string) *CmdCtx {
ctx.Alias = alias //helloworld
return ctx
}
func (ctx *CmdCtx) SetEdited() *CmdCtx {
ctx.Edited = true
return ctx
}
func (ctx *CmdCtx) SetUser(user *services.User) *CmdCtx {
ctx.User = user
return ctx
}
func (ctx *CmdCtx) SetChannel(channel *services.Channel) *CmdCtx {
ctx.Channel = channel
return ctx
}
func (ctx *CmdCtx) SetServer(server *services.Server) *CmdCtx {
ctx.Server = server
return ctx
}
func (ctx *CmdCtx) SetMessage(message *services.Message) *CmdCtx {
ctx.Message = message
return ctx
}
func (ctx *CmdCtx) SetService(service services.Service) *CmdCtx {
ctx.Service = service
return ctx
}
func (ctx *CmdCtx) AddArgs(arg ...*CmdArg) *CmdCtx {
ctx.Args = append(ctx.Args, arg...)
return ctx
}
func (ctx *CmdCtx) GetArg(name string) *CmdArg {
for _, arg := range ctx.Args {
if arg.Name == name {
return arg
}
}
return nil
}
func (ctx *CmdCtx) AddAttachments(attach ...*services.MessageAttachment) *CmdCtx {
ctx.Attachments = append(ctx.Attachments, attach...)
return ctx
}