User:Coffi/Module:ToolbotArchive
-- ToolbotArchive -- MediaWiki Lua module to auto‑close dormant threads after 24 h -- and archive talk pages exceeding 3000 words (WordCounter.net logic) -- -- Usage (in wikitext): -- Script error: No such module "User:Coffi/Module:ToolbotArchive". -- -- No parameters needed – user details are hard‑coded for User:Coffi.
local p = {} local mw = mw
-- CONFIGURATION ---------------------------------------------------
local USER_PAGE = "User talk:Coffi" local ARCHIVE_PREFIX = "User talk:Coffi/Archive/" local WORD_LIMIT = 1 -- words local INACTIVITY_HOURS = 24 -- hours
-- Helper: WordCounter.net‑style word count ------------------------ local function wordCountWCNet(text)
-- WordCounter counts a sequence of alphabetic chars or numbers -- apostrophes inside a word count as part of the word (e.g. "don't" = 1) -- Hyphens split words ("well‑known" = 2) -- Anything else is a delimiter. text = mw.ustring.gsub(text, "[%z\1-\31]", " ") -- replace hyphens with space text = mw.ustring.gsub(text, "‑", " ") local count = 0 for word in mw.ustring.gmatch(text, "[%w']+") do count = count + 1 end return count
end
-- Helper: collapse a thread -------------------------------------- local function collapseThread(threadTitle)
return string.format("
Discussion finished
| ||
---|---|---|
\n== %s ==\n|}", threadTitle)
end -- Main algorithm -------------------------------------------------- function p.run() local page = mw.title.new(USER_PAGE) if not page then return "" end local content = page:getContent() or "" local now = os.time() local modified = false -- Detect section headers and timestamps local newContent = {} local currentSection = {} local sectionTitle = nil local lastTimestamp = nil local function flushSection() if sectionTitle then -- check inactivity if lastTimestamp and (now - lastTimestamp) > INACTIVITY_HOURS*3600 thentable.insert(currentSection, 1, "
|