koishi-plugin-pixluna
Version:
1 lines • 41.6 kB
JavaScript
var e=Object.create,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,i=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,n=(n,o,c)=>(c=null!=n?e(i(n)):{},((e,i,n,o)=>{if(i&&"object"==typeof i||"function"==typeof i)for(var c,l=a(i),u=0,g=l.length;u<g;u++)c=l[u],s.call(e,c)||c===n||t(e,c,{get:(e=>i[e]).bind(null,c),enumerable:!(o=r(i,c))||o.enumerable});return e})(!o&&n&&n.__esModule?c:t(c,"default",{value:n,enumerable:!0}),n));const o=n(require("koishi")),c=n(require("pyodide")),l=n(require("node:crypto")),u={};let g=-1;var d=class{pool;limit;constructor(e){this.pool=[],this.limit=e}add(e){const t=Array.isArray(e)?e:[e];for(const e of t)this.pool.push(e);return this}async run(){const e=[];for(let t=0;t<this.pool.length;t+=this.limit){const r=this.pool.slice(t,t+this.limit);e.push(...await Promise.all(r))}return e}};async function p(e,t,r){return await r()}let h=null,f=!1;async function m(){if(h&&f)return h;if(h||(h=await(0,c.loadPyodide)(),q.debug("Installing packages from Pyodide distribution..."),await h.loadPackage(["https://cdn.jsdelivr.net/pyodide/v0.28.0/full/pillow-11.2.1-cp313-cp313-pyodide_2025_0_wasm32.whl","https://cdn.jsdelivr.net/pyodide/v0.28.0/full/numpy-2.2.5-cp313-cp313-pyodide_2025_0_wasm32.whl"]),q.debug("Successfully installed packages from Pyodide distribution")),!f){try{h.runPython("\ntry:\n from PIL import Image\n import numpy as np\n print('PIL and numpy imported successfully')\nexcept ImportError as e:\n print(f'Import error: {e}')\n raise e\n ")}catch(e){throw q.error("Failed to import required packages:",e),new Error("Required packages are not available")}h.runPython("\nimport io\nimport base64\nfrom PIL import Image\nimport numpy as np\nfrom js import Uint8Array\n\ndef buffer_to_image(buffer_data):\n buffer_bytes = bytes(buffer_data)\n return Image.open(io.BytesIO(buffer_bytes))\n\ndef image_to_buffer(image, format='PNG', quality=None):\n buffer = io.BytesIO()\n if format.upper() == 'PNG':\n if quality is not None:\n image.save(buffer, format=format, optimize=True)\n else:\n image.save(buffer, format=format)\n else:\n if quality is not None:\n image.save(buffer, format=format, quality=quality)\n else:\n image.save(buffer, format=format)\n return buffer.getvalue()\n\ndef compress_image(buffer_data, quality=80):\n image = buffer_to_image(buffer_data)\n\n if quality < 100:\n if image.mode in ('RGBA', 'LA', 'P'):\n background = Image.new('RGB', image.size, (255, 255, 255))\n if image.mode == 'P':\n image = image.convert('RGBA')\n background.paste(image, mask=image.split()[-1] if image.mode in ('RGBA', 'LA') else None)\n image = background\n elif image.mode != 'RGB':\n image = image.convert('RGB')\n return image_to_buffer(image, 'JPEG', quality)\n else:\n return image_to_buffer(image, 'PNG')\n\ndef mix_image_pixels(buffer_data):\n image = buffer_to_image(buffer_data)\n\n if image.mode != 'RGB':\n image = image.convert('RGB')\n\n width, height = image.size\n\n pixels = image.load()\n\n import random\n x = random.randint(0, width - 1)\n y = random.randint(0, height - 1)\n\n r, g, b = pixels[x, y]\n\n r = min(255, r + 1) if r < 255 else max(0, r - 1)\n g = min(255, g + 1) if g < 255 else max(0, g - 1)\n b = min(255, b + 1) if b < 255 else max(0, b - 1)\n\n pixels[x, y] = (r, g, b)\n\n return image_to_buffer(image, 'PNG')\n\ndef flip_image(buffer_data, mode='none'):\n image = buffer_to_image(buffer_data)\n\n if mode == 'horizontal':\n image = image.transpose(Image.FLIP_LEFT_RIGHT)\n elif mode == 'vertical':\n image = image.transpose(Image.FLIP_TOP_BOTTOM)\n elif mode == 'both':\n image = image.transpose(Image.FLIP_LEFT_RIGHT)\n image = image.transpose(Image.FLIP_TOP_BOTTOM)\n\n return image_to_buffer(image, 'PNG')\n "),f=!0}return h}async function y(e,t,r){const a=await m(),i=new Uint8Array(t);a.globals.set("buffer_data",i),a.globals.set("quality",r.imageProcessing.compressQuality);const s=a.runPython("\ncompressed_buffer = compress_image(buffer_data, quality)\ncompressed_buffer\n ");return Buffer.from(s)}async function w(e,t,r,a){let i=t;return r.imageProcessing.isFlip&&(i=await async function(e,t,r){const a=await m(),i=new Uint8Array(t);a.globals.set("buffer_data",i),a.globals.set("mode",r||"none");const s=a.runPython("\nflipped_buffer = flip_image(buffer_data, mode)\nflipped_buffer\n ");return Buffer.from(s)}(0,i,r.imageProcessing.flipMode)),r.imageProcessing.confusion?await async function(e,t,r){r.imageProcessing.compress&&(t=await y(0,t,r));const a=await m(),i=new Uint8Array(t);a.globals.set("buffer_data",i);const s=a.runPython("\nmixed_buffer = mix_image_pixels(buffer_data)\nmixed_buffer\n ");return Buffer.from(s)}(0,i,r):r.imageProcessing.compress&&!a?await y(0,i,r):i}var b=class{static description;config;ctx;constructor(e,t){this.ctx=e,this.config=t}};function x(e){const t=`--${e}--`,r=(0,l.createHash)("sha1");return r.update(t),r.digest("hex")}var P=class extends b{constructor(e,t){super(e,t),this.ctx=e,this.config=t}async getMetaData({context:e},t){let r=[];t.tag&&(r=t.tag.split(/[,\uff0c]/).map((e=>e.trim())).filter(Boolean));const a={r18:this.config.isR18&&t.r18?1:0,num:1,size:t.size,keyword:0===r.length?t.tag:void 0,tag:r.length>0?r:void 0,excludeAI:t.excludeAI,proxy:t.proxy},i=await e.http.post(this.API_URL,a,{proxyAgent:this.config.isProxy?this.config.proxyHost:void 0});if(i.error||!i.data||0===i.data.length)return{status:"error",data:new Error(i.error||"No image data returned")};const s=i.data[0],n=this.config.imageProcessing.compress?s.urls.original:s.urls.regular||s.urls.original,o={id:s.pid,title:s.title,author:s.author,r18:s.r18,tags:s.tags,extension:s.ext,aiType:s.aiType,uploadDate:s.uploadDate,urls:s.urls};return q.debug("\u6210\u529f\u83b7\u53d6\u56fe\u7247\u5143\u6570\u636e",{metadata:o}),{status:"success",data:{url:n,urls:{regular:s.urls.regular,original:s.urls.original},raw:o}}}setConfig(e){this.config=e}getMeta(){return{referer:"https://www.pixiv.net/"}}};function _(e){if(e.length<=1)return[...e];const t=[...e],r=new Uint32Array(t.length);l.webcrypto.getRandomValues(r);for(let e=t.length-1;e>0;e--){const a=r[e]%(e+1);[t[e],t[a]]=[t[a],t[e]]}return t}function S(e,t){const r=[o.h.image(e.data,e.mimeType),(0,o.h)("text",{content:`\ntitle\uff1a${e.title}\n`}),(0,o.h)("text",{content:`id\uff1a${e.id}\n`})];return!1!==t?.showTags&&r.push((0,o.h)("text",{content:`tags\uff1a${e.tags.map((e=>`#${e}`)).join(" ")}\n`})),(0,o.h)("",r)}function I(e,t){return(0,o.h)("",[(0,o.h)("at",{id:e}),(0,o.h)("text",{content:` ${t}`})])}async function k(e=0,t=!0){(!t||e>0)&&await new Promise((e=>setTimeout(e,2e3)))}function A(e){if(!e)return[];return e.split(/[,\uff0c]/).map((e=>e.trim())).filter(Boolean).slice(0,5)}function v(e,t){if(!t.length)return!0;const r=e.title?.toLowerCase()||"",a=Array.isArray(e.tags)?e.tags.map((e=>"string"==typeof e?e.toLowerCase():e.tag?.toLowerCase()||"")):[];return t.every((e=>{const t=e.toLowerCase();return r.includes(t)||a.some((e=>"string"==typeof e&&e.includes(t)))}))}var D=class extends b{getHeaders(){return{Referer:"https://www.pixiv.net/","User-Agent":j,Cookie:`PHPSESSID=${this.config.pixiv.phpSESSID}`}}getProxyAgent(){return this.config.isProxy?this.config.proxyHost:void 0}constructImageUrl(e){const t=this.config.baseUrl||"i.pximg.net";return e.replace("i.pximg.net",t)}async fetchPixivData(e,t){return await e.http.get(t,{headers:this.getHeaders(),proxyAgent:this.getProxyAgent()})}setConfig(e){this.config=e}getMeta(){return{referer:"https://www.pixiv.net/"}}},R=class e extends D{static description="\u901a\u8fc7\u4f5c\u54c1ID\u83b7\u53d6Pixiv\u56fe\u7247";static ILLUST_URL="https://www.pixiv.net/ajax/illust/{ARTWORK_ID}";async getImageByPid(e,t,r=0){if(!this.config.pixiv.phpSESSID)return{status:"error",data:new Error("\u672a\u8bbe\u7f6e Pixiv PHPSESSID")};try{const a=await this.getIllustDetail(e,t);if(a.error||!a.body)return{status:"error",data:new Error("\u65e0\u6cd5\u83b7\u53d6\u63d2\u753b\u8be6\u60c5")};const i=a.body,s=i.urls.original.split("_p");if(2!==s.length)return{status:"error",data:new Error("\u56fe\u7247URL\u683c\u5f0f\u9519\u8bef")};const n=`${s[0]}_p${r}${s[1].substring(s[1].indexOf("."))}`;if(r>=i.pageCount)return{status:"error",data:new Error(`\u9875\u7801\u8d85\u51fa\u8303\u56f4\uff0c\u8be5\u4f5c\u54c1\u5171\u6709 ${i.pageCount} \u9875`)};const o={id:parseInt(i.id),title:i.title,author:i.userName,r18:i.xRestrict>0,tags:i.tags.tags.map((e=>e.tag)),extension:n.split(".").pop(),aiType:0,uploadDate:new Date(i.createDate).getTime(),urls:{original:this.constructImageUrl(n)}};return q.debug("\u6210\u529f\u83b7\u53d6 Pixiv \u56fe\u7247\u5143\u6570\u636e",{metadata:o}),{status:"success",data:{url:o.urls.original,urls:o.urls,raw:o}}}catch(e){return q.error("\u83b7\u53d6 Pixiv \u56fe\u7247\u5143\u6570\u636e\u5931\u8d25",{error:e}),{status:"error",data:e}}}async getIllustDetail(t,r){const a=e.ILLUST_URL.replace("{ARTWORK_ID}",r);return await t.http.get(a,{headers:this.getHeaders(),proxyAgent:this.getProxyAgent()})}async getMetaData(){return{status:"error",data:new Error("This provider only supports getting images by ID")}}async getImageWithBuffer(e,t=0){const r=await this.getImageByPid(this.ctx,e,t);if("error"===r.status)throw r.data;const[a,i]=await U(this.ctx,this.config,r.data.url,this);return{data:Buffer.from(a),mimeType:i,id:r.data.raw.id,title:r.data.raw.title,tags:r.data.raw.tags,author:r.data.raw.author,r18:r.data.raw.r18,extension:r.data.raw.extension,aiType:r.data.raw.aiType,uploadDate:r.data.raw.uploadDate,urls:r.data.raw.urls}}async getImageWithAtMessage(e,t){if(!t.pid)return I(e,"\u8bf7\u63d0\u4f9b\u4f5c\u54c1 ID (PID)");try{return S(await this.getImageWithBuffer(t.pid,t.page),this.config)}catch(t){this.ctx.logger.error(t);return I(e,(t instanceof Error?t.message:String(t))||"\u83b7\u53d6\u56fe\u7247\u5931\u8d25")}}async getAllImagesWithAtMessage(e,t){if(!t.pid)return I(e,"\u8bf7\u63d0\u4f9b\u4f5c\u54c1 ID (PID)");try{const r=await this.getIllustDetail(this.ctx,t.pid);if(r.error||!r.body)return I(e,"\u65e0\u6cd5\u83b7\u53d6\u63d2\u753b\u8be6\u60c5");const a=r.body.pageCount||1;if(1===a){return S(await this.getImageWithBuffer(t.pid,0),this.config)}const i=[];for(let e=0;e<a;e++){await k(e);const r=await this.getImageWithBuffer(t.pid,e);i.push(r)}return function(e,t){const r=[],a=e[0];return r.push((0,o.h)("text",{content:`title\uff1a${a.title}\n`}),(0,o.h)("text",{content:`id\uff1a${a.id}\n`}),(0,o.h)("text",{content:`\u5171 ${e.length} \u9875\n\n`})),!1!==t?.showTags&&r.push((0,o.h)("text",{content:`tags\uff1a${a.tags.map((e=>`#${e}`)).join(" ")}\n\n`})),e.forEach(((e,t)=>{r.push((0,o.h)("text",{content:`\u7b2c ${t+1} \u9875:\n`}),o.h.image(e.data,e.mimeType),(0,o.h)("text",{content:"\n"}))})),(0,o.h)("",r)}(i,this.config)}catch(t){this.ctx.logger.error(t);return I(e,(t instanceof Error?t.message:String(t))||"\u83b7\u53d6\u56fe\u7247\u5931\u8d25")}}};const T={danbooru:class extends b{static description="\u901a\u8fc7 Danbooru API \u83b7\u53d6\u56fe\u7247";endpoint="https://danbooru.donmai.us";keyPairs=[];setConfig(e){this.config=e,e.danbooru?.keyPairs?.length&&(this.keyPairs=e.danbooru.keyPairs)}get keyPair(){return this.keyPairs.length?this.keyPairs[Math.floor(Math.random()*this.keyPairs.length)]:null}async getMetaData({context:e},t){try{const r=this.keyPair;let a="";t.tag&&(a=t.tag.split(/[,\uff0c]/).map((e=>e.trim())).filter(Boolean).join(" "));const i={tags:a,random:!0,limit:1,...r?{login:r.login,api_key:r.apiKey}:{}};this.config.isR18&&t.r18?i.tags+=" rating:explicit":i.tags+=" rating:safe";const s=await e.http.get(`${this.endpoint}/posts.json`,{params:i,proxyAgent:this.config.isProxy?this.config.proxyHost:void 0});if(!Array.isArray(s)||0===s.length)return{status:"error",data:new Error("No image data returned")};const n=s[0],o=this.config.imageProcessing.compress?n.large_file_url:n.file_url,c={id:n.id,title:"",author:n.tag_string_artist.replace(/_/g," "),r18:"e"===n.rating||"q"===n.rating,tags:n.tag_string.split(" "),extension:n.file_url.split(".").pop(),aiType:0,uploadDate:new Date(n.created_at).getTime(),urls:{original:n.file_url,regular:n.large_file_url}};return q.debug("\u6210\u529f\u83b7\u53d6\u56fe\u7247\u5143\u6570\u636e",{metadata:c}),{status:"success",data:{url:o,urls:{regular:n.large_file_url,original:n.file_url},raw:c}}}catch(e){return{status:"error",data:e}}}getMeta(){return{referer:"https://danbooru.donmai.us"}}},e621:class extends b{static description="\u901a\u8fc7 E621 API \u83b7\u53d6\u56fe\u7247";endpoint="https://e621.net";keyPairs=[];setConfig(e){this.config=e,e.e621?.keyPairs?.length&&(this.keyPairs=e.e621.keyPairs)}get keyPair(){return this.keyPairs.length?this.keyPairs[Math.floor(Math.random()*this.keyPairs.length)]:null}async getMetaData({context:e},t){try{const r=this.keyPair;let a="";t.tag&&(a=t.tag.split(/[,\uff0c]/).map((e=>e.trim())).filter(Boolean).join(" "));const i={tags:`${a} order:random`,limit:1};this.config.isR18&&t.r18?i.tags+=" -rating:s":i.tags+=" rating:s";const s={"User-Agent":"PixLuna/1.0"};r&&(s.Authorization="Basic "+Buffer.from(`${r.login}:${r.apiKey}`).toString("base64"));const n=await e.http.get(`${this.endpoint}/posts.json`,{params:i,headers:s,proxyAgent:this.config.isProxy?this.config.proxyHost:void 0});if(!Array.isArray(n.posts)||0===n.posts.length)return{status:"error",data:new Error("No image data returned")};const o=n.posts[0],c=this.config.imageProcessing.compress?o.sample.url:o.file.url,l={id:o.id,title:"",author:o.tags.artist.join(", "),r18:"s"!==o.rating,tags:[...o.tags.general,...o.tags.artist],extension:o.file.url.split(".").pop(),aiType:0,uploadDate:new Date(o.created_at).getTime(),urls:{original:o.file.url,regular:o.sample.url}};return q.debug("\u6210\u529f\u83b7\u53d6\u56fe\u7247\u5143\u6570\u636e",{metadata:l}),{status:"success",data:{url:c,urls:{regular:o.sample.url,original:o.file.url},raw:l}}}catch(e){return{status:"error",data:e}}}getMeta(){return{referer:"https://e621.net"}}},gelbooru:class extends b{static description="\u901a\u8fc7 Gelbooru API \u83b7\u53d6\u56fe\u7247";endpoint="https://gelbooru.com/index.php";get keyPair(){const e=this.config.gelbooru?.keyPairs||[];return e.length?e[Math.floor(Math.random()*e.length)]:null}async getMetaData({context:e},t){let r="";t.tag&&(r=t.tag.split(/[,\uff0c]/).map((e=>e.trim())).filter(Boolean).join(" "));const a=new URLSearchParams({page:"dapi",s:"post",q:"index",json:"1",limit:"1",tags:`${r} sort:random${this.config.isR18&&t.r18?"":" rating:safe"}`}),i=this.keyPair;i&&a.append("api_key",i.apiKey);const s=`${this.endpoint}?${a.toString()}`;try{const t=await e.http.get(s,{proxyAgent:this.config.isProxy?this.config.proxyHost:void 0});if(!t.post?.length)return{status:"error",data:new Error("No image data returned")};const r=t.post[0],a={id:r.id,title:r.source||`Gelbooru - ${r.id}`,author:r.owner.replace(/_/g," "),r18:["explicit","questionable"].includes(r.rating),tags:r.tags.split(" "),extension:r.file_url.split(".").pop(),uploadDate:new Date(r.created_at).getTime(),aiType:0,urls:{original:r.file_url,regular:r.sample_url}};return q.debug("\u6210\u529f\u83b7\u53d6\u56fe\u7247\u5143\u6570\u636e",{metadata:a}),{status:"success",data:{url:this.config.imageProcessing.compress?r.file_url:r.sample_url,urls:{regular:r.sample_url,original:r.file_url},raw:a}}}catch(e){return{status:"error",data:e}}}getMeta(){return{referer:"https://gelbooru.com/"}}setConfig(e){this.config=e}},konachan:class extends b{static description="\u901a\u8fc7 Konachan API \u83b7\u53d6\u56fe\u7247";endpoint="https://konachan.com";keyPairs=[];hashPassword(e){const t=`So-I-Heard-You-Like-Mupkids-?--${e}--`,r=(0,l.createHash)("sha1");return r.update(t),r.digest("hex")}setConfig(e){this.config=e,e.konachan?.keyPairs?.length&&(this.keyPairs=e.konachan.keyPairs)}get keyPair(){if(!this.keyPairs.length)return null;const e=this.keyPairs[Math.floor(Math.random()*this.keyPairs.length)];return{login:e.login,password_hash:this.hashPassword(e.password)}}async getMetaData({context:e},t){try{const r=this.keyPair;let a="";t.tag&&(a=t.tag.split(/[,\uff0c]/).map((e=>e.trim())).filter(Boolean).join(" "));const i={tags:`order:random ${a}`.trim(),limit:1,api_version:2,...r&&{login:r.login,password_hash:r.password_hash,auth:!0}};this.config.isR18&&t.r18?i.tags=`${i.tags} rating:questionable rating:explicit`.trim():i.tags=`${i.tags} rating:safe`.trim(),q.debug("\u8bf7\u6c42\u53c2\u6570",i);const s=await e.http.get(`${this.endpoint}/post.json`,{params:i,proxyAgent:this.config.isProxy?this.config.proxyHost:void 0});if(!Array.isArray(s)||0===s.length)return{status:"error",data:new Error("No image data returned")};const n=s[0],o=this.config.imageProcessing.compress?n.sample_url:n.file_url,c={id:n.id,title:"",author:n.author.replace(/_/g," "),r18:"e"===n.rating||"q"===n.rating,tags:n.tags.split(" "),extension:n.file_url.split(".").pop(),aiType:0,uploadDate:new Date(n.created_at).getTime(),urls:{original:n.file_url,regular:n.sample_url}};return q.debug("\u6210\u529f\u83b7\u53d6\u56fe\u7247\u5143\u6570\u636e",{metadata:c}),{status:"success",data:{url:o,urls:{regular:n.sample_url,original:n.file_url},raw:c}}}catch(e){return q.error("Konachan\u8bf7\u6c42\u5931\u8d25",e),{status:"error",data:e}}}getMeta(){return{referer:"https://konachan.com"}}},lolibooru:class extends b{static description="\u901a\u8fc7 Lolibooru API \u83b7\u53d6\u56fe\u7247";endpoint="https://lolibooru.moe";keyPairs=[];setConfig(e){this.config=e,e.lolibooru?.keyPairs?.length&&(this.keyPairs=e.lolibooru.keyPairs)}get keyPair(){if(!this.keyPairs.length)return null;const e=this.keyPairs[Math.floor(Math.random()*this.keyPairs.length)];return{login:e.login,password_hash:x(e.password)}}async getMetaData({context:e},t){try{const r=this.keyPair;let a="";t.tag&&(a=t.tag.split(/[,\uff0c]/).map((e=>e.trim())).filter(Boolean).join(" "));const i={tags:`${a} order:random`,limit:"1"};this.config.isR18&&t.r18?i.tags+=" -rating:s":i.tags+=" rating:s",r&&(i.login=r.login,i.password_hash=r.password_hash);const s=await e.http.get(`${this.endpoint}/post/index.json`,{params:i,proxyAgent:this.config.isProxy?this.config.proxyHost:void 0});if(!Array.isArray(s)||0===s.length)return{status:"error",data:new Error("No image data returned")};const n=s[0],o=this.config.imageProcessing.compress?n.sample_url:n.file_url,c={id:n.id,title:n.source||`Lolibooru - ${n.id}`,author:n.author.replace(/_/g," "),r18:["e","q"].includes(n.rating),tags:n.tags.split(" "),extension:n.file_url.split(".").pop(),aiType:0,uploadDate:new Date(n.created_at).getTime(),urls:{original:encodeURI(n.file_url),regular:encodeURI(n.sample_url)}};return q.debug("\u6210\u529f\u83b7\u53d6\u56fe\u7247\u5143\u6570\u636e",{metadata:c}),{status:"success",data:{url:encodeURI(o),urls:{regular:encodeURI(n.sample_url),original:encodeURI(n.file_url)},raw:c}}}catch(e){return{status:"error",data:e}}}getMeta(){return{referer:"https://lolibooru.moe"}}},lolicon:class extends P{static description="\u901a\u8fc7 Lolicon API \u83b7\u53d6\u56fe\u7247";API_URL="https://api.lolicon.app/setu/v2"},lolisuki:class extends P{static description="\u901a\u8fc7 Lolisuki API \u83b7\u53d6\u56fe\u7247";API_URL="https://lolisuki.cn/api/setu/v1"},pdiscovery:class e extends D{static DISCOVERY_URL="https://www.pixiv.net/ajax/illust/discovery";static ILLUST_PAGES_URL="https://www.pixiv.net/ajax/illust/{ARTWORK_ID}/pages";async getMetaData({context:t},r){try{const a=A(r.tag),i=`${e.DISCOVERY_URL}?mode=${this.config.isR18&&r.r18?"r18":"all"}&limit=20`,s=await this.fetchPixivData(t,i);if(s.error||!s.body.illusts.length)return{status:"error",data:new Error(s.message||"\u672a\u627e\u5230\u63d2\u753b")};let n=function(e,t){if(!t.length||!e.length)return e;for(let r=t.length;r>0;r--){const a=t.slice(0,r),i=e.filter((e=>v(e,a)));if(i.length>0)return i}return e}(s.body.illusts,a);if(this.config.isR18||(n=n.filter((e=>!(e.xRestrict>0||e.tags.some((e=>"r-18"===e.toLowerCase())))))),0===n.length)return{status:"error",data:new Error(`\u672a\u627e\u5230\u5305\u542b\u6807\u7b7e "${a.join(", ")}" \u7684\u63d2\u753b`)};const o=_(n)[0],c=e.ILLUST_PAGES_URL.replace("{ARTWORK_ID}",o.id),l=await t.http.get(c,{headers:this.getHeaders(),proxyAgent:this.getProxyAgent()});if(l.error||!l.body.length)return{status:"error",data:new Error("\u65e0\u6cd5\u83b7\u53d6\u539f\u56fe\u94fe\u63a5")};const u=this.config.baseUrl||"i.pximg.net",g=l.body[0].urls.original.replace("i.pximg.net",u),d={id:parseInt(o.id),title:o.title,author:o.userName,r18:o.xRestrict>0,tags:o.tags,extension:g.split(".").pop(),aiType:0,uploadDate:new Date(o.createDate).getTime(),urls:{original:g,regular:o.url.replace("i.pximg.net",u)}};return{status:"success",data:{url:g,urls:d.urls,raw:d}}}catch(e){return q.error("\u83b7\u53d6 Pixiv Discovery \u5143\u6570\u636e\u5931\u8d25",{error:e}),{status:"error",data:e}}}},pfollowing:class e extends D{static description="\u83b7\u53d6 Pixiv \u5df2\u5173\u6ce8\u753b\u5e08\u4f5c\u54c1\uff0c\u9700\u8981 Pixiv \u8d26\u53f7";static FOLLOWING_URL="https://www.pixiv.net/ajax/user/{USER_ID}/following?offset={OFFSET_COUNT}&limit={LIMIT_COUNT}&rest=show";static USER_PROFILE_URL="https://www.pixiv.net/ajax/user/{USER_ID}/profile/all";static ILLUST_URL="https://www.pixiv.net/ajax/illust/{ARTWORK_ID}";async getMetaData({context:e},t){if(!this.config.pixiv.phpSESSID)return{status:"error",data:new Error("\u672a\u8bbe\u7f6e Pixiv PHPSESSID")};const r=A(t?.tag);try{const t=await this.getAllFollowingUsers(e);if(!t.length)return{status:"error",data:new Error("\u672a\u627e\u5230\u5173\u6ce8\u7684\u7528\u6237")};const a=[],i=new Set;let s=0;const n=Math.min(t.length,10),o=_(t);for(;s<n&&a.length<20;){await k(s);const t=o[s];if(s++,i.has(t.userId))continue;i.add(t.userId);const n=await this.getUserProfile(e,t.userId);if(n.error||!n.body.illusts)continue;const c=Object.entries(n.body.illusts).map((([e,t])=>({id:e,...t})));if(!(r.length>0))break;for(const t of c)try{await k(0,!1);const i=await this.getIllustDetail(e,t.id);if(!i.error&&i.body){const e=i.body.xRestrict>0||i.body.tags.tags.some((e=>"r-18"===e.tag.toLowerCase()));!this.config.isR18&&e||!v(i.body,r)||a.push(i.body)}}catch(e){}}if(r.length>0&&a.length>0){const e=_(a)[0];return{status:"success",data:{url:this.constructImageUrl(e.urls.original),urls:{original:this.constructImageUrl(e.urls.original)},raw:{id:parseInt(e.id),title:e.title,author:e.userName,r18:e.xRestrict>0,tags:e.tags.tags.map((e=>e.tag)),extension:e.urls.original.split(".").pop(),aiType:0,uploadDate:new Date(e.createDate).getTime(),urls:{original:this.constructImageUrl(e.urls.original)}}}}}if(r.length>0&&0===a.length)return{status:"error",data:new Error(`\u672a\u627e\u5230\u5305\u542b\u6807\u7b7e "${r.join(", ")}" \u7684\u63d2\u753b`)};{const r=_(t)[0],a=await this.getUserProfile(e,r.userId);if(a.error||!a.body.illusts)return{status:"error",data:new Error("\u65e0\u6cd5\u83b7\u53d6\u7528\u6237\u4f5c\u54c1\u5217\u8868")};const i=Object.keys(a.body.illusts);let s,n=0;const o=i.length;do{await k(n);const t=_(i)[0];if(s=await this.getIllustDetail(e,t),n++,s.error||!s.body){if(n>=o)return{status:"error",data:new Error("\u65e0\u6cd5\u83b7\u53d6\u5408\u9002\u7684\u63d2\u753b\u8be6\u60c5")};continue}const r=s.body.xRestrict>0||s.body.tags.tags.some((e=>"r-18"===e.tag.toLowerCase()));if(this.config.isR18||!r)break}while(n<o);if(n>=o)return{status:"error",data:new Error("\u672a\u627e\u5230\u7b26\u5408\u6761\u4ef6\u7684\u63d2\u753b")};const c=s.body;return{status:"success",data:{url:this.constructImageUrl(c.urls.original),urls:{original:this.constructImageUrl(c.urls.original)},raw:{id:parseInt(c.id),title:c.title,author:c.userName,r18:c.xRestrict>0,tags:c.tags.tags.map((e=>e.tag)),extension:c.urls.original.split(".").pop(),aiType:0,uploadDate:new Date(c.createDate).getTime(),urls:{original:this.constructImageUrl(c.urls.original)}}}}}}catch(e){return q.error("\u83b7\u53d6 Pixiv Discovery \u5143\u6570\u636e\u5931\u8d25",{error:e}),{status:"error",data:e}}}async getAllFollowingUsers(t){let r=0;const a=[];for(;;){await k(r);const i=e.FOLLOWING_URL.replace("{USER_ID}",this.config.pixiv.userId).replace("{OFFSET_COUNT}",r.toString()).replace("{LIMIT_COUNT}",100..toString()),s=await this.fetchPixivData(t,i);if(s.error||!s.body.users.length)break;if(a.push(...s.body.users),r+=100,s.body.users.length<100)break}return a}async getUserProfile(t,r){const a=e.USER_PROFILE_URL.replace("{USER_ID}",r);return await this.fetchPixivData(t,a)}async getIllustDetail(t,r){const a=e.ILLUST_URL.replace("{ARTWORK_ID}",r);return await this.fetchPixivData(t,a)}},safebooru:class extends b{static description="\u901a\u8fc7 Safebooru API \u83b7\u53d6\u56fe\u7247";endpoint="https://safebooru.org/index.php";async getMetaData({context:e},t){try{let r="";t.tag&&(r=t.tag.split(/[,\uff0c]/).map((e=>e.trim())).filter(Boolean).join(" "));const a={page:"dapi",s:"post",q:"index",json:"1",limit:"1",tags:`${r} sort:random`},i=`${this.endpoint}?${new URLSearchParams(a).toString()}`,s=await e.http.get(i,{proxyAgent:this.config.isProxy?this.config.proxyHost:void 0});if(!Array.isArray(s)||0===s.length)return{status:"error",data:new Error("No image data returned")};const n=s[0],o=`https://safebooru.org/images/${n.directory}/${n.image}?${n.id}`,c=n.sample?`https://safebooru.org/samples/${n.directory}/sample_${n.image}?${n.id}`:o,l={id:n.id,title:`Safebooru - ${n.id}`,author:n.owner.replace(/_/g," "),r18:!["safe","general"].includes(n.rating),tags:n.tags.split(" "),extension:n.image.split(".").pop(),aiType:0,uploadDate:new Date(n.created_at).getTime(),urls:{original:o,regular:c}};return q.debug("\u6210\u529f\u83b7\u53d6\u56fe\u7247\u5143\u6570\u636e",{metadata:l}),{status:"success",data:{url:this.config.imageProcessing.compress?c:o,urls:{regular:c,original:o},raw:l}}}catch(e){return{status:"error",data:e}}}getMeta(){return{referer:"https://safebooru.org"}}setConfig(e){this.config=e}},sankaku:class extends b{static description="\u901a\u8fc7 Sankaku Complex API \u83b7\u53d6\u56fe\u7247";endpoint="https://capi-v2.sankakucomplex.com";http;constructor(e,t){super(e,t),this.http=e.http.extend({headers:{"User-Agent":j},proxyAgent:t.isProxy?t.proxyHost:void 0})}get keyPair(){const e=this.config.sankaku?.keyPairs||[];return e.length?e[Math.floor(Math.random()*e.length)]:null}async login(e){if(!e.accessToken){const t=await this.http.post(`${this.endpoint}/auth/token`,{login:e.login,password:e.password},{proxyAgent:this.config.isProxy?this.config.proxyHost:void 0});t.access_token&&(e.accessToken=t.access_token,e.tokenType=t.token_type)}return e}async getMetaData(e,t){try{const e=this.keyPair;if(!e)throw new Error("No API credentials provided");await this.login(e);let r="";t.tag&&(r=t.tag.split(/[,\uff0c]/).map((e=>e.trim())).filter(Boolean).join(" "));const a=new URLSearchParams({tags:`${r} order:random${this.config.isR18&&t.r18?"":" rating:safe"}`,limit:"1"}),i=await this.http.get(`${this.endpoint}/posts/random`,{params:a,headers:{Authorization:`${e.tokenType} ${e.accessToken}`},proxyAgent:this.config.isProxy?this.config.proxyHost:void 0});if(!i.length)return{status:"error",data:new Error("No image data returned")};const s=i[0],n={id:s.id,title:s.source||`Sankaku - ${s.id}`,author:s.author.name.replace(/_/g," "),r18:["explicit","questionable"].includes(s.rating),tags:s.tags.map((e=>e.name)),extension:s.file_url.split(".").pop(),uploadDate:new Date(s.created_at).getTime(),aiType:0,urls:{original:s.file_url,regular:s.sample_url}};return q.debug("\u6210\u529f\u83b7\u53d6\u56fe\u7247\u5143\u6570\u636e",{metadata:n}),{status:"success",data:{url:this.config.imageProcessing.compress?s.sample_url:s.file_url,urls:{regular:s.sample_url,original:s.file_url},raw:n}}}catch(e){return{status:"error",data:e}}}getMeta(){return{referer:"https://sankaku.app"}}setConfig(e){this.config=e}},yande:class extends b{static description="\u901a\u8fc7 Yande.re API \u83b7\u53d6\u56fe\u7247";endpoint="https://yande.re";keyPairs=[];hashPassword(e){const t=`choujin-steiner--${e}--`,r=(0,l.createHash)("sha1");return r.update(t),r.digest("hex")}setConfig(e){this.config=e,e.yande?.keyPairs?.length&&(this.keyPairs=e.yande.keyPairs)}get keyPair(){if(!this.keyPairs.length)return null;const e=this.keyPairs[Math.floor(Math.random()*this.keyPairs.length)];return{login:e.login,password_hash:this.hashPassword(e.password)}}async getMetaData({context:e},t){try{const r=this.keyPair;let a="";t.tag&&(a=t.tag.split(/[,\uff0c]/).map((e=>e.trim())).filter(Boolean).join(" "));const i={tags:`${a} order:random`,limit:1,...r?{login:r.login,password_hash:r.password_hash}:{}};this.config.isR18&&t.r18?i.tags+=" rating:explicit":i.tags+=" rating:safe";const s=await e.http.get(`${this.endpoint}/post.json`,{params:i,proxyAgent:this.config.isProxy?this.config.proxyHost:void 0});if(!Array.isArray(s)||0===s.length)return{status:"error",data:new Error("No image data returned")};const n=s[0],o=this.config.imageProcessing.compress?n.sample_url:n.file_url,c={id:n.id,title:"",author:n.author.replace(/_/g," "),r18:"e"===n.rating||"q"===n.rating,tags:n.tags.split(" "),extension:n.file_url.split(".").pop(),aiType:0,uploadDate:new Date(n.created_at).getTime(),urls:{original:n.file_url,regular:n.sample_url}};return q.debug("\u6210\u529f\u83b7\u53d6\u56fe\u7247\u5143\u6570\u636e",{metadata:c}),{status:"success",data:{url:o,urls:{regular:n.sample_url,original:n.file_url},raw:c}}}catch(e){return{status:"error",data:e}}}getMeta(){return{referer:"https://yande.re"}}}};function L(e,t,r){if(r){const a=T[r];if(a)return new a(e,t);throw new Error(`\u672a\u627e\u5230\u63d0\u4f9b\u7a0b\u5e8f\uff1a${r}`)}if(!t.defaultSourceProvider?.length)throw new Error("\u672a\u914d\u7f6e\u4efb\u4f55\u56fe\u7247\u6765\u6e90");const a=_(t.defaultSourceProvider)[0],i=T[a];if(i)return new i(e,t);throw new Error(`\u672a\u627e\u5230\u63d0\u4f9b\u7a0b\u5e8f\uff1a${a}`)}const j="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36";async function U(e,t,r,a){return p(0,0,(async()=>{const i={"User-Agent":j};a?.getMeta?.()?.referer&&(i.Referer=a.getMeta().referer);const s=await e.http.get(r,{responseType:"arraybuffer",proxyAgent:t.isProxy?t.proxyHost:void 0,headers:i}),n=function(e){const t=new Uint8Array(e).subarray(0,4);let r="";for(let e=0;e<t.length;e++)r+=t[e].toString(16);switch(r){case"89504e47":return"image/png";case"ffd8ffe0":case"ffd8ffe1":case"ffd8ffe2":return"image/jpeg";case"47494638":return"image/gif";default:return"application/octet-stream"}}(s);return q.debug("\u68c0\u6d4b\u5230MIME\u7c7b\u578b",{mimeType:n}),[s,n]}))}async function E(e,t,r,a){try{const i=await async function(e,t,r,a){if(!L(e,r,a))throw new Error("\u672a\u9009\u62e9\u6709\u6548\u7684\u56fe\u7247\u6765\u6e90\uff0c\u8bf7\u68c0\u67e5\u914d\u7f6e");const i=await L(e,r,a).getMetaData({context:e},{r18:r.isR18&&Math.random()<r.r18P,excludeAI:r.excludeAI,tag:t||void 0,proxy:r.baseUrl?r.baseUrl:void 0});if("error"===i.status)return null;const[s,n]=await U(e,r,i.data.url,L(e,r,a)),o=await p(0,0,(async()=>{const e=Buffer.from(s);return await w(0,e,r,!!i.data.urls?.regular)}));return{...i.data.raw,data:o,mimeType:n,raw:i.data.raw}}(e,r,t,a);return i?S(i,t):(0,o.h)("message",[(0,o.h)("text",{content:"\u6ca1\u6709\u83b7\u53d6\u5230\u55b5\n"})])}catch(t){return e.logger.error(t),(0,o.h)("message",[(0,o.h)("text",{content:`\u56fe\u7247\u83b7\u53d6\u5931\u8d25\u4e86\u55b5~\uff0c${t}`})])}}function $(e,t){e.command("pixluna.get","\u76f4\u63a5\u901a\u8fc7\u56fe\u6e90\u83b7\u53d6\u56fe\u7247"),e.command("pixluna.get.pixiv <pid:string>","\u901a\u8fc7 pid \u83b7\u53d6\u56fe\u7247").option("pages","-p <pages:number>",{fallback:0}).option("all","-a").action((async({session:r,options:a},i)=>await async function(e,t,r,a){const i=new R(e,t);return a.all?i.getAllImagesWithAtMessage(r,a):i.getImageWithAtMessage(r,a)}(e,t,r.userId,{pid:i,page:a.pages,all:a.all})))}function M(e,t){$(e,t),function(e){e.command("pixluna.source","\u67e5\u770b\u56fe\u6e90").action((async({session:e})=>{const t=Object.entries(T),r=(0,o.h)("message",[(0,o.h)("text",{content:"\u53ef\u7528\u7684\u56fe\u7247\u6765\u6e90\uff1a\n"}),...t.map((([e,t])=>(0,o.h)("text",{content:`- ${e}: ${t.description}\n`})))]);await e.send(r)}))}(e)}async function O(e,t,r,a){try{await t.deleteMessage(r,a)}catch(t){e.logger("recall").warn("\u64a4\u56de\u6d88\u606f\u65f6\u53d1\u751f\u9519\u8bef",{channelId:r,messageId:a,error:t})}}const B=o.Schema.intersect([o.Schema.object({isR18:o.Schema.boolean().default(!1).description("\u662f\u5426\u5141\u8bb8\u8fd4\u56de R18 \u5185\u5bb9"),messageBefore:o.Schema.string().default("\u4e0d\u53ef\u4ee5\u6da9\u6da9\u54e6~").description("\u89e6\u53d1\u54cd\u5e94\u65f6\u7684\u6d88\u606f\uff0c\u7559\u7a7a\u5219\u4e0d\u53d1\u9001"),showTags:o.Schema.boolean().default(!0).description("\u662f\u5426\u663e\u793a\u56fe\u7247\u6807\u7b7e"),excludeAI:o.Schema.boolean().default(!1).description("\u662f\u5426\u6392\u9664 AI \u751f\u6210\u4f5c\u54c1"),maxConcurrency:o.Schema.number().default(1).description("\u6700\u5927\u5e76\u53d1\u8bf7\u6c42\u6570").min(1).max(10).step(1),forwardMessage:o.Schema.boolean().default(!0).description("\u662f\u5426\u4ee5\u8f6c\u53d1\u6d88\u606f\u683c\u5f0f\u53d1\u9001\u56fe\u7247"),autoRecall:o.Schema.object({enable:o.Schema.boolean().default(!1).description("\u662f\u5426\u542f\u7528\u81ea\u52a8\u64a4\u56de"),delay:o.Schema.number().default(30).description("\u81ea\u52a8\u64a4\u56de\u5ef6\u8fdf\u65f6\u95f4\uff08\u79d2\uff09").min(1).max(120).step(1)})}).description("\u901a\u7528\u8bbe\u7f6e"),o.Schema.object({imageProcessing:o.Schema.object({confusion:o.Schema.boolean().default(!1).description("\u662f\u5426\u542f\u7528\u56fe\u7247\u6df7\u6dc6\u5904\u7406\uff08\u5bf9\u67d0\u4e9b\u5e73\u53f0\u6709\u5947\u6548\uff09"),compress:o.Schema.boolean().default(!1).description("\u662f\u5426\u538b\u7f29\u56fe\u7247\uff08\u80fd\u5927\u5e45\u5ea6\u63d0\u5347\u53d1\u9001\u7684\u901f\u5ea6\uff0c\u4f46\u662f\u5bf9\u56fe\u7247\u8d28\u91cf\u6709\u5f71\u54cd\uff09"),compressQuality:o.Schema.percent().default(65).description("\u56fe\u7247\u538b\u7f29\u8d28\u91cf").min(1).max(100).step(1),isFlip:o.Schema.boolean().default(!1).description("\u662f\u5426\u542f\u7528\u56fe\u7247\u7ffb\u8f6c\u5904\u7406"),flipMode:o.Schema.union([o.Schema.const("horizontal").description("\u6c34\u5e73\u7ffb\u8f6c"),o.Schema.const("vertical").description("\u5782\u76f4\u7ffb\u8f6c"),o.Schema.const("both").description("\u6c34\u5e73\u548c\u5782\u76f4\u7ffb\u8f6c")]).default("horizontal").description("\u56fe\u7247\u7ffb\u8f6c\u6a21\u5f0f")}).description("\u56fe\u7247\u5904\u7406\u8bbe\u7f6e")}),o.Schema.object({r18P:o.Schema.percent().default(.1).description("R18 \u5185\u5bb9\u51fa\u73b0\u7684\u6982\u7387\uff08\u4ec5\u5f53 isR18 \u4e3a true \u65f6\u751f\u6548\uff09").min(0).max(1).step(.01)}).description("R18 \u5185\u5bb9\u8bbe\u7f6e"),o.Schema.object({isProxy:o.Schema.boolean().default(!1).description("\u662f\u5426\u4f7f\u7528\u4ee3\u7406"),proxyHost:o.Schema.string().default("http://127.0.0.1:7890").description("\u4ee3\u7406\u670d\u52a1\u5668\u5730\u5740"),baseUrl:o.Schema.string().default("i.pixiv.re").description("\u56fe\u7247\u53cd\u4ee3\u670d\u52a1\u7684\u5730\u5740")}).description("\u4ee3\u7406\u8bbe\u7f6e"),o.Schema.object({defaultSourceProvider:o.Schema.array(o.Schema.union([o.Schema.const("danbooru").description("Danbooru API"),o.Schema.const("e621").description("E621 API"),o.Schema.const("gelbooru").description("Gelbooru API"),o.Schema.const("konachan").description("Konachan API"),o.Schema.const("lolibooru").description("Lolibooru API"),o.Schema.const("lolicon").description("Lolicon API"),o.Schema.const("lolisuki").description("Lolisuki API"),o.Schema.const("pdiscovery").description("Pixiv Discovery"),o.Schema.const("pfollowing").description("Pixiv Following"),o.Schema.const("safebooru").description("Safebooru API"),o.Schema.const("sankaku").description("Sankaku API"),o.Schema.const("yande").description("Yande.re API")])).description("\u9009\u62e9\u9ed8\u8ba4\u56fe\u7247\u6765\u6e90\uff08\u53ef\u591a\u9009\uff09").default(["lolicon"]).role("select")}).description("\u56fe\u6e90\u8bbe\u7f6e"),o.Schema.object({pixiv:o.Schema.object({phpSESSID:o.Schema.string().description("Pixiv \u7684 PHPSESSID\uff0c\u7528\u4e8e\u8bbf\u95ee\u4e2a\u6027\u5316\u5185\u5bb9\u8fd4\u56de\u7684\u56fe\u7247\u5206\u7ea7\u53d6\u51b3\u4e8e\u8be5 Pixiv \u8d26\u53f7\u6240\u6709\u8005\u7684\u5206\u7ea7\u8bbe\u7f6e").role("secret").default(""),userId:o.Schema.string().description("Pixiv \u7528\u6237 ID\uff0c\u7528\u4e8e\u83b7\u53d6\u5173\u6ce8\u5217\u8868").default("")}).description("Pixiv \u8bbe\u7f6e")}),o.Schema.object({danbooru:o.Schema.object({keyPairs:o.Schema.array(o.Schema.object({login:o.Schema.string().required().description("Danbooru \u7528\u6237\u540d"),apiKey:o.Schema.string().required().role("secret").description("Danbooru API Key")})).default([]).description("Danbooru API \u9274\u6743\u4fe1\u606f")}).description("Danbooru \u8bbe\u7f6e")}),o.Schema.object({e621:o.Schema.object({keyPairs:o.Schema.array(o.Schema.object({login:o.Schema.string().required().description("E621 \u7528\u6237\u540d"),apiKey:o.Schema.string().required().role("secret").description("E621 API Key")})).default([]).description("E621 API \u9274\u6743\u4fe1\u606f")}).description("E621 \u8bbe\u7f6e")}),o.Schema.object({gelbooru:o.Schema.object({keyPairs:o.Schema.array(o.Schema.object({apiKey:o.Schema.string().required().role("secret").description("Gelbooru API Key")})).default([]).description("Gelbooru API \u9274\u6743\u4fe1\u606f")}).description("Gelbooru \u8bbe\u7f6e")}),o.Schema.object({lolibooru:o.Schema.object({keyPairs:o.Schema.array(o.Schema.object({login:o.Schema.string().required().description("Lolibooru \u7528\u6237\u540d"),password:o.Schema.string().required().role("secret").description("Lolibooru \u5bc6\u7801")})).default([]).description("Lolibooru API \u9274\u6743\u4fe1\u606f")}).description("Lolibooru \u8bbe\u7f6e")}),o.Schema.object({sankaku:o.Schema.object({keyPairs:o.Schema.array(o.Schema.object({login:o.Schema.string().required().description("Sankaku Complex \u7528\u6237\u540d"),password:o.Schema.string().required().role("secret").description("Sankaku Complex \u5bc6\u7801"),tokenType:o.Schema.string().hidden().default("Bearer"),accessToken:o.Schema.string().hidden()})).default([]).description("Sankaku Complex API \u9274\u6743\u4fe1\u606f")}).description("Sankaku Complex \u8bbe\u7f6e"),konachan:o.Schema.object({keyPairs:o.Schema.array(o.Schema.object({login:o.Schema.string().required().description("Konachan \u7528\u6237\u540d"),password:o.Schema.string().required().role("secret").description("Konachan \u5bc6\u7801")})).default([]).description("Konachan API \u9274\u6743\u4fe1\u606f")}).description("Konachan \u8bbe\u7f6e"),yande:o.Schema.object({keyPairs:o.Schema.array(o.Schema.object({login:o.Schema.string().required().description("Yande.re \u7528\u6237\u540d"),password:o.Schema.string().required().role("secret").description("Yande.re \u5bc6\u7801")})).default([]).description("Yande.re API \u9274\u6743\u4fe1\u606f")}).description("Yande.re \u8bbe\u7f6e")}),o.Schema.object({isLog:o.Schema.boolean().default(!1).description("\u662f\u5426\u8f93\u51fadebug\u65e5\u5fd7")}).description("\u65e5\u5fd7\u8bbe\u7f6e")]);let q;async function C(e=0,t=!0){(!t||e>0)&&await new Promise((e=>setTimeout(e,2e3)))}exports.Config=B,exports.apply=function(e,t){q=function(e,t="pixluna"){const r=u[t]||e.logger(t);return g>=0&&(r.level=g),u[t]=r,r}(e),function(e){e.isLog&&function(e){g=e;for(const t in u)u[t].level=e}(o.Logger.DEBUG)}(t),e.command("pixluna","\u6765\u5f20\u8272\u56fe").alias("\u8272\u56fe").option("number","-n <value:number>",{fallback:1}).option("source","-s <source:string>",{fallback:""}).option("tag","-t <tags:string>",{fallback:""}).action((async({session:r,options:a})=>{if(!Number.isInteger(a.number)||a.number<=0)return I(r.userId,"\u56fe\u7247\u6570\u91cf\u5fc5\u987b\u662f\u5927\u4e8e0\u7684\u6574\u6570\u54e6~");t.messageBefore&&await r.send(t.messageBefore);const i=Array.isArray(t.defaultSourceProvider)?t.defaultSourceProvider:[t.defaultSourceProvider],s={...t,defaultSourceProvider:a.source?[a.source]:i};if(a.source)try{L(e,{...s,defaultSourceProvider:[a.source]})}catch(e){return I(r.userId,e.message)}const n=[],c=new d(t.maxConcurrency);for(let t=0;t<Math.min(10,a.number);t++)await C(t),c.add(p(0,0,(async()=>{const t=await E(e,s,a.tag,a.source);n.push(t)})));await c.run();let l=[];try{const e=await p(0,0,(()=>{const e=(0,o.h)("message",n);return t.forwardMessage?r.send((0,o.h)("message",{forward:t.forwardMessage},n)):r.send(e)}));l=Array.isArray(e)?e:[e]}catch(e){q.error("\u53d1\u9001\u6d88\u606f\u65f6\u53d1\u751f\u9519\u8bef",{error:e});const t=await r.send(I(r.userId,"\u6d88\u606f\u53d1\u9001\u5931\u8d25\u4e86\u55b5\uff0c\u8d26\u53f7\u53ef\u80fd\u88ab\u98ce\u63a7\n"));t&&(l=l.concat(Array.isArray(t)?t:[t]))}l.length>0&&t.autoRecall.enable&&await async function(e,t,r,a=6e4){if(!r?.length)return;e.logger("recall").debug("\u8bbe\u7f6e\u6d88\u606f\u81ea\u52a8\u64a4\u56de",{channelId:t.channelId,messageIds:r,timeout:a}),setTimeout((async()=>{for(const a of r)await O(e,t.bot,t.channelId,a)}),a)}(e,r,l,1e3*t.autoRecall.delay)})),M(e,t)},Object.defineProperty(exports,"logger",{enumerable:!0,get:function(){return q}}),exports.name="pixluna";