-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse.go
More file actions
49 lines (40 loc) · 1.05 KB
/
Copy pathresponse.go
File metadata and controls
49 lines (40 loc) · 1.05 KB
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
package main
import (
"strings"
"text/template"
"github.com/bwmarrin/discordgo"
"github.com/travis-g/dice/math"
)
// Response templates for dice roll message responses.
var (
ResponseTemplate = "{{if .Name}}{{.Name}} rolled{{end}}{{if .Expression}} `{{.Expression}}`{{end}}{{if .Label}} _{{.Label}}_{{end}}: `{{.Rolled}}` = **{{.Result}}**"
)
var (
responseResultTemplateCompiled = template.Must(
template.New("result").Parse(ResponsePrefix + ResponseTemplate),
)
)
// Deprecated: Response is a message response for dice roll responses.
type Response struct {
*math.ExpressionResult
// Name of who made the roll (optional)
Name string
Rolled string
Result string
Expression string
Label string
FriendlyError error
Error error
}
func executeResponseTemplate(b *strings.Builder, r *Response) {
_ = responseResultTemplateCompiled.Execute(b, r)
}
type RollResponse struct {
*NamedRollInput
User *discordgo.User
Rolls []interface{}
Errors []error
}
func (r *RollResponse) Count() int {
return len(r.Rolls)
}