forked from mendaloth/a-few-random-aard-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAardwolf_Finger_Notes.xml
361 lines (299 loc) · 9.38 KB
/
Aardwolf_Finger_Notes.xml
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="AardwolfFingerNotes"
author="Mendaloth"
id="c8c16ea02be29fae8e8154cc"
language="Lua"
purpose="Allows you to store info on a player that shows up when you finger or whois them."
save_state="y"
date_written="2010-10-08 18:25:13"
requires="4.61"
version="1.0"
>
<description trim="n">
<![CDATA[
Aardwolf Finger Notes v1.0.3 Help
<=================== ACTIONS ===================>
fnote help --> Displays this message.
fnote <player> --> Displays any notes you have for
> the player.
fnote add <player> --> Adds a note for <player>, or edits
> the note if the player already has
> one.
fnote showall --> Shows all players with notes.
fnote del <player> --> Removes any notes for <player>.
]]>
</description>
</plugin>
<!-- Get our standard constants -->
<include name="constants.lua"/>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="^\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- Player \: (.*?) \((.*?)\) \-\-\-\-\-\-\-\-\-\-\-\-\-\-$"
regexp="y"
omit_from_output="n"
script="Process_Player_Line"
sequence="10"
>
</trigger>
<trigger
enabled="n"
regexp="y"
omit_from_output="n"
match="\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-"
sequence="100"
name="endtriggerline"
send_to = "12"
>
<send>
Show_Player_Notes(player_name)
EnableTrigger("endtriggerline", false)
</send>
</trigger>
<trigger
enabled="y"
match="^\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- Player \: (.*?) \((.*?)\) \((.*?)\) \-\-\-\-\-\-\-\-\-\-$"
regexp="y"
omit_from_output="n"
script="Process_Player_Line"
sequence="10"
>
</trigger>
</triggers>
<!-- Aliases -->
<aliases>
<alias
match="fnote help"
enabled="y"
send_to="12"
>
<send>
Note(GetPluginInfo (GetPluginID(), 3))
Note("Note: The database file for this plugin is stored at '".. GetInfo (66) .. "player_notes.sqlite'")
Note("If you move your Mushclient install, or make a fresh one, copy that file over to the new folder and place it where Mushclient.exe is stored.")
</send>
</alias>
<alias
match="fnote add *"
enabled="y"
sequence="5"
expand_variables="y"
ignore_case="y"
send_to="12"
>
<send>
Add_Edit_Note("%1")
</send>
</alias>
<alias
match="fnote showall"
enabled="y"
sequence="5"
expand_variables="y"
ignore_case="y"
send_to="12"
>
<send>
Show_All_Players_With_Notes()
</send>
</alias>
<alias
match="fnote *"
enabled="y"
sequence="101"
expand_variables="y"
ignore_case="y"
send_to="12"
>
<send>
Show_Player_Notes("%1")
</send>
</alias>
<alias
match="fnote del *"
enabled="y"
sequence="5"
expand_variables="y"
ignore_case="y"
send_to="12"
>
<send>
result = utils.msgbox ("Are you sure you want to delete all notes for '%1'?", "You sure?", "okcancel")
if (result == "ok") then
Delete_Player_Notes("%1")
else
Note("Delete cancelled.")
end
</send>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
function Process_Player_Line(name, line, wildcards)
player_name = wildcards[1]
EnableTrigger("endtriggerline", true)
end
function Add_Edit_Note(player_name)
result = utils.editbox ("Notes for " .. player_name , "Notes for " .. player_name, Get_Current_Note(player_name))
if result then
if (result == "") then
--They blanked the note, ask them if they want to just delete it?
result_delete = utils.msgbox ("It looks like you made the note for " .. player_name .. " blank. Do you want to delete " .. player_name .. " from the database entirely?", "Delete " .. player_name .. "?", "yesno")
if (result_delete == "yes") then
Delete_Player_Notes(player_name)
else
--They just want to blank so update the note to make it blank.
Insert_Note(player_name, result)
end
else
Insert_Note(player_name, result)
end
else
--Do nothing
Note("Note editing cancelled.")
return
end
end
function Insert_Note(player_name, note)
local time_date_stamp = os.time()
--First lets see if it exists?
if (Name_Already_In_Database(player_name)) then
--It's already in the database so just update and include last updated date
local sql_statement = string.format("UPDATE Player_Notes SET notes=%s, last_updated=%s WHERE player_name=%s", fixsql(note), time_date_stamp, fixsql(player_name))
if (db:exec(sql_statement)) then
Note("The note for '" .. player_name .. "' was successfully updated.")
else
Report_DB_Error("Insert_Note", sql_statement)
end
else
--It's NOT in the database so INSERT and include CREATED date.
local sql_statement = string.format("INSERT INTO Player_Notes (player_name, notes, last_updated, created) VALUES (%s, %s, %s, %s)", fixsql(player_name), fixsql(note), time_date_stamp, time_date_stamp)
local prepared_statement = db:prepare (sql_statement) --> returns 0 (SQLITE_OK)
local database_result = prepared_statement:step() -- returns 101 (SQLITE_DONE)
if (database_result == sqlite3.DONE) then
--correctly stepped!
else
Report_DB_Error("Insert_Note", sql_statement)
end
if (prepared_statement:finalize() == sqlite3.OK) then
Note("New player note created for '" .. player_name .. "'")
else
Report_DB_Error("Insert_Note", sql_statement)
end
end
end
function Delete_Player_Notes(player_name)
if (Name_Already_In_Database(player_name)) then
local sql_statement = string.format("DELETE FROM Player_Notes WHERE player_name=%s", fixsql(player_name))
local prepared_statement = db:prepare (sql_statement) --> returns 0 (SQLITE_OK)
local database_result = prepared_statement:step() -- returns 101 (SQLITE_DONE)
if (database_result == sqlite3.DONE) then
--stepped
else
Report_DB_Error("Delete_Player_Notes", sql_statement)
end
if (prepared_statement:finalize() == sqlite3.OK) then
Note("Player note for '" .. player_name .. "' was deleted.")
else
Note("Problem deleting in Delete_Player_Notes")
Report_DB_Error("Delete_Player_Notes", sql_statement)
end
else
Note("No notes found for '" .. player_Name "'")
end
end
function Show_Player_Notes(player)
local sql_statement = string.format("SELECT * FROM Player_Notes WHERE player_name=%s", fixsql(player))
local notes_exist = false
local seperator = "------------------------------------------------------------"
for row in db:nrows(sql_statement) do
Note(seperator)
notes_exist = true
Note("Your player notes for " .. player .. ":")
Note("")
Note(row.notes)
Note("")
Tell("Last Updated: " .. os.date("%x %X", row.last_updated))
Note(" Created: " .. os.date("%x %X", row.created))
Note(seperator)
Hyperlink ("fnote add " .. player, "Click here to edit this note.", "Edit this note" , "", 0)
Note("")
Note("")
end
if (not notes_exist) then
Note(seperator)
Hyperlink ("fnote add " .. player, "No note exists for '" .. player .. "'. Click to add one.", "No note exists" , "", 0)
Note("")
Note(seperator)
end
end
function Get_Current_Note(player_name)
local sql_statement = string.format("SELECT notes FROM Player_Notes WHERE player_name=%s", fixsql(player_name))
for row in db:nrows(sql_statement) do
return row.notes
end
--If we got to this point there is no note so just return blank
return ""
end
function Name_Already_In_Database(player_name)
local sql_statement = string.format("SELECT player_name from Player_Notes WHERE player_name=%s", fixsql(player_name))
local prepared_statement = db:prepare (sql_statement) --> returns 0 (SQLITE_OK)
local row_result = prepared_statement:step() -- returns 101 (SQLITE_DONE)
if (row_result == sqlite3.DONE) then
return false
elseif (row_result == sqlite3.ROW) then
return true
else
Note("Error in Name_Already_In_Database, SQL statement returned an unexpected result")
return false
end
end
function fixsql (s)
--stole this function from the GMCP mapper that comes with aardwolf
if s then
return "'" .. (string.gsub (s, "'", "''")) .. "'" -- replace single quotes with two lots of single quotes
else
return "NULL"
end -- if
end -- fixsql
function Report_DB_Error(function_name, attempted_sql_statement)
Note("Error (" .. db:errcode() .. " " .. db:errmsg() .. ") in function ".. function_name .. " when executing the following SQL Statement: '" .. attempted_sql_statement .. "'")
end
function OnPluginInstall ()
db = assert (sqlite3.open( GetInfo (66) .. "player_notes.sqlite" ) )
assert (db:exec ([=[
CREATE TABLE IF NOT EXISTS "Player_Notes" (
"player_id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
"player_name" TEXT COLLATE NOCASE,
"notes" TEXT,
"last_updated" INTEGER,
"created" INTEGER
)]=]))
end
function Show_All_Players_With_Notes()
local sql_statement = string.format("SELECT player_name FROM Player_Notes", fixsql(player))
local notes_exist = false
local seperator = "------------------------------------------------------------"
local number = 0
Note(seperator)
Note("The following players have notes (click name to show):")
Note("")
for row in db:nrows(sql_statement) do
number = number + 1
Tell(" " .. number .. ". ")
Hyperlink ("fnote " .. row.player_name, row.player_name, "Show this note" , "", 0)
Note("")
end
Note("")
Note(seperator)
Note("")
Note("")
end
]]>
</script>
</muclient>