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

koishi-core

Package Overview
Dependencies
Maintainers
1
Versions
182
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koishi-core - npm Package Compare versions

Comparing version 1.9.0 to 1.10.0

56

dist/app.js

@@ -89,3 +89,2 @@ "use strict";

let message = koishi_utils_1.simplify(meta.message.trim());
let parsedArgv;
if (meta.messageType !== 'private' && (capture = message.match(this.atMeRE))) {

@@ -106,9 +105,14 @@ atMe = true;

// store parsed message
meta.$parsed = { atMe, nickname, prefix, message };
Object.defineProperty(meta, '$parsed', {
value: { atMe, nickname, prefix, message },
});
// parse as command
if (prefix !== null || nickname || meta.messageType === 'private') {
parsedArgv = this.parseCommandLine(message, meta);
if (!meta.$argv && (prefix !== null || nickname || meta.messageType === 'private')) {
Object.defineProperty(meta, '$argv', {
configurable: true,
value: this.parseCommandLine(message, meta),
});
}
// parse as shortcut
if (!parsedArgv && !prefix) {
if (!meta.$argv && !prefix) {
for (const shortcut of this._shortcuts) {

@@ -129,3 +133,6 @@ const { name, fuzzy, command, oneArg, prefix, options, args = [] } = shortcut;

result.args.unshift(...args);
parsedArgv = { meta, command, ...result };
Object.defineProperty(meta, '$argv', {
configurable: true,
value: { meta, command, ...result },
});
break;

@@ -135,2 +142,9 @@ }

}
if (!meta.$argv) {
Object.defineProperty(meta, '$argv', {
configurable: true,
value: { meta },
});
}
const { command } = meta.$argv;
if (this.database) {

@@ -140,5 +154,7 @@ if (meta.messageType === 'group') {

const groupFields = new Set(['flag', 'assignee']);
this.emitEvent(meta, 'before-group', groupFields, parsedArgv || { meta });
this.emitEvent(meta, 'before-group', groupFields, meta.$argv);
const group = await this.database.observeGroup(meta.groupId, Array.from(groupFields));
Object.defineProperty(meta, '$group', { value: group, writable: true });
// emit attach event
this.emitEvent(meta, 'attach-group', meta);
// ignore some group calls

@@ -148,3 +164,3 @@ const isAssignee = !group.assignee || group.assignee === this.selfId;

const noResponse = group.flag & database_1.GroupFlag.noResponse || !isAssignee;
if (noCommand && parsedArgv)
if (noCommand && command)
return;

@@ -158,3 +174,3 @@ if (noResponse && !atMe)

const userFields = new Set(['flag']);
this.emitEvent(meta, 'before-user', userFields, parsedArgv || { meta });
this.emitEvent(meta, 'before-user', userFields, meta.$argv);
const user = await this.database.observeUser(meta.userId, Array.from(userFields));

@@ -164,2 +180,3 @@ Object.defineProperty(meta, '$user', { value: user, writable: true });

this.emitEvent(meta, 'attach', meta);
this.emitEvent(meta, 'attach-user', meta);
// ignore some user calls

@@ -170,8 +187,8 @@ if (user.flag & database_1.UserFlag.ignore)

// execute command
if (parsedArgv && !parsedArgv.command.getConfig('disable', meta)) {
return parsedArgv.command.execute(parsedArgv, next);
if (command && !command.getConfig('disable', meta)) {
return command.execute(meta.$argv, next);
}
// show suggestions
const target = message.split(/\s/, 1)[0].toLowerCase();
if (!target || !capture || parsedArgv)
if (!target || !capture || command)
return next();

@@ -215,3 +232,3 @@ const executableMap = new Map();

const next = async (fallback) => {
var _a, _b;
var _a;
if (!this._middlewareSet.has(counter)) {

@@ -223,3 +240,3 @@ return this.logger('koishi').warn(new Error(messages_1.errors.ISOLATED_NEXT));

try {
return (_b = (_a = middlewares)[index++]) === null || _b === void 0 ? void 0 : _b.call(_a, meta, next);
return (_a = middlewares[index++]) === null || _a === void 0 ? void 0 : _a.call(middlewares, meta, next);
}

@@ -349,3 +366,3 @@ catch (error) {

async start() {
var _a, _b, _c;
var _a, _b;
this.status = Status.opening;

@@ -356,3 +373,3 @@ this.receiver.emit('before-connect');

for (const type in this.options.database) {
tasks.push((_c = (_a = this.database[type]) === null || _a === void 0 ? void 0 : (_b = _a).start) === null || _c === void 0 ? void 0 : _c.call(_b));
tasks.push((_b = (_a = this.database[type]) === null || _a === void 0 ? void 0 : _a.start) === null || _b === void 0 ? void 0 : _b.call(_a));
}

@@ -376,3 +393,3 @@ }

async stop() {
var _a, _b, _c;
var _a, _b;
this.status = Status.closing;

@@ -383,3 +400,3 @@ this.receiver.emit('before-disconnect');

for (const type in this.options.database) {
tasks.push((_c = (_a = this.database[type]) === null || _a === void 0 ? void 0 : (_b = _a).stop) === null || _c === void 0 ? void 0 : _c.call(_b));
tasks.push((_b = (_a = this.database[type]) === null || _a === void 0 ? void 0 : _a.stop) === null || _b === void 0 ? void 0 : _b.call(_a));
}

@@ -413,6 +430,5 @@ }

parseCommandLine(message, meta) {
var _a;
const name = message.split(/\s/, 1)[0];
const command = this._getCommandByRawName(name);
if ((_a = command) === null || _a === void 0 ? void 0 : _a.context.match(meta)) {
if (command === null || command === void 0 ? void 0 : command.context.match(meta)) {
const result = command.parse(message.slice(name.length).trimStart());

@@ -419,0 +435,0 @@ return { meta, command, ...result };

@@ -171,3 +171,2 @@ "use strict";

async execute(argv, next = koishi_utils_1.noop) {
var _a;
const { meta, options = {}, args = [], unknown = [] } = argv;

@@ -182,3 +181,3 @@ this.app.emitEvent(meta, 'before-command', argv);

const nextArg = this._argsDef[args.length];
if ((_a = nextArg) === null || _a === void 0 ? void 0 : _a.required) {
if (nextArg === null || nextArg === void 0 ? void 0 : nextArg.required) {
return this._sendHint(CommandHint.INSUFFICIENT_ARGUMENTS, meta);

@@ -185,0 +184,0 @@ }

@@ -94,3 +94,4 @@ /// <reference types="node" />

'before-group'(fields: Set<GroupField>, argv: ParsedCommandLine): any;
'attach'(meta: Meta<'message'>): any;
'attach-user'(meta: Meta<'message'>): any;
'attach-group'(meta: Meta<'message'>): any;
'send'(meta: Meta<'send'>): any;

@@ -116,2 +117,3 @@ 'before-send'(meta: Meta<'send'>): any;

'disconnect'(): any;
'attach'(meta: Meta<'message'>): any;
}

@@ -118,0 +120,0 @@ export declare type Events = keyof EventMap;

@@ -206,5 +206,4 @@ "use strict";

getCommand(name, meta) {
var _a;
const command = this._getCommandByRawName(name);
if (((_a = command) === null || _a === void 0 ? void 0 : _a.context.match(meta)) && !command.getConfig('disable', meta)) {
if ((command === null || command === void 0 ? void 0 : command.context.match(meta)) && !command.getConfig('disable', meta)) {
return command;

@@ -211,0 +210,0 @@ }

@@ -63,4 +63,4 @@ "use strict";

subdatabases[name] = subdatabase;
subdatabase._methods = (_a = unknownMethods[name], (_a !== null && _a !== void 0 ? _a : {}));
subdatabase._options = (_b = unknownOptions[name], (_b !== null && _b !== void 0 ? _b : {}));
subdatabase._methods = (_a = unknownMethods[name]) !== null && _a !== void 0 ? _a : {};
subdatabase._options = (_b = unknownOptions[name]) !== null && _b !== void 0 ? _b : {};
}

@@ -108,5 +108,5 @@ exports.registerDatabase = registerDatabase;

createSubdatabase(sub, config) {
var _a, _b, _c;
var _a, _b;
const Subdatabase = subdatabases[sub];
const identifier = (_a = config.identifier, (_a !== null && _a !== void 0 ? _a : (config.identifier = (_c = (_b = Subdatabase).identify) === null || _c === void 0 ? void 0 : _c.call(_b, config))));
const identifier = (_a = config.identifier) !== null && _a !== void 0 ? _a : (config.identifier = (_b = Subdatabase.identify) === null || _b === void 0 ? void 0 : _b.call(Subdatabase, config));
const databases = existingDatabases[sub] || (existingDatabases[sub] = {});

@@ -113,0 +113,0 @@ return identifier in databases

import { User, Group } from './database';
import { ParsedCommandLine } from './command';
export declare type PostType = 'message' | 'notice' | 'request' | 'meta_event' | 'send';

@@ -48,2 +49,3 @@ export declare type MessageType = 'private' | 'group' | 'discuss';

$ctxType?: ContextType;
$argv?: ParsedCommandLine;
$parsed?: ParsedMessage;

@@ -50,0 +52,0 @@ $response?: (payload: ResponsePayload) => void;

@@ -91,2 +91,3 @@ "use strict";

[$ctxType + 'Id']: $ctxId,
time: Math.round(Date.now() / 1000),
};

@@ -93,0 +94,0 @@ }

@@ -65,6 +65,5 @@ "use strict";

const suggestions = items.filter((name) => {
var _a;
return name.length > 2
&& leven_1.default(name, target) <= name.length * coefficient
&& !((_a = disable) === null || _a === void 0 ? void 0 : _a(name));
&& !(disable === null || disable === void 0 ? void 0 : disable(name));
});

@@ -71,0 +70,0 @@ if (!suggestions.length)

{
"name": "koishi-core",
"description": "Core features for Koishi",
"version": "1.9.0",
"version": "1.10.0",
"main": "dist/index.js",

@@ -36,6 +36,6 @@ "typings": "dist/index.d.ts",

"@types/debug": "^4.1.5",
"@types/ws": "^7.2.1",
"@types/ws": "^7.2.2",
"get-port": "^5.1.1",
"koishi-database-memory": "^1.1.2",
"koishi-test-utils": "^3.1.1"
"koishi-database-memory": "^1.1.3",
"koishi-test-utils": "^3.1.2"
},

@@ -46,3 +46,3 @@ "dependencies": {

"escape-string-regexp": "^2.0.0",
"koishi-utils": "^1.0.3",
"koishi-utils": "^1.0.4",
"leven": "^3.1.0",

@@ -49,0 +49,0 @@ "ws": "^7.2.1"

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