New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

koishi-plugin-common

Package Overview
Dependencies
Maintainers
1
Versions
141
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koishi-plugin-common - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

dist/authorize.d.ts

2

dist/admin.d.ts
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) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc