koishi-plugin-pics
Version:
65 lines (64 loc) • 2.31 kB
TypeScript
/// <reference types="node" />
import { Context, Session, Dict } from 'koishi';
import { PicsPluginConfig } from './config';
import { segment, Element } from 'koishi';
import { LifecycleEvents, Renderer } from 'koishi-thirdeye';
import { PicMiddleware, PicResult } from './def';
import { PicSource } from './picsource';
export * from './config';
export * from './middleware';
export * from './picsource';
export * from './def';
declare module 'koishi' {
interface Context {
pics: PicsContainer;
}
}
declare const PicsContainer_base: new (ctx: Context, config: {
commandName?: string;
useAssets?: boolean;
useBase64?: boolean;
httpConfig?: {
headers?: {
[x: string]: any;
};
endpoint?: string;
timeout?: number;
proxyAgent?: string;
};
preferFile?: boolean;
}) => {
ctx: Context;
config: PicsPluginConfig;
};
export default class PicsContainer extends PicsContainer_base implements LifecycleEvents {
private sources;
private picMiddlewares;
private caller;
private logger;
private http;
private _http;
addSource(source: PicSource, targetCtx?: Context): void;
removeSource(source: PicSource): Promise<void>;
private allSources;
middleware(mid: PicMiddleware, targetCtx?: Context): void;
removeMiddlware(mid: PicMiddleware): void;
pickAvailableSources(sourceTags?: string[], includeNonDefault?: boolean): PicSource[];
randomSourceWithWeight(sources?: PicSource[]): PicSource;
private retryWithAnotherSource;
private fetchPicsWithSources;
randomPic(picTags?: string[], sourceTags?: string[]): Promise<PicResult>;
urlToBuffer(url: string): Promise<{
buffer: Buffer;
mime: string;
}>;
bufferToUrl(buffer: Buffer, mime?: string): Promise<string>;
download(url: string): Promise<string>;
resolveUrl(url: string, middlewares?: PicMiddleware[]): Promise<string>;
getSegment(url: string): Promise<segment>;
private installDefaultMiddlewares;
onPic(source: string, picTags: string[], notFound: Renderer): Promise<string>;
onQuerySource(sourceTags: string[], list: Renderer): Promise<string>;
onApply(): void;
picsComponent(attrs: Dict<any>, children: Element[], session: Session): Promise<any>;
}