-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtells.go
136 lines (126 loc) · 3.64 KB
/
tells.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package main
import (
"strings"
"time"
)
func (player *characterData) checkTells() {
numTells := len(player.Tells)
if numTells > 0 {
player.send("{rYou have {R%v {rtells waiting.", numTells-1)
} else {
player.send("You have no tells waiting.")
}
if player.Config.hasFlag(CONFIG_NOTELL) {
player.send("You currently have tells disabled!")
}
}
func cmdTells(player *characterData, input string) {
if player.Config.hasFlag(1 << CONFIG_NOTELL) {
player.send("Notice: You currently have tells disabled!")
}
numTells := len(player.Tells)
if numTells > 0 {
tell := player.Tells[0]
player.send("At %v"+NEWLINE+"%v told you: %v", tell.Sent.String(), tell.SenderName, tell.Message)
if numTells > 1 {
player.Tells = player.Tells[1:numTells]
} else {
player.Tells = []tellData{}
}
player.dirty = true
} else {
player.send("You don't have any tells waiting.")
return
}
if numTells-1 > 0 {
player.send("You have %v more tells waiting.", numTells-1)
}
}
func cmdTell(player *characterData, input string) {
if player.Config.hasFlag(1 << CONFIG_NOTELL) {
player.send("You currently have tells disabled.")
return
}
parts := strings.SplitN(input, " ", 2)
partsLen := len(parts)
if input == "" {
player.send("Tell whom what?")
return
}
if partsLen == 1 {
player.send("Tell them what?")
return
}
if target := checkPlaying(parts[0]); target != nil {
if target == player {
player.send("You tell yourself: %v", parts[1])
return
}
if target.Config.hasFlag(1 << CONFIG_NOTELL) {
player.send("Sorry, they have tells disabled.")
}
player.send("You tell %v: %v", target.Name, parts[1])
if notIgnored(player, target, true) {
target.send("%v tells you: %v", player.Name, parts[1])
}
return
} else if target := checkPlayingPMatch(parts[0]); target != nil && len(parts[0]) > 2 {
if target == player {
player.send("You tell yourself: %v", parts[1])
return
}
player.send("You tell %v: %v", target.Name, parts[1])
if notIgnored(player, target, true) {
target.send("%v tells you: %v", player.Name, parts[1])
}
return
}
if len(parts[1]) > MAX_TELL_LENGTH {
player.send("That is too long of a message for a tell. Maybe mail them a letter?")
}
tDesc := descData{valid: true}
target := tDesc.pLoad(parts[0])
if target != nil {
if target.Config.hasFlag(1 << CONFIG_NOTELL) {
player.send("Sorry, they have tells disabled.")
return
}
if len(target.Tells) < MAX_TELLS {
var ours int
for _, tell := range target.Tells {
if tell.SenderUUID == player.UUID && tell.SenderName == player.Name {
ours++
}
}
if ours >= MAX_TELLS_PER_SENDER {
player.send("You've reached the maximum number of offline tells to one person.")
return
}
player.send("You tell %v: %v", target.Name, parts[1])
player.send("They aren't available right now, but your message has been saved.")
if notIgnored(player, target, true) {
target.Tells = append(target.Tells, tellData{SenderName: player.Name, SenderUUID: player.UUID, Message: parts[1], Sent: time.Now().UTC()})
target.saveCharacter()
}
return
} else {
player.send("They aren't available right now and they have reached the maxiumum number of stored tells.")
}
}
player.send("I don't see anyone by that name.")
}
func notIgnored(player, target *characterData, feedback bool) bool {
//Players can't ignore staff.
if target.Level >= LEVEL_BUILDER && player.Level < LEVEL_BUILDER {
return true
}
for _, item := range target.Ignores {
if item.Name == player.Name && item.UUID == player.UUID {
if !item.Silent && feedback {
player.send("Sorry, %v is ignoring you.", target.Name)
}
return false
}
}
return true
}