{"id":19965363,"url":"https://github.com/eric2788/koishi-plugin-random-source-selector","last_synced_at":"2025-03-01T17:16:42.765Z","repository":{"id":203778666,"uuid":"710415082","full_name":"eric2788/koishi-plugin-random-source-selector","owner":"eric2788","description":"透过扫描API链接返回的数据随机抽出一条作为图片或文案发送，支援自定义指令","archived":false,"fork":false,"pushed_at":"2024-01-19T02:46:53.000Z","size":81,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-26T16:46:22.251Z","etag":null,"topics":["koishi","koishi-plugin","setu"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eric2788.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-26T16:35:52.000Z","updated_at":"2023-10-26T17:06:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"7eea99ae-6ec7-4211-8778-ee9a90808ac0","html_url":"https://github.com/eric2788/koishi-plugin-random-source-selector","commit_stats":null,"previous_names":["eric2788/koishi-plugin-random-source-selector"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eric2788%2Fkoishi-plugin-random-source-selector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eric2788%2Fkoishi-plugin-random-source-selector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eric2788%2Fkoishi-plugin-random-source-selector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eric2788%2Fkoishi-plugin-random-source-selector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eric2788","download_url":"https://codeload.github.com/eric2788/koishi-plugin-random-source-selector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241396781,"owners_count":19956408,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["koishi","koishi-plugin","setu"],"created_at":"2024-11-13T02:28:29.066Z","updated_at":"2025-03-01T17:16:42.742Z","avatar_url":"https://github.com/eric2788.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koishi-plugin-random-source-selector\n\n[![npm](https://img.shields.io/npm/v/koishi-plugin-random-source-selector?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-random-source-selector)\n\n透过多行文本链接随机抽出一条作为图片或文案发送，支援自定义指令\n\n\n## 功能介绍\n\n目前支援的数据解析类型:\n\n- JSON\n- 多行文本\n- HTML\n- 资源\n- 源数据\n\n目前支援的发送类型:\n\n- 图片\n- 文本\n- EJS模板\n- 视频\n- 音频\n- 文件\n\n目前支援透过指令传递参数:\n\n- 以 `{0}` `{1}` `{2}` 传入...\n\n- 透过 `--data` 传入 payload\n\n## 一般例子\n\n**假设你需要传输指令参数到你的链接**\n\n你可以使用 `{0}` `{1}` 等等的方式来传递参数, 例如:\n\n```url\nhttps://google.com/search?q={0}\n```\n\n当你的指令为 `google hello` 时，插件会将 `{0}` 替换为 `hello`，并发送到 `https://google.com/search?q=hello`。\n\n另外也支援多个参数，例如:\n\n```url\nhttps://google.com/search?q={0}\u0026safe={1}\n```\n\n当你的指令为 `google hello true` 时，插件会将 `{0}` 替换为 `hello`，`{1}` 替换为 `true`，并发送到 `https://google.com/search?q=hello\u0026safe=true`。\n\n---\n\n**假设你需要透过 payload 传输参数到你的链接**\n\npayload一般用在POST，PUT等请求，你可以在设定中添加 `request_data` 数据，例如:\n\n```yml\nrequest_data: '{\"name\": \"{0}\", \"age\": \"{1}\"}'\nrequest_json: true\n```\n\n__注意: 假设你的数据为JSON，则必须设定 `request_json` 为 `true`__\n\n此外，你也可以透过传入 `--data` 来覆盖设定中的参数，例如:\n\n```sh\n创建用户 --data '{\"name\": \"foo\", \"age\": \"bar\"}'\n```\n\n插件会将 `--data` 的数据覆盖 `request_data` 中的数据，然后提交请求。\n\n---\n\n**假设你的链接返回多行文本**，例如\n\n```txt\n今天礼拜四，V我50\n今天是疯狂星期四！！\n```\n\n则选择发送类型为`文本`, 数据返回类型为`多行文本`, 插件便会从这两句文案中随机抽选一个返回。\n\n---\n\n**假设你的链接返回多行图片链接**，例如\n\n```txt\nhttps://cdn.xyz/abc.jpg\nhttps://cdn.xyz/xyz.jpg\n```\n\n则选择发送类型为`图片`, 数据返回类型为`多行文本`, 插件便会从这两条图片链接随机抽选一张图片返回。\n\n---\n\n**假设你的链接返回随机图片**\n\n则选择发送类型为`图片`, 数据返回类型为`资源`, 插件则会直接把该链接返回的图片直接发送。\n\n此类型适用于所有资源，包括视频，音频，文件等。\n\n## 额外的解析类型选项 + 例子\n\n### HTML\n\n透过 Jquery 提取文本，设置如下\n\n```yml\njquery_selector: 提取元素, 相当于 querySelectorAll(value)\nattribute: 获取元素属性, 相当于 getAttribute(value)\n```\n\n例子如下:\n\n```html\n\u003cimg class=\"abc\" src=\"https://cdn.xyz/abc1.img\"\u003e\n\u003cimg class=\"abc\" src=\"https://cdn.xyz/abc2.img\"\u003e\n\u003cimg class=\"abc\" src=\"https://cdn.xyz/abc3.img\"\u003e\n\u003cimg class=\"xyz\" src=\"https://cdn.xyz/xyz.img\"\u003e\n```\n\n想获取仅限 class 中包含 `abc` 的图片链接，则可用:\n\n```yml\njquery_selector: .abc\nattribute: src\n```\n\n插件则会从该三张图片中随机抽选。\n\n__注意: 提取的 html 文本为 http 请求的文本，不包含js后期注入的html元素__\n\n### JSON\n\n透过字符进行JSON取值，设置如下\n\n```yml\njson_key: 需要扫描的key, 相当于在js中获取json数值时的引用 + 支援迭代逻辑 []\n```\n\n例子如下:\n\n```json\n[\n    {\n        \"id\": \"_5degoesxi\",\n        \"question\": \"What would you like to practice today?\",\n        \"possible_answers\": [\n            {\n                \"label\": \"HTML \u0026 CSS\",\n                \"action\": {\n                    \"key\": \"lesson_category\",\n                    \"type\": \"html-css\"\n                }\n            },\n            {\n                \"label\": \"General Typing\",\n                \"action\": {\n                    \"key\": \"lesson_category\",\n                    \"type\": \"general\"\n                }\n            }\n        ]\n    },\n    {\n        \"id\": \"_zvcr8k6sq\",\n        \"question\": \"Choose your difficult level.\",\n        \"possible_answers\": [\n            {\n                \"label\": \"Easy\",\n                \"action\": {\n                    \"key\": \"difficulty\",\n                    \"type\": \"easy\"\n                }\n            },\n            {\n                \"label\": \"Medium\",\n                \"action\": {\n                    \"key\": \"difficulty\",\n                    \"type\": \"medium\"\n                }\n            },\n            {\n                \"label\": \"Hard\",\n                \"action\": {\n                    \"key\": \"difficulty\",\n                    \"type\": \"hard\"\n                }\n            }\n        ]\n    }\n]\n```\n\n若想获取所有元素中内 action 的 type, 则使用\n\n```yml\njson_key: \"[].possible_answers[].action.type\"\n```\n\n`[]` 代表迭代，会提取每个迭代元素的值。\n提取后将会从 `hard`, `medium`, `easy`, `general`, `html-css` 中随机抽选。\n\n---\n\n若 JSON 从 object 而非 array 开始，则直接填入该 object 的 key 即可，例如:\n\n```json\n{\n    \"abc\": {\n        \"xyz\": [\"foo\", \"bar\"]\n    }\n}\n```\n\n则填入:\n\n```yml\njson_key: \"abc.xyz\"\n```\n\n就可获得 `foo`, `bar` 的随机抽选。\n\n__注意: 若 `json_key` 填写不当有可能会导致插件报错。__\n\n### EJS\n\n数据类型选择``元数据``，填入``EJS模板``即可。\n\n假设你的返回数据为以下的json:\n\n```json\n{\n    \"name\": \"morpheus\",\n    \"job\": \"leader\",\n    \"id\": \"583\",\n    \"createdAt\": \"2023-11-13T06:30:39.982Z\"\n}\n```\n\nEJS模板则可输入:\n\n```yml\nejs_template: |-\n    \u003cp\u003e 成功创建 name: \u003c%= data.name %\u003e, job: \u003c%= data.job %\u003e\u003c/p\u003e\n    \u003cp\u003e id: \u003c%= data.id %\u003e \u003c/p\u003e\n```\n\n插件将会根据模板输出回应。\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feric2788%2Fkoishi-plugin-random-source-selector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feric2788%2Fkoishi-plugin-random-source-selector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feric2788%2Fkoishi-plugin-random-source-selector/lists"}