I was bored, here's some code.
Lua Code:
local CachedText={};
local function OnShow(self) CachedText[self]=self:GetText(); end
local function OnTextChanged(self) local txt=self:GetText(); if txt~="" then CachedText[self]=txt; end end
local Hooked={};
hooksecurefunc("ChatEdit_ActivateChat",function(editbox)
if not Hooked[editbox] then
editbox:HookScript("OnShow",OnShow);
editbox:HookScript("OnTextChanged",OnTextChanged);
OnShow(editbox);-- Aready shown by the time this runs
Hooked[editbox]=true;
end
end);
local Count,Start=0,GetTime();
hooksecurefunc("ChatEdit_SendText",function(editbox)
local cmd,now=((CachedText[editbox] or ""):match("^/%S+") or ""):upper(),GetTime();
if IsSecureCmd(cmd) or hash_SlashCmdList[cmd] or hash_EmoteTokenList[cmd] then
-- Our reset command will run this too
if Count<0 then Count=0; return; end
if Count<1 then Start=now; end
Count=Count+1;
local runtime=now-Start;
print(("%d commands run in %0.2f seconds. (%0.2f commands per second)"):format(Count,runtime,Count/runtime));
end
end);
function SlashCmdList.SLASHCOUNT_RESET()
-- Our hook will finish the reset
Count=-1;
end
SLASH_SLASHCOUNT_RESET1="/slashcountreset";
SLASH_SLASHCOUNT_RESET2="/screset";