-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_history.go
74 lines (66 loc) · 2.28 KB
/
mod_history.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
package command
import (
"errors"
"log"
"strings"
"time"
"github.com/df-mc/dragonfly/server"
"github.com/df-mc/dragonfly/server/cmd"
"github.com/df-mc/dragonfly/server/player"
"github.com/sandertv/gophertunnel/minecraft/text"
"github.com/xtt28/neptune/database"
"github.com/xtt28/neptune/database/model"
"github.com/xtt28/neptune/lookup"
"github.com/xtt28/neptune/permission/permlvl"
"gorm.io/gorm"
)
type modHistoryCommandExec struct {
srv *server.Server
Subject string `cmd:"subject"`
}
func (c modHistoryCommandExec) Run(source cmd.Source, output *cmd.Output) {
if !RequireAtLeast(source, output, permlvl.LvlModerator) {
return
}
p := source.(*player.Player)
subject, _, err := lookup.GetOnlineOrOfflineUUID(database.DB, c.srv, c.Subject)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
output.Print(text.Colourf("<red>We couldn't find that player.</red>"))
} else {
output.Print(text.Colourf("<red>An error occurred while looking up that player.</red>"))
log.Println(err.Error())
}
return
}
target := new([]*model.Punishment)
res := database.DB.Order("created_at").
Where(&model.Punishment{Subject: subject}).
Find(&target)
if res.Error != nil {
output.Print(text.Colourf("<red>An error occurred while looking up that history.</red>"))
log.Println(res.Error.Error())
return
}
bob := strings.Builder{}
bob.WriteString(text.Colourf("\n<aqua>Enforcement history for <diamond>%s</diamond> <grey>(ascending)</grey></aqua>\n", c.Subject))
if len(*target) == 0 {
bob.WriteString(text.Colourf("<green>This player has never been punished</green>\n"))
}
for i, v := range *target {
bob.WriteString(text.Colourf("<diamond>%d. </diamond>", i + 1))
bob.WriteString(text.Colourf("<aqua>%s</aqua> <dark-grey>-</dark-grey> ", v.Type))
bob.WriteString(text.Colourf("<grey>%s</grey> (case #%d)\n", v.CreatedAt.Format(time.RFC822), v.ID))
issuerUsername, err := lookup.OfflineUUIDToUsername(database.DB, v.Issuer)
if err == nil {
bob.WriteString(text.Colourf("<grey>Issued by <white>%s</white></grey>\n", issuerUsername))
}
reason := v.Reason
if reason == "" {
reason = "<red>None provided</red>"
}
bob.WriteString(text.Colourf("<grey>Reason:</grey> <white>%s</white>\n", reason))
}
bob.WriteString("\n")
p.Message(bob.String())
}