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

koishi-plugin-schedule

Package Overview
Dependencies
Maintainers
1
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koishi-plugin-schedule - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

21

dist/database.js

@@ -25,4 +25,13 @@ "use strict";

async createSchedule(time, interval, command, session) {
const result = await this.db.collection('schedule').insertOne({ time, assignee: session.selfId, interval, command, session });
return { time, assignee: session.selfId, interval, command, session, id: result.insertedId };
let _id = 1;
const [latest] = await this.db.collection('schedule').find().sort('_id', -1).limit(1).toArray();
if (latest)
_id = latest._id + 1;
const data = { time, interval, command, assignee: session.selfId };
const result = await this.db.collection('schedule').insertOne({
_id,
...data,
session: JSON.stringify(session),
});
return { ...data, session, id: result.insertedId };
},

@@ -34,4 +43,6 @@ removeSchedule(_id) {

const res = await this.db.collection('schedule').findOne({ _id });
if (res)
if (res) {
res.id = res._id;
res.session = JSON.parse(res.session);
}
return res;

@@ -42,5 +53,7 @@ },

return await this.db.collection('schedule')
.find({ assignee: { $in } }).map(doc => ({ ...doc, id: doc._id })).toArray();
.find({ assignee: { $in } })
.map(doc => ({ ...doc, id: doc._id, session: JSON.parse(doc.session) }))
.toArray();
},
});
//# sourceMappingURL=database.js.map

20

dist/index.js

@@ -18,7 +18,11 @@ "use strict";

const logger = new koishi_utils_1.Logger('schedule');
function inspectSchedule({ id, session, interval, command, time }) {
function prepareSchedule({ id, session, interval, command, time }) {
const now = Date.now();
const date = time.valueOf();
const { database } = session.$app;
logger.debug('inspect', command);
logger.debug('prepare %d: %c at %s', id, command, time);
function executeSchedule() {
logger.debug('execute %d: %c', id, command);
return session.$execute(command);
}
if (!interval) {

@@ -30,4 +34,4 @@ if (date < now)

return;
session.$execute(command);
database.removeSchedule(id);
await database.removeSchedule(id);
await executeSchedule();
}, date - now);

@@ -42,5 +46,5 @@ }

return clearInterval(timer);
session.$execute(command);
await executeSchedule();
}, interval);
session.$execute(command);
await executeSchedule();
}, timeout);

@@ -60,3 +64,3 @@ }

schedule.session = new koishi_core_1.Session(ctx.app, schedule.session);
inspectSchedule(schedule);
prepareSchedule(schedule);
});

@@ -110,3 +114,3 @@ });

const schedule = await database.createSchedule(time, interval, options.rest, session);
inspectSchedule(schedule);
prepareSchedule(schedule);
return `日程已创建,编号为 ${schedule.id}。`;

@@ -113,0 +117,0 @@ });

{
"name": "koishi-plugin-schedule",
"description": "Schedule plugin for Koishi",
"version": "2.0.1",
"version": "2.0.2",
"main": "dist/index.js",

@@ -37,12 +37,12 @@ "typings": "dist/index.d.ts",

"devDependencies": {
"koishi-plugin-mongo": "^1.0.1",
"koishi-plugin-mongo": "^1.0.3",
"koishi-plugin-mysql": "^2.0.0",
"koishi-test-utils": "^4.0.0"
"koishi-test-utils": "^5.0.0"
},
"peerDependencies": {
"koishi-core": "^2.0.2"
"koishi-core": "^2.2.0"
},
"dependencies": {
"koishi-utils": "^3.1.2"
"koishi-utils": "^3.1.4"
}
}

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