forked from Johnson336/LotJPlugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLotJMemory.xml
More file actions
219 lines (203 loc) · 8.89 KB
/
LotJMemory.xml
File metadata and controls
219 lines (203 loc) · 8.89 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE muclient>
<muclient>
<plugin name="LotJMemory" author="@Johnson" id="ef6468111c356c67de0326a0" language="Lua" purpose="DUB/GREET Management" save_state="y" date_written="2013-03-20 19:38:54" requires="4.73" version="1.0">
<description trim="y">
<![CDATA[
Plugin for maintaining a list of your dubs greets and their corresponding racial features.
LotJMemory v 1.0 by Johnson. Enter 'memhelp' for general command information.
Enter 'memhelp <command>' for more detailed information on that command.
]]>
</description>
</plugin>
<!-- Get our standard constants -->
<include name="constants.lua" />
<!-- Triggers -->
<triggers>
<trigger name="chartochar" match="\A(?P<who>.+?) (has some cuts|has a few bruises|is slightly scratched|is in perfect health)\.\n(?P=who) is (?P<what>.+?)\.\Z" script="stripName" regexp="y" enabled="y" lines_to_match="2" multi_line="y" group="LotJMemory" sequence="100" />
<trigger name="idgrab" match="^Player id (?P<idnum>.+?) Player home (.*)$" script="storeID" group="LotJMemory" regexp="y" enabled="y" sequence="100" />
</triggers>
<!-- Aliases -->
<aliases>
<alias name="checkmemory" match="^memcheck( +(.*)?)*$" script="memCheck" enabled="y" group="LotJMemory" regexp="y" ignore_case="y" sequence="100" />
<alias name="memoryrename" match="^memrename (.*) (.*)$" script="memRename" enabled="y" group="LotJMemory" regexp="y" ignore_case="y" sequence="100" />
<alias name="memremove" match="^memremove (.*)" script="memRemove" enabled="y" group="LotJMemory" regexp="y" ignore_case="y" sequence="100" />
<alias name="memhelp" match="^memhelp(\s*(.*))?$" script="memHelp" enabled="y" group="LotJMemory" regexp="y" ignore_case="y" sequence="100" />
<alias name="memoryclear" match="^memclear$" script="memClear" enabled="y" group="LotJMemory" regexp="y" ignore_case="y" sequence="100" />
</aliases>
<!-- Script -->
<script>
<![CDATA[
require "serialize"
memory = {}
local idnum = 0
loadstring(GetVariable("memory"..idnum) or "")()
require "tprint"
function OnPluginConnect()
SaveState()
idnum = 0
memory = {}
loadstring(GetVariable("memory"..idnum) or "")()
end
function stripName(name, line, args)
assert (args, "nil arg passed to stripName")
if not string.find(args.who, " ", 0) and idnum ~= 0 then -- avoid saving multi-word names, like armor restrings
memory[args.who] = {what = args.what, when = os.time()}
Note("Saved ".. args.who .. " description.")
end
end
function storeID(name, line, args)
SaveState()
idnum = args.idnum
memory = {}
loadstring(GetVariable("memory"..idnum) or "")()
end
function memClear()
memory = {}
ColourNote("lime","black","Stored dub/greet description memory cleared.")
end
function memRemove(name, line, args)
assert (args, "nil arg passed to memRemove")
local namefind
if args[1] ~= "" then
namefind = Trim(args[1])
for k, v in pairs(memory) do
if (string.lower(k) == string.lower(namefind)) then
memory[k] = nil
ColourNote("lime","black", k.." removed from memory.")
return
end
end
ColourNote("red","black",k.." not found in memory.")
return
end
ColourNote("red","black","Usage: memremove <name>")
end
function memRename(name, line, args)
assert (args, "nil arg passed to memRename")
local namefind, replace
if args[1] ~= "" and args[2] ~= "" then
namefind = Trim(args[1])
replace = Trim(args[2])
for k, v in pairs(memory) do
if (string.lower(k) == string.lower(namefind)) then
memory[replace] = memory[k]
ColourNote("lime","black", k.." renamed to "..replace)
memory[k] = nil
return
end
end
ColourNote("red","black",namefind.." not found in memory.")
return
end
ColourNote("red","black","Usage: memrename <name> <rename>")
end
function memCheck(name, line, args)
assert (args, "nil arg passed to memCheck")
--tprint(memory)
local i = 0
local found = false
local name = ""
if Trim(args[1]) ~= "" then
name = Trim(args[1])
if name == "full" then
ColourNote("silver","black","Full Dub/Greet description memory:")
ColourNote("silver","black"," Greet/dub : LastSeen : Player description")
for k, v in pairs(memory) do
i = i + 1
ColourNote("gray","black",string.format("%-20s : %8s : %-20s", k, os.date("%x", tonumber(v.when)), v.what))
end
ColourNote("silver","black","You can remember a total of "..i.." dub/greet description"..((i==1 and "") or "s")..".")
else
for k, v in pairs(memory) do
if string.find(string.lower(k), string.lower(name), 0) or string.find(string.lower(v.what), string.lower(name), 0) then
local daysago = string.format("%1.0f", os.difftime(os.time(), tonumber(v.when))/86400)
ColourTell("silver","black","You last saw ",
"cyan","black",k,
"silver","black"," on ",
"cyan","black",os.date("%x", tonumber(v.when)),
"silver","black","(",
"cyan","black",daysago,
"silver","black",((daysago == "1" and " day") or " days").." ago). They were "..v.what..".\r\n")
found = true
end
end
if not found then
ColourNote("red","black",name.." not found in memory.")
return
end
end
else
ColourNote("silver","black","Dub/Greet description memory:")
for k, v in pairs(memory) do
i=i+1
local daysago = string.format("%1.0f", os.difftime(os.time(), tonumber(v.when))/86400)
ColourTell("gray","black",string.format("%-20s ", k),
"cyan","black",string.format("%-3d ", daysago))
if math.fmod(i,3) == 0 then
Note("")
end
end
if math.fmod(i,3) ~= 0 then
Note("")
end
ColourNote("silver","black","You can remember a total of "..i.." dub/greet description"..((i==1 and "") or "s")..".")
end
Note("")
end
function OnPluginSaveState()
SetVariable("memory"..idnum, serialize.save("memory"))
end
-- define our help command structure
local commands = { { name = "memcheck", desc = "Displays all of your saved player descriptions.",
args = { { name = "<none>", desc = "Lists shortened description memory."},
{ name = "full", desc = "Lists every description memory in full detail."},
{ name = "<argument1>", desc = "Searches your memory for the given keyword. Can be any part of the name or description to match."}, }
},
{ name = "memrename", desc = "Used to rename a saved player description.",
args = { { name = "<argument1> <argument2>", desc = "Keep argument1's description and last-seen date, but give it argument2's name."}, }
},
{ name = "memremove", desc = "Removes an description from memory.",
args = { { name = "<argument1>", desc = "Removes the specified name's description from memory. Useful in the event of receiving a player's greet that didn't get updated properly."} }
},
{ name = "memclear", desc = "Deletes your entire description memory.",
args = { }
},
{ name = "memhelp", desc = "Display this help file.",
args = { { name = "<argument1>", desc = "Display more detailed help information on the given command."} }
},
}
function memHelp(name, line, args)
local found = false
if args[1] == "" then -- show general help
ColourNote("white","black","LotJMemory v 1.0 by Johnson. Enter 'memhelp <command>' for more detailed information.")
for a, b in ipairs(commands) do -- commands
local command = b
ColourNote("silver","black",string.format("%-20s", command.name).." : "..command.desc)
end
Note("")
else -- entered something
ColourNote("white","black","LotJMemory v 1.0 by Johnson. Enter 'memhelp' for more general information.")
for a, b in ipairs(commands) do -- scroll through commands
if (string.lower(b.name) == string.lower(Trim(args[1]))) then -- found our argument
found = true
ColourNote("silver","black",b.name .. " : " .. b.desc)
ColourNote("silver","black","Available arguments:")
if #b.args == 0 then -- no arguments
ColourNote("silver","black"," None.")
else -- arguments to print
for i, k in ipairs(b.args) do
ColourNote("silver","black",string.format("%20s", k.name).." : " .. k.desc)
end -- end print arguments
end -- end no arguments
Note("")
end -- end found command
end -- end scroll commands
if not found then
ColourNote("silver","black","Command '"..args[1].."' not found.")
end
end -- end no input
end
]]>
</script>
</muclient>