Skip to content

Commit

Permalink
smarter autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
tg123 committed May 4, 2020
1 parent 79673c2 commit 2883d88
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1130,8 +1130,29 @@ function GUI:Init()
return data
end

local lastchat = {}
local onraidchat = function(text, playerName)
playerName = strsplit("-", playerName)
lastchat[playerName] = time()

local min = playerName
for p in pairs(lastchat) do
if lastchat[p] < lastchat[min] then
min = p
end
end

if #lastchat > 10 then
lastchat[min] = nil
end
end

RegEvent("CHAT_MSG_RAID_LEADER", onraidchat)
RegEvent("CHAT_MSG_RAID", onraidchat)

local autoCompleteRaidRoster = function(text)
local data = {}
local tmp = {}

for i = 1, MAX_RAID_MEMBERS do
local name, _, subgroup, _, class = GetRaidRosterInfo(i)
Expand All @@ -1147,14 +1168,22 @@ function GUI:Init()
b = b or (strfind(class, string.lower(text)))

if b then
tinsert(data, {
["name"] = name,
["priority"] = LE_AUTOCOMPLETE_PRIORITY_IN_GROUP,
})
tinsert(tmp, name)
end
end
end

table.sort(tmp, function(a, b)
return (lastchat[a] or 0) > (lastchat[b] or 0)
end)

for _, name in pairs(tmp) do
tinsert(data, {
["name"] = name,
["priority"] = LE_AUTOCOMPLETE_PRIORITY_IN_GROUP,
})
end

return data
end

Expand Down

0 comments on commit 2883d88

Please sign in to comment.