Commit 6fe5c057 authored by nanahira's avatar nanahira

first

parent f27c4288
# 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/
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:
- tags
/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-heisi
Koishi pics source plugin, based on [nonebot_plugin_heisi](https://github.com/yzyyz1387/nonebot_plugin_heisi)
\ No newline at end of file
基于 [nonebot_plugin_heisi](https://github.com/yzyyz1387/nonebot_plugin_heisi) 的 Koishi 图源插件。
## 安装
### npm
```bash
npm install koishi-plugin-picsource-heisi
```
## 配置
共通实例属性见 [`koishi-plugin-pics`](https://code.mycard.moe/3rdeye/koishi-plugin-pics)`PicSourceInfo` 定义。
其余见 `config.ts`
#!/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@next \
ws
This diff is collapsed.
{
"name": "koishi-plugin-picsource-heisi",
"description": "基于 [nonebot_plugin_heisi](https://github.com/yzyyz1387/nonebot_plugin_heisi) 的 Koishi 图源插件。",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"lint": "eslint --fix .",
"build": "webpack"
},
"repository": {
"type": "git",
"url": "https://code.mycard.moe/3rdeye/koishi-plugin-picsource-heisi.git"
},
"author": "Nanahira <nanahira@momobako.com>",
"license": "MIT",
"keywords": [
"Koishi.js",
"qqbot",
"cqhttp",
"onebot",
"nonebot",
"heisi",
"required:picscontainer",
"required:cache"
],
"bugs": {
"url": "https://code.mycard.moe/3rdeye/koishi-plugin-picsource-heisi/issues"
},
"homepage": "https://code.mycard.moe/3rdeye/koishi-plugin-picsource-heisi",
"peerDependencies": {
"koishi": "^4.0.0-beta.4"
},
"dependencies": {
"koishi-thirdeye": "^4.2.3",
"source-map-support": "^0.5.21",
"koishi-plugin-pics": "^4.1.3"
},
"devDependencies": {
"@types/node": "^16.11.11",
"@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.0.0-beta.4",
"koishi-plugin-pics": "^4.1.3",
"prettier": "^2.5.1",
"raw-loader": "^4.0.2",
"ts-loader": "^9.2.6",
"typescript": "^4.5.2",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"ws": "^8.3.0"
}
}
import 'source-map-support/register';
import { DefineSchema, RegisterSchema } from 'koishi-thirdeye';
import PicsourceHeisi from './index';
import { PicSourceConfig } from 'koishi-plugin-pics';
@RegisterSchema()
export class PicsourceHeisiConfig extends PicSourceConfig {
constructor(config: PicsourceHeisiConfigLike) {
super();
}
@DefineSchema({
description: '黑丝的图源地址。',
default:
'https://cdn.jsdelivr.net/gh/yzyyz1387/blogimages/nonebot/heisi.txt',
})
endpoint: string;
@DefineSchema({
description: '图源的有效时间,单位毫秒。',
default: 24 * 3600 * 1000,
})
ttl: number;
@DefineSchema({
description: '图片描述。',
default: '黑丝',
})
picDescription: string;
}
export type PicsourceHeisiConfigLike = Partial<PicsourceHeisiConfig>;
import 'source-map-support/register';
import { Context, Quester, Cache, Logger, Random } from 'koishi';
import { PicsourceHeisiConfig, PicsourceHeisiConfigLike } from './config';
import {
KoishiPlugin,
InjectConfig,
Inject,
OnApply,
OnConnect,
InjectLogger,
} from 'koishi-thirdeye';
import { PicsContainer, PicSource } from 'koishi-plugin-pics';
export * from './config';
declare module 'koishi' {
interface Modules {
'picsource-heisi': typeof import('.');
}
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cache {
interface Tables {
heisiList: string[];
}
}
}
@KoishiPlugin({ name: 'picsource-heisi', schema: PicsourceHeisiConfig })
export default class PicsourceHeisi
extends PicSource
implements OnApply, OnConnect {
constructor(ctx: Context, config: PicsourceHeisiConfigLike) {
super(ctx);
}
@InjectConfig()
private config: PicsourceHeisiConfig;
@Inject(true)
private http: Quester;
@Inject(true)
private pics: PicsContainer;
@Inject(true)
private cache: Cache;
@InjectLogger()
private logger: Logger;
onApply() {
this.config.applyTo(this);
this.cache.table('heisiList', { maxAge: this.config.ttl });
}
async onConnect() {
await this.getRandomUrl();
this.pics.addSource(this, this.ctx);
}
async randomPic() {
const url = await this.getRandomUrl();
if (!url) return;
return {
url,
description: this.config.picDescription,
};
}
async getRandomUrl() {
const list = await this.cache.get('heisiList', 'list');
if (!list || !list.length) {
await this.fetchPicList();
}
if (!list || !list.length) {
return;
}
return Random.pick(list);
}
async fetchPicList() {
try {
const content = await this.http.get(this.config.endpoint);
const urls = content
.trim()
.split('\n')
.map((line) => line.trim())
.filter((line) => line.startsWith('http'));
await this.cache.set('heisiList', 'list', urls);
this.logger.info(
`fetched ${urls.length} pics from ${this.config.endpoint}`,
);
} catch (e) {
this.logger.error(
`Failed to fetch pic list from ${
this.config.endpoint
}: ${e.toString()}`,
);
}
}
}
{
"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