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 inboxes = 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"}, ["Newsfeed"] = {"Newsfeed"}, }

--[[

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

INBOX_NAME and GROUP should be typed without quotations "" Mrs. Rider NOT "Mrs. Rider" Group Chats NOT "Group Chats"

]]

function p.main(frame) local args = getArgs(frame, {parentFirst = 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(girl_name) end

return "" end

function count_elems(arr) local count = 0 for _, elem in pairs(arr) do   count = count + 1 end return count 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, inbox_name, girl) -- Check if rewards is present in Module:Messages/data if thread.rewards == nil then return " Missing rewards list in Module:Messages/data "..inbox_name.." in "..thread.title end -- Construct Title column. local title = {} local rowspan = 0 local tab = {} if girl == nil then rowspan = count_elems(thread.rewards) else rowspan = count_girl_in_thread(girl, thread) -- No pictures with girl. Return nothing! if rowspan == 0 then return "" end end

title[#title+1] = "style=\"text-align: left;\" " if rowspan > 1 then title[#title+1] = "rowspan=\""..rowspan.."\" " end title[#title+1] = "| " 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 mw.log(reward.thumbnail) mw.log(reward.type) -- Insert Reward column. table.insert(tab, "| "..reward.type)

if reward.thumbnail == nil then table.insert(tab, "| style=\"vertical-align:middle;\" | N/A") else table.insert(tab, "| style=\"vertical-align:middle;\" | ") 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, "| "..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, inbox_data))

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

local tab = {} table.insert(tab, "! colspan=\"4\" style=\"text-align: center;\" "..                   "|  "..                    inbox_data.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 inbox_data.threads == nil then return table.concat(tab, "\n") --return " Missing threads list in Module:Messages/data "..name end

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

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

function p.messages_single(single) if inboxes[single] ~= nil then local tab = { '{| class="wikitable" style="width:85%; text-align: center;"', '|-',       }

table.insert(tab, get_inbox_data(single, inboxes[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(girl) local tab = { '{| class="wikitable" style="width:85%; text-align: center;"', '|-',     }    table.insert(tab, "! colspan=\"5\" | "..                     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, inbox_data in pairs(inboxes) do     local count_all = 0 if (girl ~= name) then count_all = count_girl_in_chat(girl, inbox_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 inbox_data.picture ~= nil then chat[#chat+1] = " " end chat[#chat+1] = " "..inbox_data.title.."" table.insert(tab, "| style=\"vertical-align:middle;\" "..table.concat(chat, "")) -- Add valid threads. for _, thread in ipairs(inbox_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

return p