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 3.0.0-beta.16 to 3.0.0

4

dist/handler.js

@@ -21,3 +21,3 @@ "use strict";

});
const { blackList = [], respondents = [], throttle, welcome = defaultMessage } = options;
const { blackList = [], respondents = [], welcome = defaultMessage } = options;
blackList.length && ctx.prependMiddleware((session, next) => {

@@ -39,3 +39,3 @@ for (const word of blackList) {

});
const throttleConfig = !throttle ? [] : Array.isArray(throttle) ? throttle : [throttle];
const throttleConfig = koishi_utils_1.makeArray(options.throttle);
if (throttleConfig.length) {

@@ -42,0 +42,0 @@ const counters = {};

@@ -10,7 +10,2 @@ import { Context } from 'koishi-core';

export interface Config extends HandlerOptions, RepeaterOptions, SenderConfig {
admin?: false;
broadcast?: false;
contextify?: false;
echo?: false;
info?: false;
debug?: DebugOptions;

@@ -17,0 +12,0 @@ }

@@ -28,12 +28,7 @@ "use strict";

ctx.plugin(sender_1.default, config);
if (config.admin !== false)
ctx.plugin(require('./admin'));
if (config.contextify !== false)
ctx.plugin(require('./contextify'));
if (config.debug)
ctx.plugin(require('./debug'), config.debug);
if (config.info !== false)
ctx.plugin(require('./info'));
ctx.plugin(require('./admin'));
ctx.plugin(require('./debug'), config.debug);
ctx.plugin(require('./info'));
}
exports.apply = apply;
//# sourceMappingURL=index.js.map
import { Context } from 'koishi-core';
export interface SenderConfig {
broadcast?: false;
echo?: false;
operator?: number;
}
export default function apply(ctx: Context, config?: SenderConfig): void;

@@ -6,4 +6,3 @@ "use strict";

function apply(ctx, config = {}) {
config.broadcast !== false && ctx
.command('broadcast <message...>', '全服广播', { authority: 4 })
ctx.command('broadcast <message...>', '全服广播', { authority: 4 })
.before(session => !session.$app.database)

@@ -25,4 +24,3 @@ .option('forced', '-f 无视 silent 标签进行广播')

});
config.echo !== false && ctx
.command('echo <message...>', '向当前上下文发送消息', { authority: 2 })
ctx.command('echo <message...>', '向当前上下文发送消息', { authority: 2 })
.option('anonymous', '-a 匿名发送消息', { authority: 3 })

@@ -45,4 +43,88 @@ .option('forceAnonymous', '-A 匿名发送消息', { authority: 3 })

});
const interactions = {};
config.operator && ctx.command('feedback', '发送反馈信息给作者')
.userFields(['name', 'id'])
.action(async ({ session }, text) => {
if (!text)
return '请输入要发送的文本。';
const { $username: name, userId } = session;
const nickname = name === '' + userId ? userId : `${name} (${userId})`;
const message = `收到来自 ${nickname} 的反馈信息:\n${text}`;
const id = await session.$bot.sendPrivateMsg(config.operator, message);
interactions[id] = userId;
return '反馈信息发送成功!';
});
ctx.middleware((session, next) => {
const { $reply, $parsed } = session;
const userId = interactions[$reply];
if (!$parsed || !userId)
return next();
return session.$bot.sendPrivateMsg(userId, $parsed);
});
ctx.command('contextify <message...>', '在特定上下文中触发指令', { authority: 3 })
.alias('ctxf')
.userFields(['authority'])
.before(session => !session.$app.database)
.option('user', '-u [id] 使用私聊上下文')
.option('group', '-g [id] 使用群聊上下文')
.option('member', '-m [id] 使用当前群/讨论组成员上下文')
.option('type', '-t [type] 确定发送信息的子类型')
.usage([
'私聊的子类型包括 other(默认),friend,group。',
'群聊的子类型包括 normal(默认),notice,anonymous。',
'讨论组聊天没有子类型。',
].join('\n'))
.action(async ({ session, options }, message) => {
if (!message)
return '请输入要触发的指令。';
if (options.member) {
if (session.messageType === 'private') {
return '无法在私聊上下文使用 --member 选项。';
}
options.group = session.groupId;
options.user = options.member;
}
if (!options.user && !options.group) {
return '请提供新的上下文。';
}
const newSession = new koishi_core_1.Session(ctx.app, session);
newSession.$send = session.$send.bind(session);
newSession.$sendQueued = session.$sendQueued.bind(session);
delete newSession.groupId;
if (!options.group) {
newSession.messageType = 'private';
newSession.subType = options.type || 'other';
delete newSession.$group;
}
else if (options.group !== session.groupId) {
newSession.groupId = +options.group;
newSession.messageType = 'group';
newSession.subType = options.type || 'normal';
delete newSession.$group;
await newSession.$observeGroup(koishi_core_1.Group.fields);
}
if (options.user) {
const id = koishi_core_1.getTargetId(options.user);
if (!id)
return '未指定目标。';
newSession.userId = id;
newSession.sender.userId = id;
delete newSession.$user;
const user = await newSession.$observeUser(koishi_core_1.User.fields);
if (session.$user.authority <= user.authority) {
return '权限不足。';
}
}
if (options.group) {
const info = await session.$bot.getGroupMemberInfo(newSession.groupId, newSession.userId).catch(() => ({}));
Object.assign(newSession.sender, info);
}
else if (options.user) {
const info = await session.$bot.getStrangerInfo(newSession.userId).catch(() => ({}));
Object.assign(newSession.sender, info);
}
return newSession.$execute(message);
});
}
exports.default = apply;
//# sourceMappingURL=sender.js.map
{
"name": "koishi-plugin-common",
"description": "Common plugins for Koishi",
"version": "3.0.0-beta.16",
"version": "3.0.0",
"main": "dist/index.js",

@@ -34,10 +34,10 @@ "typings": "dist/index.d.ts",

"peerDependencies": {
"koishi-core": "^2.2.0"
"koishi-core": "^2.2.2"
},
"devDependencies": {
"koishi-test-utils": "^5.0.0"
"koishi-test-utils": "^5.0.1"
},
"dependencies": {
"koishi-utils": "^3.1.4"
"koishi-utils": "^3.1.5"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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