Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ The other Console tabs:
| Roster | Reads the guild roster for the website and lists inactive members. |
| Recruits | An Add recruit form that fills in your target, plus applicants and trials with yes/no votes from officers. |
| Payouts | Recruitment drive winners and their prize, settled a week after each drive ends. Stand at a mailbox and click Mail to send it; nothing sends until then, and a row disappears once it's paid. |
| Bank | Saves the open guild bank tab's log for the website. |
| Bank | Lists everyone who has used the guild bank, biggest giver first: gold and items put in (items valued at the guild's auction prices) and gold, repairs and items taken out. It also saves the open tab's log for the website. These totals only count what your own copy of the addon has read from the bank log; the website's Guild page adds up every officer's reads, counts each member's characters together, and shows the totals to all members. The game keeps only each tab's latest entries, so open every tab now and then. |
| Announce | Posts a message to guild chat and every member's News tab, and to Discord if you tick the box. |
| Sync | Shows what hasn't been sent to the website yet, with Export and Import buttons. **Update calendar** puts the site's upcoming events on the in-game guild calendar. |
| Debug | Guild Master only. Lists what the game blocked SideQuest from doing and errors the addon caught, with a box to copy them. **View as** shows the windows as a non-member, member or officer sees them; **Back to my view**, closing the window or `/sq viewas off` ends it. |
Expand Down
128 changes: 126 additions & 2 deletions SideQuest/Bank.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
-- timestamp across exports, keyed by its unchanging content, and a repeat
-- capture matches against it within a tolerance that absorbs both the
-- elapsed-hour rounding and the hour that passes between two captures.
--
-- Every new row is also credited to SideQuestDB.bankContrib, a running
-- per-character tally of gold and items put in and taken out. Unlike
-- pending.bank it is never cleared, so officers can see who has given what
-- since this client started counting. It only knows the rows this client
-- captured: the game keeps a short log per tab, so anything that scrolls
-- off before an officer opens that tab is never counted.

SideQuest = SideQuest or {}
SideQuest.Bank = {}
Expand Down Expand Up @@ -123,6 +130,60 @@ local function recordIfNew(key, at, matchedThisPass)
return true, id
end

local function newContributor()
return { gold_in = 0, gold_out = 0, repairs = 0, items_in = 0, items_out = 0, items = {} }
end

-- Adds one newly recorded log row to its character's running totals. Tab
-- moves and tab purchases aren't anyone's contribution, so they're skipped.
local function credit(row)
if row.character == "" then
return
end
local kind, ledger = row.kind, SideQuestDB.bankContrib
local isItem = kind == "deposit" or kind == "withdraw"
if not (isItem or kind == "deposit_money" or kind == "withdraw_money" or kind == "repair") then
return
end
local c = ledger.players[row.character]
if not c then
c = newContributor()
ledger.players[row.character] = c
end
if kind == "deposit_money" then
c.gold_in = c.gold_in + row.money
elseif kind == "withdraw_money" then
c.gold_out = c.gold_out + row.money
elseif kind == "repair" then
c.repairs = c.repairs + row.money
else
local count = row.count or 0
local item = row.item_id and c.items[row.item_id]
if row.item_id and not item then
item = { given = 0, taken = 0 }
c.items[row.item_id] = item
end
if kind == "deposit" then
c.items_in = c.items_in + count
if item then item.given = item.given + count end
else
c.items_out = c.items_out + count
if item then item.taken = item.taken + count end
end
end
if not c.last_at or row.at > c.last_at then
c.last_at = row.at
end
if not ledger.since or row.at < ledger.since then
ledger.since = row.at
end
end

local function record(row)
table.insert(SideQuestDB.pending.bank, row)
credit(row)
end

--- Capture a guild bank tab's item transaction log into pending.bank.
-- Reads whatever QueryGuildBankLog(tab) has already delivered; call once
-- GUILDBANKLOG_UPDATE has fired. Returns the number of new rows, or nil if
Expand All @@ -144,7 +205,7 @@ function Bank.CaptureItemLog(tabIndex)
local at = estimateAt(years, months, days, hours)
local isNew, id = recordIfNew(key, at, matchedThisPass)
if isNew then
table.insert(SideQuestDB.pending.bank, {
record({
id = id,
at = at,
character = normalized(name),
Expand Down Expand Up @@ -196,7 +257,7 @@ function Bank.CaptureMoneyLog()
local at = estimateAt(years, months, days, hours)
local isNew, id = recordIfNew(key, at, matchedThisPass)
if isNew then
table.insert(SideQuestDB.pending.bank, {
record({
id = id,
at = at,
character = normalized(name),
Expand All @@ -217,6 +278,69 @@ function Bank.CaptureMoneyLog()
return added
end

-- What a character's deposited items would fetch at the guild's last
-- imported auction prices (SideQuestDB.prices), in copper. Items with no
-- known price add nothing.
local function depositedItemValue(items)
local value = 0
for itemId, item in pairs(items) do
local price = SideQuest.Market.AuctionPrice(itemId)
if price and price.p then
value = value + price.p * item.given
end
end
return value
end

--- Everyone this client has seen use the guild bank, biggest contributor
-- first: gold deposited plus the auction value of items deposited, then
-- items deposited, then name. Each entry is { character, gold_in,
-- gold_out, repairs, items_in, items_out, item_value, last_at, items },
-- where items lists { item_id, given, taken }, most given first.
function Bank.Contributors()
local list = {}
for character, c in pairs(SideQuestDB.bankContrib.players) do
local items = {}
for itemId, item in pairs(c.items) do
table.insert(items, { item_id = itemId, given = item.given, taken = item.taken })
end
table.sort(items, function(a, b)
if a.given ~= b.given then
return a.given > b.given
end
return a.item_id < b.item_id
end)
table.insert(list, {
character = character,
gold_in = c.gold_in,
gold_out = c.gold_out,
repairs = c.repairs,
items_in = c.items_in,
items_out = c.items_out,
item_value = depositedItemValue(c.items),
last_at = c.last_at,
items = items,
})
end
table.sort(list, function(a, b)
local av, bv = a.gold_in + a.item_value, b.gold_in + b.item_value
if av ~= bv then
return av > bv
end
if a.items_in ~= b.items_in then
return a.items_in > b.items_in
end
return a.character < b.character
end)
return list
end

--- When the earliest row this client has counted happened, or nil before
-- any capture.
function Bank.ContributionsSince()
return SideQuestDB.bankContrib.since
end

--- Ask the server for the item and money logs; results land asynchronously
-- via GUILDBANKLOG_UPDATE, captured below. Safe to call with the bank
-- closed (QueryGuildBankLog is simply a no-op then); does nothing if the
Expand Down
5 changes: 5 additions & 0 deletions SideQuest/Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ local function defaultDB()
-- row whose reported elapsed time has grown. Survives `/sq export clear`
-- (pending.bank doesn't); pruned at 120 days.
bankSeen = {},
-- Bank.lua: per-character running totals of what each player put into and took out of the guild bank,
-- built from every log row this client captures. Never cleared by `/sq export clear`. `since` is the
-- earliest row counted; players[character] = { gold_in, gold_out, repairs, items_in, items_out,
-- last_at, items = { [item_id] = { given, taken } } } (copper for gold, counts for items).
bankContrib = { since = nil, players = {} },
standby = {}, -- list of normalized "Name-Realm"
settings = {
officerRankIndex = nil, -- lowest guild rank that counts as officer; 0 is the Guild Master, like GetGuildInfo
Expand Down
133 changes: 116 additions & 17 deletions SideQuest/UI/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4945,7 +4945,8 @@ function UI.RefreshConsolePayouts()
setScrollContentHeight(chamber.scroll, 46 * #rows)
end

-- Bank ledger sub-view
-- Bank sub-view: who has put what into the guild bank (Bank.Contributors, kept across syncs), then the log rows
-- captured since the last sync.
function UI.BuildConsoleBank(panel)
local sub = makeConsoleSub(panel, "Bank")
local chamber = createChamber(sub, "SideQuestConsoleBankChamber")
Expand All @@ -4957,38 +4958,133 @@ function UI.BuildConsoleBank(panel)
SideQuest.Bank.RequestCapture()
end)

local scroll, content = buildScroll(chamber.inner, -58)
chamber.scroll, chamber.content, chamber.rows = scroll, content, {}
local captureHint = makeFontString(chamber.inner, FONT_BODY_ITALIC, 10, C.mist2, "LEFT")
captureHint:SetPoint("TOPLEFT", captureBtn, "BOTTOMLEFT", 0, -4)
captureHint:SetWidth(540)
captureHint:SetText("The game only keeps each tab's latest entries. Open every tab now and then so no gift is missed.")

local scroll, content = buildScroll(chamber.inner, -78)
chamber.scroll, chamber.content, chamber.rows, chamber.contribRows = scroll, content, {}, {}
chamber.captureHint = captureHint
panel.bankChamber = chamber
end

local BANK_TOP_ITEMS = 3

-- "12g 30s and 45 items (~3g at AH)" for what a contributor gave.
local function bankGaveText(c)
local parts = {}
if c.gold_in > 0 then
table.insert(parts, money(c.gold_in))
end
if c.items_in > 0 then
local value = c.item_value > 0 and (" (~" .. money(c.item_value) .. " at AH)") or ""
table.insert(parts, c.items_in .. (c.items_in == 1 and " item" or " items") .. value)
end
return #parts > 0 and table.concat(parts, " and ") or "nothing"
end

-- "2g, 50s in repairs and 5 items" for what a contributor took out.
local function bankTookText(c)
local parts = {}
if c.gold_out > 0 then
table.insert(parts, money(c.gold_out))
end
if c.repairs > 0 then
table.insert(parts, money(c.repairs) .. " in repairs")
end
if c.items_out > 0 then
table.insert(parts, c.items_out .. (c.items_out == 1 and " item" or " items"))
end
return #parts > 0 and table.concat(parts, ", ") or "nothing"
end

local function bankTopItemsText(items)
local parts = {}
for _, item in ipairs(items) do
if item.given == 0 or #parts == BANK_TOP_ITEMS then
break
end
table.insert(parts, SideQuest.ItemName(item.item_id) .. " x" .. item.given)
end
return #parts > 0 and (" Most given: " .. table.concat(parts, ", ") .. ".") or ""
end

function UI.RefreshConsoleBank()
local panel = UI.panels[OFFICER_TAB]
if not panel or not panel.bankChamber then
return
end
local chamber = panel.bankChamber
local rows = SideQuestDB.pending.bank or {}
local contributors = SideQuest.Bank.Contributors()
for _, r in ipairs(chamber.rows) do
r:Hide()
end
for _, r in ipairs(chamber.contribRows) do
r:Hide()
end
if chamber.contribHeading then
chamber.contribHeading:Hide()
chamber.pendingHeading:Hide()
end
if not chamber.emptyText then
chamber.emptyText = makeFontString(chamber.content, FONT_BODY, 12, C.mist2, "LEFT")
chamber.emptyText:SetPoint("TOPLEFT")
end
if not SideQuest.Bank.IsAvailable() then
if not chamber.emptyText then
chamber.emptyText = makeFontString(chamber.content, FONT_BODY, 12, C.mist2, "LEFT")
chamber.emptyText:SetPoint("TOPLEFT")
end
setStateText(chamber.emptyText, "Guild bank log API unavailable here; record deposits/withdrawals on the site.", true)
setScrollContentHeight(chamber.scroll, 0)
return
elseif #rows == 0 then
if not chamber.emptyText then
chamber.emptyText = makeFontString(chamber.content, FONT_BODY, 12, C.mist2, "LEFT")
chamber.emptyText:SetPoint("TOPLEFT")
end
elseif #rows == 0 and #contributors == 0 then
setStateText(chamber.emptyText, "Open the guild bank to read its log; rows appear here automatically.", true)
setScrollContentHeight(chamber.scroll, 0)
return
elseif chamber.emptyText then
chamber.emptyText:SetText("")
end
chamber.emptyText:SetText("")

if not chamber.contribHeading then
chamber.contribHeading = createSubHeading(chamber.content, "Contributors")
chamber.contribHeading:SetWidth(540)
chamber.pendingHeading = createSubHeading(chamber.content, "Waiting to sync")
chamber.pendingHeading:SetWidth(540)
end
local y = 0
local since = SideQuest.Bank.ContributionsSince()
chamber.contribHeading:ClearAllPoints()
chamber.contribHeading:SetPoint("TOPLEFT", 0, -y)
chamber.contribHeading.label:SetText(trackedCaps("Contributors (" .. #contributors .. ")"
.. (since and (" since " .. date("%Y-%m-%d", since)) or "")))
chamber.contribHeading:Show()
y = y + 20
for i, c in ipairs(contributors) do
local row = chamber.contribRows[i]
if not row then
row = CreateFrame("Frame", nil, chamber.content)
row:SetSize(540, 46)
row.titleText = makeFontString(row, FONT_BODY, 13, C.ink, "LEFT")
row.titleText:SetPoint("TOPLEFT")
row.metaText = makeFontString(row, FONT_BODY, 11, C.mist2, "LEFT")
row.metaText:SetPoint("TOPLEFT", row.titleText, "BOTTOMLEFT", 0, -2)
row.metaText:SetWidth(540)
row.metaText:SetWordWrap(true)
chamber.contribRows[i] = row
end
row:ClearAllPoints()
row:SetPoint("TOPLEFT", 0, -y)
row.titleText:SetText(displayName(c.character) .. " -- last used the bank " .. ago(c.last_at))
row.metaText:SetText("Gave " .. bankGaveText(c) .. ". Took " .. bankTookText(c) .. "."
.. bankTopItemsText(c.items))
row:Show()
y = y + 50
end

y = y + 8
chamber.pendingHeading:ClearAllPoints()
chamber.pendingHeading:SetPoint("TOPLEFT", 0, -y)
chamber.pendingHeading.label:SetText(trackedCaps("Waiting to sync (" .. #rows .. ")"))
chamber.pendingHeading:Show()
y = y + 20
for i, b in ipairs(rows) do
local row = chamber.rows[i]
if not row then
Expand All @@ -4998,11 +5094,14 @@ function UI.RefreshConsoleBank()
row.text:SetPoint("LEFT")
chamber.rows[i] = row
end
row:SetPoint("TOPLEFT", 0, -20 * (i - 1))
row.text:SetText(b.kind .. " " .. (b.item_name or "") .. " x" .. (b.count or 0) .. " " .. displayName(b.character or ""))
row:ClearAllPoints()
row:SetPoint("TOPLEFT", 0, -y)
local what = b.money and b.money > 0 and money(b.money) or ((b.item_name or "") .. " x" .. (b.count or 0))
row.text:SetText(b.kind .. " " .. what .. " " .. displayName(b.character or ""))
row:Show()
y = y + 20
end
setScrollContentHeight(chamber.scroll, 20 * #rows)
setScrollContentHeight(chamber.scroll, y)
end

-- Announce sub-view: compose -> toast + guild chat + queued for Discord,
Expand Down
Loading
Loading