koishi-plugin-common
Advanced tools
Comparing version 0.1.0 to 0.1.1
import { Context, Meta, UserField, CommandConfig, GroupField, UserData, GroupData } from 'koishi-core'; | ||
import { Observed } from 'koishi-utils'; | ||
declare type ActionCallback<T extends {}, K extends keyof T> = (this: Context, meta: Meta, target: Observed<Pick<T, K>>, ...args: string[]) => Promise<void>; | ||
declare type ActionCallback<T extends {}, K extends keyof T> = (this: Context, meta: Meta, target: Observed<Pick<T, K>>, ...args: string[]) => Promise<any>; | ||
export interface UserAction { | ||
@@ -5,0 +5,0 @@ callback: ActionCallback<UserData, UserField>; |
import { Context, CommandConfig } from 'koishi-core'; | ||
import admin from './admin'; | ||
import authorize from './authorize'; | ||
import broadcast, { BroadcastOptions } from './broadcast'; | ||
import callme, { CallmeOptions } from './callme'; | ||
import echo from './echo'; | ||
import exit from './exit'; | ||
import help from './help'; | ||
@@ -13,21 +15,21 @@ import rank from './rank'; | ||
export * from './admin'; | ||
export * from './authorize'; | ||
export * from './exit'; | ||
export * from './rank'; | ||
export { admin, broadcast, callme, echo, help, rank, repeater, requestHandler, respondent, welcome }; | ||
declare module 'koishi-core/dist/app' { | ||
interface AppOptions { | ||
pluginConfig?: { | ||
admin?: false | CommandConfig; | ||
broadcast?: false | BroadcastOptions; | ||
callme?: false | CallmeOptions; | ||
echo?: false | CommandConfig; | ||
help?: false | CommandConfig; | ||
rank?: false | CommandConfig; | ||
repeater?: false | RepeaterOptions; | ||
requestHandler?: false | HandlerOptions; | ||
respondent?: false | Respondent[]; | ||
welcome?: false | WelcomeMessage; | ||
}; | ||
} | ||
export { admin, authorize, broadcast, callme, echo, exit, help, rank, repeater, requestHandler, respondent, welcome }; | ||
interface CommonPluginOptions { | ||
admin?: false | CommandConfig; | ||
authorize?: false | Record<number, number>; | ||
broadcast?: false | BroadcastOptions; | ||
callme?: false | CallmeOptions; | ||
echo?: false | CommandConfig; | ||
exit?: false | CommandConfig; | ||
help?: false | CommandConfig; | ||
rank?: false | CommandConfig; | ||
repeater?: false | RepeaterOptions; | ||
requestHandler?: false | HandlerOptions; | ||
respondent?: false | Respondent[]; | ||
welcome?: false | WelcomeMessage; | ||
} | ||
export declare const name = "common"; | ||
export declare function apply(ctx: Context): void; | ||
export declare function apply(ctx: Context, options?: CommonPluginOptions): void; |
@@ -11,2 +11,4 @@ "use strict"; | ||
exports.admin = admin_1.default; | ||
const authorize_1 = __importDefault(require("./authorize")); | ||
exports.authorize = authorize_1.default; | ||
const broadcast_1 = __importDefault(require("./broadcast")); | ||
@@ -18,2 +20,4 @@ exports.broadcast = broadcast_1.default; | ||
exports.echo = echo_1.default; | ||
const exit_1 = __importDefault(require("./exit")); | ||
exports.exit = exit_1.default; | ||
const help_1 = __importDefault(require("./help")); | ||
@@ -32,16 +36,21 @@ exports.help = help_1.default; | ||
__export(require("./admin")); | ||
__export(require("./authorize")); | ||
__export(require("./exit")); | ||
__export(require("./rank")); | ||
exports.name = 'common'; | ||
function apply(ctx) { | ||
const { pluginConfig = {} } = ctx.app.options; | ||
function apply(ctx, options = {}) { | ||
ctx | ||
.plugin(admin_1.default, pluginConfig.admin) | ||
.plugin(echo_1.default, pluginConfig.echo) | ||
.plugin(help_1.default, pluginConfig.help) | ||
.plugin(rank_1.default, pluginConfig.rank) | ||
.plugin(repeater_1.default, pluginConfig.repeater) | ||
.plugin(requestHandler_1.default, pluginConfig.requestHandler) | ||
.plugin(respondent_1.default, pluginConfig.respondent) | ||
.plugin(welcome_1.default, pluginConfig.welcome); | ||
.plugin(admin_1.default, options.admin) | ||
.plugin(authorize_1.default, options.authorize) | ||
.plugin(broadcast_1.default, options.broadcast) | ||
.plugin(callme_1.default, options.callme) | ||
.plugin(echo_1.default, options.echo) | ||
.plugin(exit_1.default, options.exit) | ||
.plugin(help_1.default, options.help) | ||
.plugin(rank_1.default, options.rank) | ||
.plugin(repeater_1.default, options.repeater) | ||
.plugin(requestHandler_1.default, options.requestHandler) | ||
.plugin(respondent_1.default, options.respondent) | ||
.plugin(welcome_1.default, options.welcome); | ||
} | ||
exports.apply = apply; |
@@ -33,3 +33,3 @@ "use strict"; | ||
options = { ...defaultOptions, ...options }; | ||
ctx.app.receiver.on('send/group', ({ groupId, message }) => { | ||
ctx.app.groups.receiver.on('send', ({ groupId, message }) => { | ||
const state = getState(groupId); | ||
@@ -46,3 +46,3 @@ state.repeated = true; | ||
}); | ||
ctx.middleware(({ message, groupId, userId, $send, $group }, next) => { | ||
ctx.premiddleware(({ message, groupId, userId, $send, $group }, next) => { | ||
const state = getState(groupId); | ||
@@ -74,4 +74,4 @@ if (!$group || $group.assignee !== ctx.app.options.selfId) | ||
return next(); | ||
}, 0); | ||
}); | ||
} | ||
exports.default = apply; |
import { App, Meta } from 'koishi-core'; | ||
declare type RequestHandler = boolean | ((meta: Meta, app: App) => boolean | void | Promise<boolean | void>); | ||
declare type RequestHandler = boolean | ((meta: Meta<'request'>, app: App) => boolean | void | Promise<boolean | void>); | ||
export interface HandlerOptions { | ||
@@ -4,0 +4,0 @@ handleFriend?: RequestHandler; |
@@ -20,3 +20,3 @@ "use strict"; | ||
const { handleFriend, handleGroupAdd, handleGroupInvite } = { ...defaultHandlers, ...options }; | ||
ctx.receiver.on('request/friend', async (meta) => { | ||
ctx.users.receiver.on('request', async (meta) => { | ||
const result = await getHandleResult(handleFriend, meta, ctx); | ||
@@ -27,3 +27,3 @@ if (typeof result === 'boolean') { | ||
}); | ||
ctx.receiver.on('request/group/add', async (meta) => { | ||
ctx.groups.receiver.on('request/add', async (meta) => { | ||
const result = await getHandleResult(handleGroupAdd, meta, ctx); | ||
@@ -34,3 +34,3 @@ if (typeof result === 'boolean') { | ||
}); | ||
ctx.receiver.on('request/group/invite', async (meta) => { | ||
ctx.groups.receiver.on('request/invite', async (meta) => { | ||
const result = await getHandleResult(handleGroupInvite, meta, ctx); | ||
@@ -37,0 +37,0 @@ if (typeof result === 'boolean') { |
import { App, Meta } from 'koishi-core'; | ||
export declare type WelcomeMessage = string | ((meta: Meta) => string | Promise<string>); | ||
export declare type WelcomeMessage = string | ((meta: Meta<'notice'>) => string | Promise<string>); | ||
export default function apply(ctx: App, message?: WelcomeMessage): void; |
{ | ||
"name": "koishi-plugin-common", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "dist/index.js", | ||
@@ -21,8 +21,10 @@ "typings": "dist/index.d.ts", | ||
"eslint-plugin-standard": "^4.0.1", | ||
"husky": "^3.1.0", | ||
"koishi-database-mysql": "0.1.2", | ||
"typescript": "^3.7.2" | ||
}, | ||
"dependencies": { | ||
"koishi-core": "^0.1.1", | ||
"koishi-core": "^0.2.1", | ||
"koishi-utils": "^0.1.4" | ||
} | ||
} |
@@ -5,3 +5,3 @@ import { Context, User, userFlags, UserFlag, Meta, UserField, getTargetId, CommandConfig, GroupField, UserData, GroupData } from 'koishi-core' | ||
type ActionCallback <T extends {}, K extends keyof T> = | ||
(this: Context, meta: Meta, target: Observed<Pick<T, K>>, ...args: string[]) => Promise<void> | ||
(this: Context, meta: Meta, target: Observed<Pick<T, K>>, ...args: string[]) => Promise<any> | ||
@@ -8,0 +8,0 @@ export interface UserAction { |
@@ -1,2 +0,2 @@ | ||
import { MessageType, Context, CommandConfig } from 'koishi-core' | ||
import { MetaTypeMap, Context, CommandConfig } from 'koishi-core' | ||
@@ -14,3 +14,3 @@ export default function (ctx: Context, options: CommandConfig) { | ||
discuss: options.discuss ? options.discuss.split(',') : [], | ||
} as Record<MessageType, number[]> | ||
} as Record<MetaTypeMap['message'], number[]> | ||
if (!channels.private.length && !channels.group.length && !channels.discuss.length) { | ||
@@ -17,0 +17,0 @@ channels[meta.messageType].push(meta.messageType === 'private' ? meta.userId : meta[meta.messageType + 'Id']) |
@@ -1,2 +0,2 @@ | ||
import { Context, Command, isAncestor, UserData, Meta, CommandConfig } from 'koishi-core' | ||
import { Context, Command, isAncestor, UserData, CommandConfig, MessageMeta } from 'koishi-core' | ||
@@ -29,3 +29,3 @@ export default function apply (ctx: Context, options: CommandConfig) { | ||
function getCommands (context: Context, meta: Meta, parent?: Command) { | ||
function getCommands (context: Context, meta: MessageMeta, parent?: Command) { | ||
const commands = parent | ||
@@ -39,3 +39,3 @@ ? parent.children | ||
function showGlobalShortcut (context: Context, meta: Meta) { | ||
function showGlobalShortcut (context: Context, meta: MessageMeta) { | ||
const commands = getCommands(context, meta) | ||
@@ -46,3 +46,3 @@ const shortcuts = [].concat(...commands.map(command => getShortcuts(command, meta.$user))) | ||
function getCommandList (context: Context, meta: Meta, parent: Command, expand: boolean) { | ||
function getCommandList (context: Context, meta: MessageMeta, parent: Command, expand: boolean) { | ||
let commands = getCommands(context, meta, parent) | ||
@@ -66,3 +66,3 @@ if (!expand) { | ||
function showGlobalHelp (context: Context, meta: Meta, options: any) { | ||
function showGlobalHelp (context: Context, meta: MessageMeta, options: any) { | ||
return meta.$send([ | ||
@@ -79,3 +79,3 @@ '当前可用的指令有(括号内为对应的最低权限等级,标有星号的表示含有子指令):', | ||
async function showCommandHelp (command: Command, meta: Meta, options: any) { | ||
async function showCommandHelp (command: Command, meta: MessageMeta, options: any) { | ||
const output = [command.rawName, command.config.description] | ||
@@ -106,3 +106,3 @@ if (command.context.database) { | ||
} | ||
if (authorityHint) { | ||
@@ -109,0 +109,0 @@ output.push(authorityHint) |
import { Context, CommandConfig } from 'koishi-core' | ||
import admin from './admin' | ||
import authorize from './authorize' | ||
import broadcast, { BroadcastOptions } from './broadcast' | ||
import callme, { CallmeOptions } from './callme' | ||
import echo from './echo' | ||
import exit from './exit' | ||
import help from './help' | ||
@@ -14,21 +16,21 @@ import rank from './rank' | ||
export * from './admin' | ||
export * from './authorize' | ||
export * from './exit' | ||
export * from './rank' | ||
export { admin, broadcast, callme, echo, help, rank, repeater, requestHandler, respondent, welcome } | ||
export { admin, authorize, broadcast, callme, echo, exit, help, rank, repeater, requestHandler, respondent, welcome } | ||
declare module 'koishi-core/dist/app' { | ||
interface AppOptions { | ||
pluginConfig?: { | ||
admin?: false | CommandConfig | ||
broadcast?: false | BroadcastOptions | ||
callme?: false | CallmeOptions | ||
echo?: false | CommandConfig | ||
help?: false | CommandConfig | ||
rank?: false | CommandConfig | ||
repeater?: false | RepeaterOptions | ||
requestHandler?: false | HandlerOptions | ||
respondent?: false | Respondent[] | ||
welcome?: false | WelcomeMessage | ||
} | ||
} | ||
interface CommonPluginOptions { | ||
admin?: false | CommandConfig | ||
authorize?: false | Record<number, number> | ||
broadcast?: false | BroadcastOptions | ||
callme?: false | CallmeOptions | ||
echo?: false | CommandConfig | ||
exit?: false | CommandConfig | ||
help?: false | CommandConfig | ||
rank?: false | CommandConfig | ||
repeater?: false | RepeaterOptions | ||
requestHandler?: false | HandlerOptions | ||
respondent?: false | Respondent[] | ||
welcome?: false | WelcomeMessage | ||
} | ||
@@ -38,14 +40,16 @@ | ||
export function apply (ctx: Context) { | ||
const { pluginConfig = {} } = ctx.app.options | ||
export function apply (ctx: Context, options: CommonPluginOptions = {}) { | ||
ctx | ||
.plugin(admin, pluginConfig.admin) | ||
.plugin(echo, pluginConfig.echo) | ||
.plugin(help, pluginConfig.help) | ||
.plugin(rank, pluginConfig.rank) | ||
.plugin(repeater, pluginConfig.repeater) | ||
.plugin(requestHandler, pluginConfig.requestHandler) | ||
.plugin(respondent, pluginConfig.respondent) | ||
.plugin(welcome, pluginConfig.welcome) | ||
.plugin(admin, options.admin) | ||
.plugin(authorize, options.authorize) | ||
.plugin(broadcast, options.broadcast) | ||
.plugin(callme, options.callme) | ||
.plugin(echo, options.echo) | ||
.plugin(exit, options.exit) | ||
.plugin(help, options.help) | ||
.plugin(rank, options.rank) | ||
.plugin(repeater, options.repeater) | ||
.plugin(requestHandler, options.requestHandler) | ||
.plugin(respondent, options.respondent) | ||
.plugin(welcome, options.welcome) | ||
} |
@@ -59,3 +59,3 @@ import { GroupContext } from 'koishi-core' | ||
ctx.app.receiver.on('send/group', ({ groupId, message }) => { | ||
ctx.app.groups.receiver.on('send', ({ groupId, message }) => { | ||
const state = getState(groupId) | ||
@@ -72,3 +72,3 @@ state.repeated = true | ||
ctx.middleware(({ message, groupId, userId, $send, $group }, next) => { | ||
ctx.premiddleware(({ message, groupId, userId, $send, $group }, next) => { | ||
const state = getState(groupId) | ||
@@ -98,3 +98,3 @@ if (!$group || $group.assignee !== ctx.app.options.selfId) return next() | ||
return next() | ||
}, 0) | ||
}) | ||
} |
import { App, Meta } from 'koishi-core' | ||
type RequestHandler = boolean | ((meta: Meta, app: App) => boolean | void | Promise<boolean | void>) | ||
type RequestHandler = boolean | ((meta: Meta<'request'>, app: App) => boolean | void | Promise<boolean | void>) | ||
@@ -22,3 +22,3 @@ export interface HandlerOptions { | ||
async function getHandleResult (handler: RequestHandler, meta: Meta, ctx: App) { | ||
async function getHandleResult (handler: RequestHandler, meta: Meta<'request'>, ctx: App) { | ||
return typeof handler === 'function' ? handler(meta, ctx) : handler | ||
@@ -30,3 +30,3 @@ } | ||
ctx.receiver.on('request/friend', async (meta) => { | ||
ctx.users.receiver.on('request', async (meta) => { | ||
const result = await getHandleResult(handleFriend, meta, ctx) | ||
@@ -38,3 +38,3 @@ if (typeof result === 'boolean') { | ||
ctx.receiver.on('request/group/add', async (meta) => { | ||
ctx.groups.receiver.on('request/add', async (meta) => { | ||
const result = await getHandleResult(handleGroupAdd, meta, ctx) | ||
@@ -46,3 +46,3 @@ if (typeof result === 'boolean') { | ||
ctx.receiver.on('request/group/invite', async (meta) => { | ||
ctx.groups.receiver.on('request/invite', async (meta) => { | ||
const result = await getHandleResult(handleGroupInvite, meta, ctx) | ||
@@ -49,0 +49,0 @@ if (typeof result === 'boolean') { |
import { App, Meta } from 'koishi-core' | ||
export type WelcomeMessage = string | ((meta: Meta) => string | Promise<string>) | ||
export type WelcomeMessage = string | ((meta: Meta<'notice'>) => string | Promise<string>) | ||
const defaultMessage = (meta: Meta) => `欢迎新大佬 [CQ:at,qq=${meta.userId}]!` | ||
const defaultMessage = (meta: Meta<'notice'>) => `欢迎新大佬 [CQ:at,qq=${meta.userId}]!` | ||
@@ -7,0 +7,0 @@ export default function apply (ctx: App, message: WelcomeMessage = defaultMessage) { |
71486
47
1568
12
+ Addedkoishi-core@0.2.7(transitive)
- Removedaccepts@1.3.8(transitive)
- Removedarray-flatten@1.1.1(transitive)
- Removedbody-parser@1.20.3(transitive)
- Removedbytes@3.1.2(transitive)
- Removedcall-bind-apply-helpers@1.0.2(transitive)
- Removedcall-bound@1.0.3(transitive)
- Removedcontent-disposition@0.5.4(transitive)
- Removedcontent-type@1.0.5(transitive)
- Removedcookie@0.7.1(transitive)
- Removedcookie-signature@1.0.6(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddepd@2.0.0(transitive)
- Removeddestroy@1.2.0(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedee-first@1.1.1(transitive)
- Removedencodeurl@1.0.22.0.0(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.1.1(transitive)
- Removedescape-html@1.0.3(transitive)
- Removedetag@1.8.1(transitive)
- Removedexpress@4.21.2(transitive)
- Removedfinalhandler@1.3.1(transitive)
- Removedforwarded@0.2.0(transitive)
- Removedfresh@0.5.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.3.0(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhttp-errors@2.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedinherits@2.0.4(transitive)
- Removedipaddr.js@1.9.1(transitive)
- Removedkoishi-core@0.1.11(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedmedia-typer@0.3.0(transitive)
- Removedmerge-descriptors@1.0.3(transitive)
- Removedmethods@1.1.2(transitive)
- Removedmime@1.6.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedms@2.0.0(transitive)
- Removednegotiator@0.6.3(transitive)
- Removedobject-inspect@1.13.4(transitive)
- Removedon-finished@2.4.1(transitive)
- Removedparseurl@1.3.3(transitive)
- Removedpath-to-regexp@0.1.12(transitive)
- Removedproxy-addr@2.0.7(transitive)
- Removedqs@6.13.0(transitive)
- Removedrange-parser@1.2.1(transitive)
- Removedraw-body@2.5.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsend@0.19.0(transitive)
- Removedserve-static@1.16.2(transitive)
- Removedsetprototypeof@1.2.0(transitive)
- Removedside-channel@1.1.0(transitive)
- Removedside-channel-list@1.0.0(transitive)
- Removedside-channel-map@1.0.1(transitive)
- Removedside-channel-weakmap@1.0.2(transitive)
- Removedstatuses@2.0.1(transitive)
- Removedtoidentifier@1.0.1(transitive)
- Removedtype-is@1.6.18(transitive)
- Removedunpipe@1.0.0(transitive)
- Removedutils-merge@1.0.1(transitive)
- Removedvary@1.1.2(transitive)
Updatedkoishi-core@^0.2.1