模块:HttpTest:修订间差异
来自夜幕之下
更多操作
创建页面,内容为“local p = {} function p.test() local url = "https://data.saltedkiss.org/items/cards?limit=1" local res = mw.http.fetch(url) if not res then return "HTTP请求失败" end return "状态码: " .. tostring(res.status) .. "<br>内容:<pre>" .. mw.text.nowiki(res.body) .. "</pre>" end return p” |
无编辑摘要 |
||
| (未显示同一用户的9个中间版本) | |||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
function p. | function p.get(frame) | ||
local cardname = frame.args[1] or "" | |||
local url = "https://data.saltedkiss.org/items/cards?limit=1" | 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 | local rawData = mw.ext.externalData.getExternalData({ | ||
url = url, | |||
format = "json" | |||
}) | |||
if not | if not rawData or #rawData == 0 then | ||
return " | return "No data returned." | ||
end | end | ||
return " | 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 | 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