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.0-alpha.0 to 2.0.0-alpha.1

dist/utils.d.ts

5

dist/index.d.ts

@@ -1,3 +0,4 @@

import { Context, CommandConfig, Meta } from 'koishi-core';
import { Context, Meta } from 'koishi-core';
import './database';
export * from './utils';
export interface Schedule {

@@ -12,2 +13,2 @@ id: number;

export declare const name = "schedule";
export declare function apply(ctx: Context, config?: CommandConfig): void;
export declare function apply(ctx: Context): void;

56

dist/index.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
const koishi_core_1 = require("koishi-core");
const ms_1 = __importDefault(require("ms"));
const utils_1 = require("./utils");
require("./database");
__export(require("./utils"));
function inspectSchedule({ id, assignee, meta, interval, command, time }) {

@@ -37,18 +38,15 @@ if (!koishi_core_1.appMap[assignee])

}
const databases = new Set();
koishi_core_1.onStart(async () => {
const { database } = koishi_core_1.appList[0];
const schedules = await database.getAllSchedules();
schedules.forEach(schedule => inspectSchedule(schedule));
});
exports.name = 'schedule';
function apply(ctx, config = {}) {
function apply(ctx) {
const { database } = ctx.app;
ctx.app.receiver.on('connect', async () => {
if (!database || databases.has(database) || !database.getAllSchedules)
return;
databases.add(database);
const schedules = await database.getAllSchedules();
schedules.forEach(schedule => inspectSchedule(schedule));
});
ctx.command('schedule [time] -- <command>', '设置定时命令', { authority: 3, ...config })
.option('-i, --interval <interval>', '设置触发的间隔秒数', { default: 0, authority: 4 })
ctx.command('schedule [time] -- <command>', '设置定时命令', { authority: 3 })
.option('-i, --interval <interval>', '设置触发的间隔秒数', { authority: 4, isString: true })
.option('-l, --list', '查看已经设置的日程')
.option('-d, --delete <id>', '删除已经设置的日程', { notUsage: true })
.action(async ({ meta, options, rest }, date) => {
.option('-d, --delete <id>', '删除已经设置的日程')
.action(async ({ meta, options, rest }, ...dateSegments) => {
if (options.delete) {

@@ -63,11 +61,21 @@ await database.removeSchedule(options.delete);

return meta.$send(schedules.map(({ id, time, interval, command }) => {
let output = `${id}. 起始时间:${new Date(time).toLocaleString()},`;
let output = `${id}. 起始时间:${time.toLocaleString()},`;
if (interval)
output += `间隔时间:${ms_1.default(interval)},`;
output += `间隔时间:${utils_1.formatTime(interval)},`;
return output + `指令:${command}`;
}).join('\n'));
}
if (/^\d{1,2}(:\d{1,2}){1,2}$/.exec(date)) {
date = `${new Date().toLocaleDateString()} ${date}`;
if (!rest)
return meta.$send('请输入要执行的指令。');
let parsed;
let date = dateSegments.join('-');
if (parsed = utils_1.parseTime(date)) {
date = Date.now() + parsed;
}
else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) {
date = `${new Date().toLocaleDateString()}-${date}`;
}
else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) {
date = `${new Date().getFullYear()}-${date}`;
}
const time = date ? new Date(date) : new Date();

@@ -77,3 +85,7 @@ if (Number.isNaN(+time)) {

}
const schedule = await database.createSchedule(time, ctx.app.selfId, options.interval * 1000, rest, meta);
const interval = utils_1.parseTime(options.interval);
if (!interval && options.interval) {
return meta.$send('请输入合法的时间间隔。');
}
const schedule = await database.createSchedule(time, ctx.app.selfId, interval, rest, meta);
await meta.$send(`日程已创建,编号为 ${schedule.id}。`);

@@ -80,0 +92,0 @@ return inspectSchedule(schedule);

{
"name": "koishi-plugin-schedule",
"description": "Schedule plugin for Koishi",
"version": "2.0.0-alpha.0",
"version": "2.0.0-alpha.1",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"dist"
],
"author": "Shigma <1700011071@pku.edu.cn>",

@@ -11,3 +14,4 @@ "license": "MIT",

"build": "tsc -b",
"lint": "eslint src --ext .ts"
"lint": "eslint src --ext .ts",
"prepack": "tsc -b"
},

@@ -35,8 +39,8 @@ "repository": {

"@types/ms": "^0.7.31",
"koishi-database-level": "^1.1.5",
"koishi-database-mysql": "^1.1.5",
"koishi-test-utils": "^3.2.0"
"koishi-database-level": "^2.0.0-alpha.0",
"koishi-database-mysql": "^2.0.0-alpha.0",
"koishi-test-utils": "^4.0.0-alpha.0"
},
"dependencies": {
"koishi-core": "^1.11.0",
"koishi-core": "^2.0.0-alpha.0",
"koishi-utils": "^1.0.4",

@@ -43,0 +47,0 @@ "ms": "^2.1.2"

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