打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:HttpTest:修订间差异

来自夜幕之下
Rin留言 | 贡献
无编辑摘要
Rin留言 | 贡献
无编辑摘要
 
(未显示同一用户的3个中间版本)
第1行: 第1行:
local p = {}
local p = {}
local function val(v, fallback)
    if v == nil or v == "" then
        return fallback or "—"
    end
    return v
end
-- 用于调试输出表格结构
local function dump(tbl, indent)
    indent = indent or 0
    local formatting = string.rep("  ", indent)
    if type(tbl) ~= "table" then
        return tostring(tbl)
    end
    local str = "{\n"
    for k,v in pairs(tbl) do
        if type(v) == "table" then
            str = str .. formatting .. "  " .. tostring(k) .. " = " .. dump(v, indent+1) .. ",\n"
        else
            str = str .. formatting .. "  " .. tostring(k) .. " = " .. tostring(v) .. ",\n"
        end
    end
    str = str .. formatting .. "}"
    return str
end


function p.get(frame)
function p.get(frame)
     local cardname = frame.args[1] or ""
     local cardname = frame.args[1] or ""
   
 
     local url =
     local url =
         "https://data.saltedkiss.org/items/cards?filter[stylename][_eq]="
         "https://data.saltedkiss.org/items/cards?filter[stylename][_eq]="
         .. mw.uri.encode(cardname)
         .. mw.uri.encode(cardname)
         .. "&limit=1&fields=stylename,rarity,character.name,profession.name,desire.name,"
         .. "&limit=1&fields=*,character.*,profession.*,desire.*,skill_normal_attack.*,skill_passive.*,skill_ultimate.*,feats.stages.*,stories.text"
        .. "skill_normal_attack.name,skill_normal_attack.description,skill_normal_attack.levels,"
 
        .. "skill_passive.name,skill_passive.description,skill_passive.levels,"
    local rawData = mw.ext.externalData.getExternalData({
        .. "skill_ultimate.name,skill_ultimate.description,skill_ultimate.levels,"
        url = url,
         .. "feats.stages,stories.text"
         format = "json"
    })


    -- 调用 External API
     if not rawData or #rawData == 0 then
    local response = mw.ext.jsonapi.get(url)
         return "No data returned."
     if not response or not response.data then
         return "API 请求失败或返回为空"
     end
     end


     local card = response.data[1] or {}
     local cardData = rawData[1].__json.data[1]
 
     if not cardData then
    -- 变量映射
         return "Card not found."
    local stylename = val(card.stylename)
     end
    local rarity = val(card.rarity)
    local character = val(card.character and card.character.name)
    local profession = val(card.profession and card.profession.name)
     local desire = val(card.desire and card.desire.name)
 
    -- 技能
    local skill_normal_attack = {
        name = val(card.skill_normal_attack and card.skill_normal_attack.name),
         description = val(card.skill_normal_attack and card.skill_normal_attack.description),
        levels = card.skill_normal_attack and card.skill_normal_attack.levels or {}
     }


     local skill_passive = {
    -- 创建变量
        name = val(card.skill_passive and card.skill_passive.name),
    local name = cardData.stylename or "—"
        description = val(card.skill_passive and card.skill_passive.description),
     local rarity = cardData.rarity or "—"
        levels = card.skill_passive and card.skill_passive.levels or {}
    local character = cardData.character and cardData.character.name or "—"
    }
    local profession = cardData.profession and cardData.profession.name or "—"
    local desire = cardData.desire and cardData.desire.name or "—"


     local skill_ultimate = {
     local normal = cardData.skill_normal_attack or {}
        name = val(card.skill_ultimate and card.skill_ultimate.name),
     local passive = cardData.skill_passive or {}
        description = val(card.skill_ultimate and card.skill_ultimate.description),
    local ultimate = cardData.skill_ultimate or {}
        levels = card.skill_ultimate and card.skill_ultimate.levels or {}
    }
 
    -- feats
     local feats = {}
    if card.feats and #card.feats > 0 then
        for i, featEntry in ipairs(card.feats) do
            feats[i] = {}
            if featEntry.stages then
                feats[i].stages = {}
                for j, stage in ipairs(featEntry.stages) do
                    feats[i].stages[j] = {
                        stage = stage.stage,
                        extra_name = stage.extra_name,
                        stat_boosts = stage.stat_boosts or {},
                        value = stage.value or {}
                    }
                end
            end
        end
    end


     -- stories
     -- 故事
     local stories = {}
     local stories = cardData.stories or {}
     if card.stories and #card.stories > 0 then
     local storyCount = #stories
        for i, s in ipairs(card.stories) do
    local storyTexts = {}
            stories[i] = s.text or ""
    for i, s in ipairs(stories) do
        end
        table.insert(storyTexts, string.format("%d: %s", i, s.text or ""))
     end
     end


     -- 调试输出
     -- 输出
     local output_table = {
     local out = {}
        stylename = stylename,
    table.insert(out, string.format("卡牌名: %s", name))
        rarity = rarity,
    table.insert(out, string.format("稀有度: %s", rarity))
        character = character,
    table.insert(out, string.format("角色: %s", character))
        profession = profession,
    table.insert(out, string.format("职业: %s", profession))
        desire = desire,
    table.insert(out, string.format("欲望: %s", desire))
        skill_normal_attack = skill_normal_attack,
    table.insert(out, "")
        skill_passive = skill_passive,
    table.insert(out, string.format("普通攻击: %s - %s", normal.name or "—", normal.description or "—"))
        skill_ultimate = skill_ultimate,
    table.insert(out, string.format("被动技能: %s - %s", passive.name or "—", passive.description or "—"))
        feats = feats,
    table.insert(out, string.format("必杀技能: %s - %s", ultimate.name or "—", ultimate.description or "—"))
        stories = stories
    table.insert(out, "")
     }
    table.insert(out, string.format("故事条数: %d", storyCount))
     table.insert(out, table.concat(storyTexts, "\n"))


    -- 直接返回调试字符串
     return table.concat(out, "\n")
     return dump(output_table)
end
end


return p
return p

2026年3月11日 (三) 22:37的最新版本

此模块的文档可以在模块:HttpTest/doc创建

local p = {}

function p.get(frame)
    local cardname = frame.args[1] or ""

    local url =
        "https://data.saltedkiss.org/items/cards?filter[stylename][_eq]="
        .. mw.uri.encode(cardname)
        .. "&limit=1&fields=*,character.*,profession.*,desire.*,skill_normal_attack.*,skill_passive.*,skill_ultimate.*,feats.stages.*,stories.text"

    local rawData = mw.ext.externalData.getExternalData({
        url = url,
        format = "json"
    })

    if not rawData or #rawData == 0 then
        return "No data returned."
    end

    local cardData = rawData[1].__json.data[1]
    if not cardData then
        return "Card not found."
    end

    -- 创建变量
    local name = cardData.stylename or "—"
    local rarity = cardData.rarity or "—"
    local character = cardData.character and cardData.character.name or "—"
    local profession = cardData.profession and cardData.profession.name or "—"
    local desire = cardData.desire and cardData.desire.name or "—"

    local normal = cardData.skill_normal_attack or {}
    local passive = cardData.skill_passive or {}
    local ultimate = cardData.skill_ultimate or {}

    -- 故事
    local stories = cardData.stories or {}
    local storyCount = #stories
    local storyTexts = {}
    for i, s in ipairs(stories) do
        table.insert(storyTexts, string.format("%d: %s", i, s.text or ""))
    end

    -- 输出
    local out = {}
    table.insert(out, string.format("卡牌名: %s", name))
    table.insert(out, string.format("稀有度: %s", rarity))
    table.insert(out, string.format("角色: %s", character))
    table.insert(out, string.format("职业: %s", profession))
    table.insert(out, string.format("欲望: %s", desire))
    table.insert(out, "")
    table.insert(out, string.format("普通攻击: %s - %s", normal.name or "—", normal.description or "—"))
    table.insert(out, string.format("被动技能: %s - %s", passive.name or "—", passive.description or "—"))
    table.insert(out, string.format("必杀技能: %s - %s", ultimate.name or "—", ultimate.description or "—"))
    table.insert(out, "")
    table.insert(out, string.format("故事条数: %d", storyCount))
    table.insert(out, table.concat(storyTexts, "\n"))

    return table.concat(out, "\n")
end

return p