koishi-plugin-pixluna
Version:
374 lines (373 loc) • 12.7 kB
TypeScript
import { Schema, Context, Logger, h, Bot, Element } from 'koishi';
export interface Config {
isR18: boolean;
r18P: number;
excludeAI: boolean;
isProxy: boolean;
proxyHost: string;
baseUrl: string;
maxConcurrency: number;
forwardMessage: boolean;
defaultSourceProvider: string[];
isLog: boolean;
pixiv: {
phpSESSID: string;
userId: string;
};
danbooru?: {
keyPairs: {
login: string;
apiKey: string;
}[];
};
e621?: {
keyPairs: {
login: string;
apiKey: string;
}[];
};
gelbooru?: {
keyPairs: {
apiKey: string;
}[];
};
lolibooru?: {
keyPairs: {
login: string;
password: string;
}[];
};
sankaku?: {
keyPairs: {
login: string;
password: string;
tokenType?: string;
accessToken?: string;
}[];
};
konachan?: {
keyPairs: {
login: string;
password: string;
}[];
};
yande?: {
keyPairs: {
login: string;
password: string;
}[];
};
imageProcessing: {
confusion: boolean;
compress: boolean;
compressQuality: number;
isFlip: boolean;
flipMode: 'horizontal' | 'vertical' | 'both';
};
autoRecall: {
enable: boolean;
delay: number;
};
messageBefore: string;
showTags: boolean;
}
export const Config: Schema<Config>;
export const name = "pixluna";
export type ImageMimeType = 'jpg' | 'jpeg' | 'png' | 'gif';
export interface ImageMetaData {
url: string;
urls: {
regular?: string;
original?: string;
};
raw: GeneralImageData;
}
export interface GeneralImageData {
id: number | string;
title: string;
author: string;
r18: boolean;
tags: string[];
extension: string;
aiType: number;
uploadDate: number;
urls: {
regular?: string;
original: string;
};
}
export interface CommonSourceRequest {
tag?: string;
size?: string[];
r18?: boolean;
excludeAI?: boolean;
proxy?: string;
}
export interface CommonSourceResponse {
image: ArrayBuffer;
metaData: ImageMetaData;
}
export type SourceResponseStatus = 'success' | 'error';
export type SourceResponse<T, U extends SourceResponseStatus = SourceResponseStatus> = U extends 'success' ? {
status: U;
data: T;
} : U extends 'error' ? {
status: U;
data: Error | string | null | undefined;
} : {
status: SourceResponseStatus;
data: any;
};
export interface ImageSourceMeta {
referer?: string;
}
export abstract class SourceProvider {
static description: string;
protected config: Config;
protected ctx: Context;
constructor(ctx: Context, config: Config);
abstract getMetaData(props: {
context: Context;
}, request: CommonSourceRequest): Promise<SourceResponse<ImageMetaData>>;
abstract setConfig(config: Config): void;
abstract getMeta(): ImageSourceMeta;
}
export function shuffleArray<T>(array: T[]): T[];
export function createLogger(ctx: Context, name?: string): Logger;
export function setLoggerLevel(level: number): void;
export class ParallelPool<T = any> {
private readonly pool;
private readonly limit;
constructor(limit: number);
add<R extends T>(promise: Promise<R>): this;
add<R extends T>(promise: Promise<R>[]): this;
run(): Promise<any[]>;
}
export function taskTime<T>(ctx: Context, name: string, task: () => Promise<T>): Promise<T>;
export function qualityImage(_ctx: Context, imageBuffer: Buffer, config: Config): Promise<Buffer<any>>;
export function mixImage(ctx: Context, imageBuffer: Buffer, config: Config): Promise<Buffer<any>>;
export function processImage(ctx: Context, imageBuffer: Buffer, config: Config, hasRegularUrl: boolean): Promise<Buffer>;
export class DanbooruSourceProvider extends SourceProvider {
static description: string;
protected endpoint: string;
private keyPairs;
setConfig(config: Config): void;
private get keyPair();
getMetaData({ context }: {
context: Context;
}, props: CommonSourceRequest): Promise<SourceResponse<ImageMetaData>>;
getMeta(): ImageSourceMeta;
}
export class E621SourceProvider extends SourceProvider {
static description: string;
protected endpoint: string;
private keyPairs;
setConfig(config: Config): void;
private get keyPair();
getMetaData({ context }: {
context: Context;
}, props: CommonSourceRequest): Promise<SourceResponse<ImageMetaData>>;
getMeta(): ImageSourceMeta;
}
export class GelbooruSourceProvider extends SourceProvider {
static description: string;
protected endpoint: string;
private get keyPair();
getMetaData({ context }: {
context: Context;
}, props: CommonSourceRequest): Promise<SourceResponse<ImageMetaData>>;
getMeta(): ImageSourceMeta;
setConfig(config: Config): void;
}
export class KonachanSourceProvider extends SourceProvider {
static description: string;
protected endpoint: string;
private keyPairs;
private hashPassword;
setConfig(config: Config): void;
private get keyPair();
getMetaData({ context }: {
context: Context;
}, props: CommonSourceRequest): Promise<SourceResponse<ImageMetaData>>;
getMeta(): ImageSourceMeta;
}
export class LolibooruSourceProvider extends SourceProvider {
static description: string;
protected endpoint: string;
private keyPairs;
setConfig(config: Config): void;
private get keyPair();
getMetaData({ context }: {
context: Context;
}, props: CommonSourceRequest): Promise<SourceResponse<ImageMetaData>>;
getMeta(): ImageSourceMeta;
}
export interface LoliconLikeSourceRequest {
r18?: number;
num?: number;
uid?: number[];
keyword?: string;
tag?: string[];
size?: string[];
proxy?: string;
excludeAI?: boolean;
}
export interface LoliconLikeResponse {
error: string;
data: {
pid: number;
p: number;
uid: number;
title: string;
author: string;
r18: boolean;
tags: string[];
ext: string;
aiType: number;
uploadDate: number;
urls: {
original: string;
regular?: string;
};
}[];
}
export abstract class LoliconLikeProvider extends SourceProvider {
protected ctx: Context;
protected config: Config;
protected abstract API_URL: string;
constructor(ctx: Context, config: Config);
getMetaData({ context }: {
context: Context;
}, props: CommonSourceRequest): Promise<SourceResponse<ImageMetaData>>;
setConfig(config: Config): void;
getMeta(): ImageSourceMeta;
}
export class LolisukiSourceProvider extends LoliconLikeProvider {
static description: string;
protected API_URL: string;
}
export class LoliconSourceProvider extends LoliconLikeProvider {
static description: string;
protected API_URL: string;
}
export class SafebooruSourceProvider extends SourceProvider {
static description: string;
protected endpoint: string;
getMetaData({ context }: {
context: Context;
}, props: CommonSourceRequest): Promise<SourceResponse<ImageMetaData>>;
getMeta(): ImageSourceMeta;
setConfig(config: Config): void;
}
export class SankakuSourceProvider extends SourceProvider {
static description: string;
protected endpoint: string;
protected http: Context['http'];
constructor(ctx: Context, config: Config);
private get keyPair();
private login;
getMetaData(_: {
context: Context;
}, props: CommonSourceRequest): Promise<SourceResponse<ImageMetaData>>;
getMeta(): ImageSourceMeta;
setConfig(config: Config): void;
}
export class YandeSourceProvider extends SourceProvider {
static description: string;
protected endpoint: string;
private keyPairs;
private hashPassword;
setConfig(config: Config): void;
private get keyPair();
getMetaData({ context }: {
context: Context;
}, props: CommonSourceRequest): Promise<SourceResponse<ImageMetaData>>;
getMeta(): ImageSourceMeta;
}
export type ProviderTypes = 'danbooru' | 'e621' | 'gelbooru' | 'konachan' | 'lolibooru' | 'lolicon' | 'lolisuki' | 'pdiscovery' | 'pfollowing' | 'safebooru' | 'sankaku' | 'yande';
export const Providers: {
[K in ProviderTypes]: typeof SourceProvider & {
description: string;
};
};
export function getProvider(ctx: Context, config: Config, specificProvider?: string): SourceProvider;
export function detectMimeType(buffer: ArrayBuffer): string;
export const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36";
export function fetchImageBuffer(ctx: Context, config: Config, url: string, provider?: SourceProvider): Promise<[ArrayBuffer, string]>;
export function getRemoteImage(ctx: Context, tag: string, config: Config, specificProvider?: string): Promise<GeneralImageData & {
data: Buffer;
mimeType: string;
raw: GeneralImageData;
}>;
export function renderImageMessage(image: GeneralImageData & {
data: Buffer;
mimeType: string;
}, config?: Config): h;
export function createAtMessage(userId: string, content: string): h;
export function renderMultipleImageMessage(images: (GeneralImageData & {
data: Buffer;
mimeType: string;
})[], config?: Config): h;
export function render(ctx: Context, config: Config, tag?: string, specificProvider?: string): Promise<h>;
export function deleteMessage(ctx: Context, bot: Bot, channelId: string, messageId: string): Promise<void>;
export function setupAutoRecall(ctx: Context, session: any, messageIds: string[], timeout?: number): Promise<void>;
export let logger: Logger;
export function apply(ctx: Context, config: Config): void;
abstract class PixivBaseProvider extends SourceProvider {
protected getHeaders(): {
Referer: string;
'User-Agent': string;
Cookie: string;
};
protected getProxyAgent(): string;
protected constructImageUrl(originalUrl: string): string;
protected fetchPixivData<T>(context: Context, url: string): Promise<T>;
setConfig(config: Config): void;
getMeta(): ImageSourceMeta;
}
export class PixivDiscoverySourceProvider extends PixivBaseProvider {
static DISCOVERY_URL: string;
static ILLUST_PAGES_URL: string;
getMetaData({ context }: {
context: Context;
}, props: CommonSourceRequest): Promise<SourceResponse<ImageMetaData>>;
}
export class PixivFollowingSourceProvider extends PixivBaseProvider {
static description: string;
static FOLLOWING_URL: string;
static USER_PROFILE_URL: string;
static ILLUST_URL: string;
getMetaData({ context }: {
context: Context;
}, props?: CommonSourceRequest): Promise<SourceResponse<ImageMetaData>>;
private getAllFollowingUsers;
private getUserProfile;
private getIllustDetail;
}
export class PixivGetByIDProvider extends PixivBaseProvider {
static description: string;
static ILLUST_URL: string;
getImageByPid(context: Context, pid: string, page?: number): Promise<SourceResponse<ImageMetaData>>;
private getIllustDetail;
getMetaData(): Promise<SourceResponse<ImageMetaData>>;
getImageWithBuffer(pid: string, page?: number): Promise<GeneralImageData & {
data: Buffer;
mimeType: string;
}>;
getImageWithAtMessage(userId: string, options: {
pid: string;
page: number;
}): Promise<string | Element>;
getAllImagesWithAtMessage(userId: string, options: {
pid: string;
page: number;
}): Promise<string | Element>;
}
export function getPixivImageByID(ctx: Context, config: Config, userId: string, options: {
pid: string;
page: number;
all?: boolean;
}): Promise<string | import("koishi").Element>;
export function commandGet(ctx: Context, config: Config): void;
export function commandSource(ctx: Context, _config: Config): void;
export function registerCommand(ctx: Context, config: Config): void;