@kotori-bot/core
Version:
Kotori Core
140 lines (139 loc) • 3.56 kB
TypeScript
import I18n from '@kotori-bot/i18n';
import { Http } from '@kotori-bot/tools';
import FluoroContext from 'fluoro';
import type { Parser } from 'tsukiko';
import { type Api, Cache } from '../components';
import { Symbols } from '../global';
import type { AdapterClass } from '../types';
import type { EventsMapping } from '../types/events';
import Config from './config';
import Message from './message';
export interface Context {
/**
* Adapter constructors list.
*
* @readonly
*/
readonly [Symbols.adapter]: Context[typeof Symbols.adapter];
/**
* Bot instances list.
*
* @readonly
*/
readonly [Symbols.bot]: Context[typeof Symbols.bot];
/**
* Core config.
*
* @readonly
*/
readonly config: Config['config'];
/**
* Meta information.
*
* @readonly
*/
readonly meta: Config['meta'];
/**
* Registered middlewares list.
*
* @readonly
*/
readonly [Symbols.midware]: Message[typeof Symbols.midware];
/**
* Registered commands list.
*
* @readonly
*/
readonly [Symbols.command]: Message[typeof Symbols.command];
/**
* Registered regexps list.
*
* @readonly
*/
readonly [Symbols.regexp]: Message[typeof Symbols.regexp];
/**
* Registered scheduled tasks list.
*
* @readonly
*/
readonly [Symbols.task]: Message[typeof Symbols.task];
/**
* Registered session filters list.
*
* @readonly
*/
readonly [Symbols.filter]: Message[typeof Symbols.filter];
/**
* Session promises in progress list.
*
* @readonly
*/
readonly [Symbols.promise]: Message[typeof Symbols.promise];
/**
* Register a message handled middleware.
*
* @param callback - Middleware callback
* @param priority - Middleware priority, default is 100
* @returns dispose function
*/
midware: Message['midware'];
/**
* Register a command.
*
* @param template - Command template
* @param config - Command config, optional
* @returns Command instance
*/
command: Message['command'];
/**
* Register a regexp.
*
* @param match - Regexp to match
* @param callback - Regexp callback
* @returns dispose function
*/
regexp: Message['regexp'];
/**
* Register a scheduled task.
*
* @param options - Task options
* @param callback - Task callback
* @returns dispose function
*/
task: Message['task'];
/**
* Register a session filter.
*
* @param option - Filter option
* @returns new context
*/
filter: Message['filter'];
/**
* Send a notified message to the master of first bot instance at config.
*
* @experimental
*/
notify: Message['notify'];
/**
* Send a message to all sessions on all bots.
*
* @experimental
*/
boardcast: Message['boardcast'];
/** Http request methods */
http: Http;
/** International methods */
i18n: I18n;
/** Cache service */
cache: Cache;
}
export declare class Context extends FluoroContext<EventsMapping> implements Context {
readonly [Symbols.adapter]: Map<string, [AdapterClass, Parser<unknown>?]>;
readonly [Symbols.bot]: Map<string, Set<Api>>;
constructor(config?: ConstructorParameters<typeof Config>[0]);
start(): void;
stop(): void;
}
export type Core = Context;
export declare const Core: typeof Context;
export default Core;