-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cfb697b
Showing
15 changed files
with
279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
* text eol=lf | ||
|
||
*.png -text | ||
*.jpg -text | ||
*.ico -text | ||
*.gif -text | ||
*.webp -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
lib | ||
dist | ||
|
||
node_modules | ||
npm-debug.log | ||
yarn-debug.log | ||
yarn-error.log | ||
tsconfig.tsbuildinfo | ||
|
||
.eslintcache | ||
.DS_Store | ||
.idea | ||
.vscode | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Context } from '@koishijs/client' | ||
import Page from './page.vue' | ||
|
||
|
||
export default (ctx: Context) => { | ||
ctx.page({ | ||
name: '扩展页面', | ||
path: '/custom-page', | ||
component: Page, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<template> | ||
<k-layout>扩展内容</k-layout> | ||
</template> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"rootDir": ".", | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"jsx": "preserve", | ||
"types": [ | ||
"@koishijs/client/global" | ||
] | ||
}, | ||
"include": [ | ||
"." | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "koishi-plugin-rpixiv", | ||
"description": "search pixiv", | ||
"version": "0.0.1", | ||
"main": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
"files": [ | ||
"lib", | ||
"dist" | ||
], | ||
"license": "MIT", | ||
"scripts": {}, | ||
"keywords": [ | ||
"chatbot", | ||
"koishi", | ||
"plugin" | ||
], | ||
"peerDependencies": { | ||
"koishi": "^4.11.6" | ||
}, | ||
"dependencies": { | ||
"axios": "0.26.1", | ||
"dotenv": "^16.0.3", | ||
"runtu-pixiv-sdk": "^1.0.18" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# koishi-plugin-rpixiv | ||
|
||
[![npm](https://img.shields.io/npm/v/koishi-plugin-rpixiv?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-rpixiv) | ||
|
||
search pixiv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { RPixiv, WebPixivType } from "runtu-pixiv-sdk"; | ||
import { h } from "koishi"; | ||
|
||
export const requestBuffers = (urls: WebPixivType["illusts"], r: RPixiv) => { | ||
const promise = []; | ||
urls.slice(0, 10).forEach((item) => { | ||
promise.push(r.getPixivStream(item.image_urls.medium, "arraybuffer")); | ||
}); | ||
return Promise.all(promise).then((res) => { | ||
return h( | ||
"p", | ||
{}, | ||
res.map((item) => h.image(item, "image/png")) | ||
); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './buffers' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Context, Schema } from 'koishi' | ||
import { RPixiv } from 'runtu-pixiv-sdk' | ||
import { rPixivIllustsSearch, illustsPush } from './middleware/index' | ||
|
||
|
||
export const name = 'rpixiv' | ||
|
||
|
||
export interface Config { | ||
refresh: string, | ||
keywords: { | ||
start: string, | ||
day: string, | ||
week: string, | ||
month: string, | ||
searchIllusts: string, | ||
searchAuthor: string, | ||
}, | ||
proxy: { | ||
host: string, | ||
port: number | ||
} | ||
} | ||
|
||
export const Config: Schema<Config> = Schema.object({ | ||
refresh: Schema.string().required().default("").description("Pixiv的RefreshToken"), | ||
keywords: Schema.object({ | ||
start: Schema.string().default("rpixiv酱").description("机器人的触发词。"), | ||
day: Schema.string().default("查询每日推荐榜").description("每日推荐榜的触发语,紧跟着start字段触发词"), | ||
week: Schema.string().default("查询每周推荐榜").description("每周推荐榜的触发语,紧跟着start字段触发词"), | ||
month: Schema.string().default("查询每月推荐榜").description("每周推荐榜的触发语,紧跟着start字段触发词"), | ||
searchIllusts: Schema.string().default("查询作品").description("每周推荐榜的触发语,紧跟着start字段触发词"), | ||
searchAuthor: Schema.string().default("查询作者").description("每周推荐榜的触发语,紧跟着start字段触发词"), | ||
}), | ||
proxy: Schema.object({ | ||
host: Schema.string().default("").description("代理的host"), | ||
port: Schema.number().default(0).description("代理端口") | ||
}) | ||
}) | ||
|
||
|
||
|
||
|
||
export function apply(ctx: Context, config: Config) { | ||
|
||
const keywords = { | ||
...config.keywords | ||
} | ||
|
||
for (const [key, word] of Object.entries(config.keywords)) { | ||
if (key !== config.keywords.start) { | ||
keywords[key] = config.keywords.start + word | ||
} | ||
} | ||
|
||
const rPixiv = new RPixiv({ | ||
host: "127.0.0.1", | ||
port: 7890 | ||
}) | ||
|
||
// 环境变量设置 | ||
process.env.REFEESH_TOKEN = config.refresh | ||
// token初始化 | ||
rPixiv.token() | ||
|
||
// 触发 | ||
console.log(keywords) | ||
ctx.middleware(illustsPush(keywords.day, 'day', rPixiv)) | ||
ctx.middleware(illustsPush(keywords.week, 'week', rPixiv)) | ||
ctx.middleware(illustsPush(keywords.month, 'month', rPixiv)) | ||
ctx.middleware(rPixivIllustsSearch(keywords.searchIllusts, rPixiv)) | ||
|
||
|
||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Middleware } from 'koishi' | ||
import { RPixiv } from 'runtu-pixiv-sdk' | ||
import { requestBuffers } from '../components' | ||
|
||
|
||
export const illustsPush: (trigger: string, type: string, r: RPixiv) => Middleware = (trigger, type, rPixiv) => { | ||
const triggerC = trigger | ||
console.log("sdsdsds",trigger) | ||
let requestFn: RPixiv['getMonthRanks'] | RPixiv['getDayRanks'] | RPixiv['getWeekRanks'] = undefined | ||
if (type === 'day') { | ||
requestFn = rPixiv.getDayRanks | ||
} else if (type === 'week') { | ||
requestFn = rPixiv.getWeekRanks | ||
} else if (type === 'month') { | ||
requestFn = rPixiv.getMonthRanks | ||
} else { | ||
requestFn = null | ||
} | ||
return (session, next) => { | ||
if (session.content.startsWith(triggerC)) { | ||
console.log('触发了') | ||
requestFn.call(rPixiv, "").then(res => { | ||
if (res.code === 200) { | ||
return requestBuffers(res.data.illusts, rPixiv) | ||
} else { | ||
session.send("网络出现错误,请联系管理员") | ||
} | ||
}).then(info => { | ||
session.send(info) | ||
}).catch(() => { | ||
session.send("出现了渣不多得勒的错误") | ||
}) | ||
} else { | ||
next() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './illustPush' | ||
export * from './search' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Middleware, h } from 'koishi' | ||
import { RPixiv } from 'runtu-pixiv-sdk' | ||
import { requestBuffers } from '../components' | ||
|
||
|
||
export const rPixivIllustsSearch: (trigger: string, r: RPixiv) => Middleware = (trigger, rpixiv) => { | ||
return (session, next) => { | ||
// 指定前缀 | ||
if (session.content.startsWith(trigger)) { | ||
const words = session.content.slice(trigger.length) | ||
rpixiv.searchIllusts(words) | ||
.then((res) => { | ||
if (res.code === 400) { | ||
session.send("网络出现问题,请联系管理员") | ||
} else { | ||
return requestBuffers(res.data.illusts, rpixiv) | ||
} | ||
}) | ||
.then(info => { | ||
session.send(info) | ||
}) | ||
.catch((err) => { | ||
console.log(err) | ||
session.send("出现了渣不多得勒的错误,请联系管理员") | ||
}) | ||
|
||
} else { | ||
next() | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "lib", | ||
"target": "es2020", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"composite": true, | ||
"incremental": true, | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"moduleResolution": "node", | ||
"jsx": "react-jsx", | ||
"jsxImportSource": "@satorijs/element", | ||
}, | ||
"include": [ | ||
"src", | ||
], | ||
} |