Commit fba3555b authored by nanahira's avatar nanahira

add pics component support

parent 01899cb8
import { Awaitable, Context, Schema } from 'koishi'; import { Awaitable, Context, Schema, segment } from 'koishi';
import { import {
DefinePlugin, DefinePlugin,
MultiInstancePlugin, MultiInstancePlugin,
...@@ -65,6 +65,8 @@ export default class ExtrasInDev { ...@@ -65,6 +65,8 @@ export default class ExtrasInDev {
isDefault: true, isDefault: true,
// endpoint: 'https://cdn02.moecube.com:444', // endpoint: 'https://cdn02.moecube.com:444',
}); });
ctx.command('pic2').action(() => segment('pics'));
} }
static using = ['pics'] as const; static using = ['pics'] as const;
......
This diff is collapsed.
...@@ -28,13 +28,13 @@ ...@@ -28,13 +28,13 @@
"homepage": "https://github.com/koishijs/koishi-plugin-pics", "homepage": "https://github.com/koishijs/koishi-plugin-pics",
"dependencies": { "dependencies": {
"@koishijs/assets": "^1.0.1", "@koishijs/assets": "^1.0.1",
"koishi-thirdeye": "^11.1.14", "koishi-thirdeye": "^11.1.17",
"lodash": "^4.17.21" "lodash": "^4.17.21"
}, },
"devDependencies": { "devDependencies": {
"@koishijs/plugin-console": "^4.7.1", "@koishijs/plugin-console": "^5.0.0",
"@koishijs/plugin-database-memory": "^2.0.1", "@koishijs/plugin-database-memory": "^2.0.1",
"@koishijs/plugin-sandbox": "^2.4.0", "@koishijs/plugin-sandbox": "^2.5.0",
"@types/jest": "^29.2.0", "@types/jest": "^29.2.0",
"@types/lodash": "^4.14.176", "@types/lodash": "^4.14.176",
"@types/node": "^16.11.4", "@types/node": "^16.11.4",
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
"ws": "^8.3.0" "ws": "^8.3.0"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.10.4" "koishi": "^4.10.10"
}, },
"jest": { "jest": {
"moduleFileExtensions": [ "moduleFileExtensions": [
......
// import 'source-map-support/register'; // import 'source-map-support/register';
import { Context, Random, Logger, Bot, remove } from 'koishi'; import { Context, Random, Logger, Bot, remove, Session, Dict } from 'koishi';
import { PicsPluginConfig } from './config'; import { PicsPluginConfig } from './config';
import _ from 'lodash'; import _ from 'lodash';
import { segment, Quester } from 'koishi'; import { segment, Quester, Element } from 'koishi';
import { import {
StarterPlugin, StarterPlugin,
Caller, Caller,
...@@ -14,11 +14,11 @@ import { ...@@ -14,11 +14,11 @@ import {
LifecycleEvents, LifecycleEvents,
Provide, Provide,
PutArgs, PutArgs,
PutBot,
PutOption, PutOption,
PutRenderer, PutRenderer,
Renderer, Renderer,
UseCommand, UseCommand,
UseComponent,
} from 'koishi-thirdeye'; } from 'koishi-thirdeye';
import { AxiosRequestConfig } from 'axios'; import { AxiosRequestConfig } from 'axios';
import { PicAssetsTransformMiddleware } from './middlewares/assets'; import { PicAssetsTransformMiddleware } from './middlewares/assets';
...@@ -322,4 +322,19 @@ export default class PicsContainer ...@@ -322,4 +322,19 @@ export default class PicsContainer
this._http = this.http.extend(this.config.httpConfig); this._http = this.http.extend(this.config.httpConfig);
this.installDefaultMiddlewares(); this.installDefaultMiddlewares();
} }
@UseComponent('pics')
async picsComponent(attrs: Dict<any>, children: Element[], session: Session) {
const tags = attrs.tags?.split(/[ ,+\uFF0C\uFF0B\u3001]/) || [];
const sourceTags = attrs.source?.split(/[ ,+\uFF0C\uFF0B\u3001]/) || [];
const result = await this.randomPic(tags, sourceTags);
if (!result) {
return attrs.fallback || '';
}
const segment = await this.getSegment(result.url);
if (result.description) {
segment.attrs.description = result.description;
}
return segment;
}
} }
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