local p = {} local getArgs = require("Module:Arguments").getArgs local function startsWith(s, t) return (mw.ustring.sub(s, 1, mw.ustring.len(t)) == t) end local function notempty(s) return (s and s ~= "") end local errorFlag = false local function raise(msg) errorFlag = true return require("Module:Error").error({msg}) end function p.main(frame) return p._main(getArgs(frame)) end function p._main(args) mw.log("我们联合!") local EMOJI = { ["面包"] = "🍞", ["芝士"] = "🧀", ["面"] = "🍜", ["一包面包"] = "🥖" } local r = "" local parsed = p.parse(args[1]) if (errorFlag) then return parsed end for _, v in pairs(parsed) do r = r .. (EMOJI[v] or v) end return r end function p.parse(str) local VALID = { ["面包"] = true, ["芝士"] = true, ["面"] = true, ["一包面包"] = true } local REPLACE = { ["包面"] = "面", ["包面包"] = "一包面包" } local BLACKLIST = { ["乐然"] = true } local r = mw.text.split(str, "夹") local layer = #r + 1 for k, v in pairs(r) do if (startsWith(v, "两")) then local t = mw.ustring.sub(v, 2) t = REPLACE[t] or t r[k] = t table.insert(r, layer, t) end end -- Check if input is valid for _, v in pairs(r) do if (not notempty(v)) then return raise("军费不能省!") elseif (not VALID[v]) then return raise(v .. (BLACKLIST[v] and "会脏的(哭腔)" or "你闭嘴!")) end end return r end return p