You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
3.9 KiB

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Wednesday, February 22, 2023, 1:56 PM -->
<!-- MuClient version 5.07-pre -->
<!-- Plugin "FriendAgoSorted" generated by Plugin Wizard -->
<!-- Blame Kerith. He's a jerk. -->
<muclient>
<plugin name="FriendAgoSorted" author="Crowley" id="d434e9b635dc35c2ff25e1c9" language="Lua" purpose="Sort Friend Ago" save_state="y" date_written="2023-02-22 13:55:27" requires="4.99" version="1.0">
</plugin>
<!-- Triggers -->
<triggers>
<trigger group="friendCheck" match="^\s{0,2}\d+\) - (\w+)\s+\(Offline -\s(.*)\)" regexp="y" script="getStatus" sequence="100" omit_from_output="y">
</trigger>
<trigger group="friendCheck" match="^\s{0,2}\d+\) - (\w+)\s+\((?:(Online|Private|Missing|Linkdead))\)" regexp="y" script="storeOther" sequence="100" omit_from_output="y">
</trigger>
<trigger group="friendCheck" match="^$" regexp="y" send_to="12" sequence="100">
<send>EnableTriggerGroup("friendCheck", false)
returnOutput()
</send>
</trigger>
</triggers>
<!-- Aliases -->
<aliases>
<alias match="^friend ago(?: (-r))?$" enabled="y" regexp="y" send_to="12" sequence="100">
<send>
resetValues()
if "%1" == "-r" then
reverse = true
end
EnableTriggerGroup("friendCheck")
Send("friend ago")
</send>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
dofile(GetInfo(60) .. "aardwolf_colors.lua")
friendAgo = {}
friendSeconds = {}
friendOther = {}
friendsAlpha = {}
count = 0
reverse = false
strForm = "@w%3d) - %-12s@R(Offline - %d day%s and %02d:%02d:%02d)\n"
statForm = "@w%3d) - %-12s%s(%s)\n"
function resetValues()
friendAgo = {}
friendSeconds = {}
friendOther = {}
count = 0
friendsAlpha = {}
end
function getStatus(name, line, wildcards)
local name = wildcards[1]
local status = wildcards[2]
local days, hours, minutes, seconds = 0, 0, 0, 0
if string.find(status, "day") then
days, hours, minutes, seconds = string.match(status, "(%d+) days? and (%d+):(%d+):(%d+)")
else
hours, minutes, seconds = string.match(status, "(%d+):(%d+):(%d+)")
end
friendAgo[name] = {days = days, hours = hours, minutes = minutes, seconds = seconds}
end
function convertToSeconds(name, days, hours, minutes, seconds)
local totSeconds = days*86400 + hours*3600 + minutes*60 + seconds
friendSeconds[name] = totSeconds
end
function sortTableByValue(tbl)
local sortedTable = {}
for k, v in pairs(tbl) do
table.insert(sortedTable, {key = k, value = v})
end
if reverse == true then
table.sort(sortedTable, function(b, a) return a.value > b.value end)
else
table.sort(sortedTable, function(a, b) return a.value > b.value end)
end
reverse = false
return sortedTable
end
function returnOutput()
for i,v in pairs(friendAgo) do
convertToSeconds(i, v.days, v.hours, v.minutes, v.seconds)
end
friendSeconds = sortTableByValue(friendSeconds)
for i,v in pairs(friendSeconds) do
local kname = v.key
local fTable = friendAgo[kname]
local days = fTable.days
local hours = fTable.hours
local minutes = fTable.minutes
local seconds = fTable.seconds
local plural = (tonumber(days) == 1 and "" or "s")
Simulate(ColoursToANSI(string.format(strForm, i, kname, days, plural, hours, minutes, seconds)))
count = i
end
for k in pairs(friendOther) do
table.insert(friendsAlpha, k)
end
table.sort(friendsAlpha)
for _, v in pairs(friendsAlpha) do
local vColor = "@G"
if friendOther[v] == "Private" or friendOther[v] == "Missing" then
vColor = "@Y"
elseif friendOther[v] == "Linkdead" then
vColor = "@C"
end
count = count + 1
Simulate(ColoursToANSI(string.format(statForm, count, v, vColor, friendOther[v])))
end
end
function storeOther(name, line, wildcards)
friendOther[wildcards[1]] = wildcards[2]
end
]]>
</script>
</muclient>