-- ============================================ -- 落叶科技旗下作者:无敌老猫开发,以下不懂的不要乱动 -- ============================================ -- ===== 集中配置区(改这里就行) ===== local CONFIG = { -- API 地址 API_LIST = "http://wl.luoyeyun.icu/api/gsh/list.php", API_NOTICE = "https://wl.luoyeyun.icu/api/gsh/Notice.php", API_SEND = "https://wl.luoyeyun.icu/api/gsh/send.php", -- UI 常量 LOGO = '🍃🍃🍃🍃🍃🍃🍃🍃🍃🍃🍃🍃🍃🍃🍃🍃🍃', NICKNAME = "落叶科技", USER_LEVEL = 0, -- 菜单文本 MENU_TITLE = '工具箱', TEXT_SEARCH = '搜索应用', TEXT_BACK = '返回上一页', TEXT_EXIT = '退出脚本', TEXT_CANCEL = '已取消', TEXT_ALERT_NO_RESULT = '没有关键词为 "%s" 的应用哦~', TEXT_ALERT_FIRST_PAGE = '已是初始页~', TEXT_ALERT_NOT_IMPL = "功能未实现", } -- ===== 内部状态(集中管理) ===== local STATE = { deposit = {}, -- 页面栈 containerId = {}, -- 主菜单项 containerId2 = {}, -- 功能回调映射 } -- 初始化 deposit 栈 STATE.deposit[1] = STATE.containerId -- ============================================ -- 工具函数(原封不动) -- ============================================ local function urlencode(str) if not str then return "" end str = tostring(str):gsub("\n", "\r\n") return str:gsub("([^%w%-%.%_%~])", function(c) return string.format("%%%02X", string.byte(c)) end) end local function fetchAll() local resp = gg.makeRequest(CONFIG.API_LIST) if not resp then return "网络请求失败" end local raw = resp.content or resp.Content or resp.data or "" if raw == "" then return "服务器返回空内容" end local j = table.json(raw) if not j or not j.list then return "无消息列表" end local t = {} for _, v in ipairs(j.list) do table.insert(t, ("\n%s-[%s]: %s\n%s\n"):format(v.u, v.l or "", v.m, v.t)) end return table.concat(t, "\n") end -- ============================================ -- 聊天室模块 -- ============================================ Cloud = {} Cloud.Chat = function(n, userLevel) local logo = CONFIG.LOGO local yn = "" local ok, resp = pcall(gg.makeRequest, CONFIG.API_NOTICE) if ok and resp and resp.content then yn = resp.content end local by = yn while true do local chatText = fetchAll() local panelText = logo .. "\n" .. by .. "\n".. logo .."\n" .. chatText .. "\n\n" .. logo .. "\n【输入消息】" local input = gg.prompt({ panelText }, nil, { "text" }) if not input or input[1] == "" then gg.toast(CONFIG.TEXT_CANCEL) return end local encodedUser = urlencode(n or "匿名") local encodedMsg = urlencode(input[1]) local totalParam = userLevel or 0 local url = string.format( "%s?user=%s&message=%s&total=%s", CONFIG.API_SEND, encodedUser, encodedMsg, tostring(totalParam) ) local ret = gg.makeRequest(url) -- 处理响应(新逻辑:HTTP 200 + JSON code 判断) if not ret or ret.code ~= 200 then gg.toast("网络请求失败 (HTTP " .. tostring(ret and ret.code or "未知") .. ")") else local ok2, js = pcall(table.json, ret.content or ret.Content or ret.data or "") if ok2 and js and js.code == 200 then gg.toast("发送成功") elseif ok2 and js and js.code == 429 then local remain = js.remaining_seconds or "几" gg.toast("发送太快,请等待 " .. remain .. " 秒后再试") else gg.toast("发送失败") end end end end -- ============================================ -- 菜单数据初始化 -- ============================================ STATE.containerId[#STATE.containerId + 1] = '▤管理菜单' STATE.containerId[#STATE.containerId + 1] = '\n功能名称: 聊天室\n最后更新: 2023-12-10 08:19\n\n' STATE.containerId2 = {} for _, v in pairs(STATE.containerId) do if v ~= '▤管理菜单' then STATE.containerId2[#STATE.containerId2 + 1] = v end end STATE.containerId2[1] = function() Cloud.Chat(CONFIG.NICKNAME, CONFIG.USER_LEVEL) end -- ============================================ -- 主菜单逻辑 -- ============================================ primaryMenu = function(first) while true do if gg.isVisible(true) then ::main:: local page = (#STATE.deposit == 1) and '' or ('(第' .. #STATE.deposit .. '页)') local title = string.format('%s\n共有%d个应用 %s', CONFIG.MENU_TITLE, #STATE.deposit[#STATE.deposit] - 1, page) C1 = gg.choice(first, nil, title) if C1 then if first[C1] == '▤管理菜单' then local search = {} search[#search + 1] = CONFIG.TEXT_SEARCH if #STATE.deposit > 1 then search[#search + 1] = CONFIG.TEXT_BACK end search[#search + 1] = CONFIG.TEXT_EXIT ::main2:: C2 = gg.choice(search, nil, '▤管理菜单') if C2 then if search[C2] == CONFIG.TEXT_SEARCH then P1 = gg.prompt({'请输入关键词'}, nil, {'text'}) if P1 and P1[1] ~= "" then local _1 = {} _1[#_1 + 1] = '▤管理菜单' for i = 2, #first do if string.find(string.lower(first[i]), string.lower(P1[1]), 1, true) then table.insert(_1, first[i]) end end if #_1 < 2 then gg.alert(string.format(CONFIG.TEXT_ALERT_NO_RESULT, P1[1])) goto main end STATE.deposit[#STATE.deposit + 1] = _1 primaryMenu(_1) else goto main2 end elseif search[C2] == CONFIG.TEXT_BACK then if #STATE.deposit == 1 then gg.alert(CONFIG.TEXT_ALERT_FIRST_PAGE) goto main end STATE.deposit[#STATE.deposit] = nil primaryMenu(STATE.deposit[#STATE.deposit]) elseif search[C2] == CONFIG.TEXT_EXIT then os.exit() end else goto main end else local fun = nil for i = 1, #STATE.containerId do if first[C1] == STATE.containerId[i] then fun = i - 1 break end end if fun and STATE.containerId2[fun] then STATE.containerId2[fun]() else gg.alert(CONFIG.TEXT_ALERT_NOT_IMPL) end goto main end end gg.setVisible(false) end end end menuControl = STATE.containerId primaryMenu(menuControl)