Commit b563fcb7 authored by nanahira's avatar nanahira

first

parent f1022ac9
Pipeline #9443 passed with stages
in 45 seconds
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/data
/output
/config.yaml
.git*
Dockerfile
.dockerignore
webpack.config.js
dist/*
build/*
\ No newline at end of file
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/data
/output
/config.yaml
\ No newline at end of file
stages:
- build
- deploy
variables:
GIT_DEPTH: "1"
build:
stage: build
tags:
- linux
script:
- npm ci
- npm run build
artifacts:
paths:
- dist/
upload_to_minio:
stage: deploy
dependencies:
- build
tags:
- linux
script:
- aws s3 --endpoint=https://minio.mycard.moe:9000 sync --delete dist/full/ s3://nanahira/koishi-plugin/myplugin
only:
- master
deploy_npm:
stage: deploy
dependencies:
- build
tags:
- linux
script:
- apt update;apt -y install coreutils
- echo $NPMRC | base64 --decode > ~/.npmrc
- npm publish . --access public
only:
- master
/install-npm.sh
.git*
/data
/output
/config.yaml
.idea
.dockerignore
Dockerfile
/src
/dist/full
{
"singleQuote": true,
"trailingComma": "all"
}
\ No newline at end of file
The MIT License (MIT)
Copyright (c) 2021 Nanahira
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# koishi-plugin-picsource-yande
Koishi pics source plugin for https://yande.re or https://konachan.com
\ No newline at end of file
Koishi 的 [Yande](https://yande.re)[Konachan](https://konachan.com) 图源插件。
## 安装
### npm
```bash
npm install koishi-plugin-picsource-yande
```
### 直接安装
在 https://cdn02.moecube.com:444/nanahira/koishi-plugin/picsource-yande/index.js 下载即可。
## 配置
详见 `config.ts` 部分,或详见 Schema 描述配置。
#!/bin/bash
npm install --save \
source-map-support \
koishi-thirdeye
npm install --save-dev \
@types/node \
typescript \
'@typescript-eslint/eslint-plugin@^4.28.2' \
'@typescript-eslint/parser@^4.28.2 '\
'eslint@^7.30.0' \
'eslint-config-prettier@^8.3.0' \
'eslint-plugin-prettier@^3.4.0' \
prettier \
raw-loader \
ts-loader \
webpack \
webpack-cli \
koishi@latest \
ws
This diff is collapsed.
{
"name": "koishi-plugin-picsource-yande",
"description": "Koishi 的 [Yande](https://yande.re) 和 [Konachan](https://konachan.com) 图源插件。",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"lint": "eslint --fix .",
"build": "webpack && env PACK_ALL=1 webpack"
},
"repository": {
"type": "git",
"url": "https://code.mycard.moe/3rdeye/koishi-plugin-picsource-yande.git"
},
"author": "Nanahira <nanahira@momobako.com>",
"license": "MIT",
"keywords": [
"Koishi.js",
"qqbot",
"cqhttp",
"onebot",
"required:pics"
],
"bugs": {
"url": "https://code.mycard.moe/3rdeye/koishi-plugin-picsource-yande/issues"
},
"homepage": "https://code.mycard.moe/3rdeye/koishi-plugin-picsource-yande",
"peerDependencies": {
"koishi": "^4.2.0",
"koishi-plugin-pics": "^8.2.0"
},
"dependencies": {
"koishi-thirdeye": "^8.2.0",
"source-map-support": "^0.5.21"
},
"devDependencies": {
"@types/node": "^17.0.17",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.1",
"koishi": "^4.2.0",
"koishi-plugin-pics": "^8.2.0",
"prettier": "^2.5.1",
"raw-loader": "^4.0.2",
"ts-loader": "^9.2.6",
"typescript": "^4.5.5",
"webpack": "^5.68.0",
"webpack-cli": "^4.9.2",
"ws": "^8.5.0"
}
}
import 'source-map-support/register';
import { DefineSchema, RegisterSchema } from 'koishi-thirdeye';
import { PicSourceInfo } from 'koishi-plugin-pics';
@RegisterSchema()
export class InstanceConfig implements PicSourceInfo {
@DefineSchema({ description: '图源名称', default: 'yande' })
name: string;
@DefineSchema({ type: 'string', default: [], description: '图源标签' })
tags: string[];
@DefineSchema({ default: 1, description: '图源权重' })
weight: number;
@DefineSchema({ description: '图源描述' })
description?: string;
@DefineSchema({ description: '是否为默认图源' })
isDefault?: boolean;
@DefineSchema({
description: '网站 post.json 的地址',
default: 'https://yande.re/post.json',
})
endpoint: string;
// 给目标对象注入上述对象。
applyTo(target: PicSourceInfo) {
target.tags = this.tags;
target.weight = this.weight;
target.name = this.name;
target.description = this.description;
target.isDefault = this.isDefault;
}
}
@RegisterSchema()
export class PicSourceYandePluginConfig {
constructor(config: PicSourceYandePluginConfigLike) {}
@DefineSchema({ description: '实例列表。', type: InstanceConfig })
instances: InstanceConfig[];
}
export type PicSourceYandePluginConfigLike = Partial<PicSourceYandePluginConfig>;
export interface PicInfo {
id: number;
tags: string;
created_at: number;
creator_id: number;
author: string;
change: number;
source: string;
score: number;
md5: string;
file_size: number;
file_url: string;
is_shown_in_index: boolean;
preview_url: string;
preview_width: number;
preview_height: number;
actual_preview_width: number;
actual_preview_height: number;
sample_url: string;
sample_width: number;
sample_height: number;
sample_file_size: number;
jpeg_url: string;
jpeg_width: number;
jpeg_height: number;
jpeg_file_size: number;
rating: string;
has_children: boolean;
parent_id?: any;
status: string;
width: number;
height: number;
is_held: boolean;
frames_pending_string: string;
frames_pending: any[];
frames_string: string;
frames: any[];
}
import 'source-map-support/register';
import { InstanceConfig, PicSourceYandePluginConfig } from './config';
import {
DefinePlugin,
BasePlugin,
Inject,
LifecycleEvents,
} from 'koishi-thirdeye';
import PicsContainer, { PicSource } from 'koishi-plugin-pics';
import { Context, Random } from 'koishi';
import { PicInfo } from './def';
export * from './config';
export class PicSourceInstance extends PicSource {
constructor(ctx: Context, private config: InstanceConfig) {
super(ctx);
config.applyTo(this);
}
private page = 1;
private nextPage() {
const currentPage = this.page;
if (this.page >= 200) {
this.page = 1;
} else {
++this.page;
}
return currentPage;
}
async randomPic(picTags: string[]) {
const page = this.nextPage();
const data = await this.ctx.http.get<PicInfo[]>(this.config.endpoint, {
params: {
tags: picTags.join('+'),
limit: 1000,
page: page,
},
});
if (!Array.isArray(data)) {
return;
}
if (data.length === 0) {
if (page === 1) {
return;
}
this.page = 1;
return this.randomPic(picTags);
}
const pic = Random.pick(data);
return {
url: pic.file_url,
description: `#${pic.id} ${pic.tags} by ${pic.author}`,
};
}
}
@DefinePlugin({ name: 'picsource-yande', schema: PicSourceYandePluginConfig })
export default class PicSourceYandePlugin
extends BasePlugin<PicSourceYandePluginConfig>
implements LifecycleEvents
{
@Inject(true)
private pics: PicsContainer;
onApply() {
for (const instanceConfig of this.config.instances) {
this.pics.addSource(new PicSourceInstance(this.ctx, instanceConfig));
}
}
}
{
"compilerOptions": {
"outDir": "dist",
"module": "commonjs",
"target": "es2021",
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": true,
"sourceMap": true,
"skipLibCheck": true
},
"compileOnSave": true,
"allowJs": true,
"include": [
"*.ts",
"src/**/*.ts"
]
}
const path = require('path');
const packgeInfo = require('./package.json');
function externalsFromDep() {
return Object.fromEntries(
[
...Object.keys(packgeInfo.dependencies || {}),
...Object.keys(packgeInfo.peerDependencies || {}),
]
.filter((dep) => dep !== 'source-map-support')
.map((dep) => [dep, dep]),
);
}
const packAll = !!process.env.PACK_ALL;
module.exports = {
entry: './src/index.ts',
mode: 'production',
target: 'node',
devtool: 'source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{ test: /\.mustache$/, use: 'raw-loader' },
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'index.js',
library: {
type: 'commonjs',
},
path: path.resolve(__dirname, packAll ? 'dist/full' : 'dist'),
},
externals: {
koishi: 'koishi',
...(packAll ? {} : externalsFromDep()),
},
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment