Module:Messages

-- The following pages are related: https://fapceo.miraheze.org/wiki/Module:Messages https://fapceo.miraheze.org/wiki/Module:Messages/data

local getArgs = require('Module:Arguments').getArgs local p = {} local inbox = mw.loadData('Module:Messages/data') local inbox_groups = { ["Girls"] = {"Alexis", "Amanda", "Amber", "Anika", "Ayumi", "Cassandra", "Charlotte", "Chloe", "Cressida", "Dalla", "Delilah", "Dita", "Dominique", "Eira", "Holly", "Ingrid", "Judy", "Kelly", "Lana", "Laura", "Lisa", "Lizzie", "Lorelei", "Maria", "Mrs. Claus", "Mrs. Rider", "Nova", "Olivia", "PrincessCumXXX", "Rose", "Sara", "Saya", "Tasha", "Victoria", "Vivian", "Yrelianna", "Zoe"},

["Group Chats"] = {"Group Chat", "Black Friday Group Chat", "Sex Night"}, ["Panoramas"] = {"Summer Chat", "Holiday Wonderland"}, ["News Feed"] = {"Newsfeed"}, }

--[[

-- Generate table for current girl (her page). -- Generate table for GIRL_NAME. -- Generate single table with threads from inbox_groups[GROUP] inboxes. -- Generate table with thrads that picture/video contain current girl (her page). -- Generate table with thrads that picture/video contain GIRL_NAME.

]]

function p.main(frame) local args = getArgs(frame, {parentOnly = true}) if args[1] == "GenerateInbox" and args[2] ~= nil then return p.messages_single(args[2]) elseif args[1] == "GenerateInbox" then local girl_name = mw.title.getCurrentTitle.text return p.messages_single(girl_name) elseif args[1] == "GenerateGroup" and args[2] ~= nil then return p.messages_group(args[2]) elseif args[1] == "GenerateGirlPresent" and args[2] ~= nil then return p.messages_girl_present(args[2]) elseif args[1] == "GenerateGirlPresent" then local girl_name = mw.title.getCurrentTitle.text return p.messages_girl_present(args[2]) end return "" end

-- This function returns rows of a given thread. -- 'girl' parameter is optional to specify to include only pictures with a given girl. -- The beginning and end of the table should be added separately! function add_thread(thread, chat, girl) -- Check if rewards is present in Module:Messages/data if thread.rewards == nil then return " Missing rewards list in Module:Messages/data "..chat.." in "..thread.title end -- Construct Title column. local title = {} local rowspan = 0 local tab = {} if girl == nil then rowspan = #thread.rewards else rowspan = count_girl_in_thread(girl, thread) -- No pictures with girl. Return nothing! if rowspan == 0 then return "" end end if rowspan > 1 then title[#title+1] = "rowspan=\""..rowspan.."\" | " end if thread.thumbnail ~= nil then title[#title+1] = " " end title[#title+1] = " "..thread.title.."" table.insert(tab, "| "..table.concat(title, ""))

-- Go through rewards. for _, reward in ipairs(thread.rewards) do     -- girl == nil -> We want all threads. -- girl ~= nil -> We want only those where girl is present. if girl == nil or is_girl_present(girl, reward.girls) then -- Insert Reward column. table.insert(tab, "| style=\"text-align: center;\" | "..reward.type)

if reward.thumbnail == nil then table.insert(tab, "| N/A") else table.insert(tab, "| ") end

-- Check if unlock is present in Module:Messages/data if reward.unlock == nil then return " Missing unlock list in Module:Messages/data "..name.." in "..thread.title end

local u = {} for _, unlock in ipairs(reward.unlock) do         if unlock.event ~= nil and unlock.cost ~= nil then if unlock.name ~= nil then u[#u+1] = unlock.cost.." from "..""..unlock.name.."" else u[#u+1] = unlock.cost.." from "..""..unlock.event.."" end elseif unlock.other ~= nil then u[#u+1] = unlock.other else u[#u+1] = "Insert Data to Module:Messages/data." end end -- Insert Unlocked For column. Each Event in new line table.insert(tab, "| style=\"text-align: center;\" | "..table.concat(u, " ")) -- Insert end of row. table.insert(tab, "|-") end end return table.concat(tab, "\n") end

-- This function returns inside of the table. -- The beginning and end of the table should be added separately! --[[   local tab = {    '{| class="wikitable" style="width:70%;"',    '|-',      }

table.insert(tab, get_inbox_data(name, thread_data))

-- End table. table.insert(tab, "|}") ]] function get_inbox_data(name, thread_data) if thread_data == nil then return " Missing chat in Module:Messages/data "..name end

local tab = {} table.insert(tab, "! colspan=\"4\" style=\"text-align: center;\" "..                   "|  "..                    thread_data.inbox_title.." "..                    "") table.insert(tab, "|-") table.insert(tab, "! Title") table.insert(tab, "! Reward") table.insert(tab, "! Thumbnail") table.insert(tab, "! Unlocked For") table.insert(tab, "|-")

-- Check if threads is present in Module:Messages/data if thread_data.threads == nil then return table.concat(tab, "\n") --return " Missing threads list in Module:Messages/data "..name end

for _, thread in ipairs(thread_data.threads) do   table.insert(tab, add_thread(thread, name)) end return table.concat(tab, "\n") end

function p.messages_group(frame) if inbox_groups[group] ~= nil then local tab = { '{| class="wikitable" style="width:70%;"', '|-',       }    for _, chat_name in ipairs(inbox_groups[group]) do      table.insert(tab, get_inbox_data(chat_name, inbox[chat_name])) end -- End table. table.insert(tab, "|}") return table.concat(tab, "\n") end return "" end

function p.messages_single(frame) if inbox[single] ~= nil then local tab = { '{| class="wikitable" style="width:70%;"', '|-',       }

table.insert(tab, get_inbox_data(chat_name, inbox[single])) -- End table. table.insert(tab, "|}") return table.concat(tab, "\n") end return "" end

-- Count total occurrences in the whole thread. For rowspan of chat column. function count_girl_in_chat(girl, chat) if chat == nil or chat.threads == nil then return 0 end local count = 0 -- Go through threads for _, thread in ipairs(chat.threads) do   count = count + count_girl_in_thread(girl, thread) end return count end

-- Count total occurrences in the whole thread. For rowspan of thread column. function count_girl_in_thread(girl, thread) if thread == nil then return 0 end local count = 0 -- Go through rewards. for _, reward in ipairs(thread.rewards) do   -- Go through rewards. if is_girl_present(girl, reward.girls) then count = count + 1 end end return count end

-- Simple search if the girl is present in the list. function is_girl_present(girl, girls) for _, girl_name in ipairs(girls) do   if girl_name == girl then return true end end return false end

function p.messages_girl_present(frame) local tab = { '{| class="wikitable" style="width:70%;"', '|-',     }    table.insert(tab, "! colspan=\"5\" style=\"text-align: center;\" | "..                     girl.." can also be found in those Chats and Threads") table.insert(tab, "|-") table.insert(tab, "! Chat") table.insert(tab, "! Title") table.insert(tab, "! Reward") table.insert(tab, "! Thumbnail") table.insert(tab, "! Unlocked For") table.insert(tab, "|-") local count = 0 -- Iterate through all inboxes. for name, thread_data in pairs(inbox) do     local count_all = 0 if (girl ~= name) then count_all = count_girl_in_chat(girl, thread_data) end if count_all > 0 then count = count + 1 -- Construct Chat column. local chat = {} -- Make rowspan correct. if count_all > 1 then chat[#chat+1] = "rowspan=\""..count_all.."\" " end -- Add separator 'settings | data/text' chat[#chat+1] = "| " if thread_data.inbox_picture ~= nil then chat[#chat+1] = " " end chat[#chat+1] = " "..thread_data.inbox_title.."" table.insert(tab, "| style=\"text-align: center; vertical-align:middle;\" "..table.concat(chat, "")) -- Add valid threads. for _, thread in ipairs(thread_data.threads) do       t = add_thread(thread, name, girl) if t ~= nil and t ~= "" then table.insert(tab, t)       end end end end

-- End table. table.insert(tab, "|}") if count > 0 then return table.concat(tab, "\n") else return "" -- Possible return value if there are no other threads showcasing the girl. end end