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 0.1.1 to 1.0.0

9

dist/database.d.ts
import { MessageMeta } from 'koishi-core';
import { Schedule } from '.';
declare module 'koishi-core/dist/database' {

@@ -16,10 +17,2 @@ interface TableMethods {

}
export interface Schedule {
id: number;
assignee: number;
time: number;
interval: number;
command: string;
meta: MessageMeta;
}
export {};

3

dist/database.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const koishi_core_1 = require("koishi-core");
const koishi_utils_1 = require("koishi-utils");
koishi_core_1.injectMethods('mysql', 'schedule', {

@@ -31,3 +32,3 @@ createSchedule(time, assignee, interval, command, meta) {

getSchedule(id) {
return this.tables.schedule.get(id);
return this.tables.schedule.get(id).catch(koishi_utils_1.noop);
},

@@ -34,0 +35,0 @@ async getAllSchedules(assignees) {

@@ -1,2 +0,12 @@

import { Context } from 'koishi-core';
export declare function apply(ctx: Context): void;
import { Context, CommandConfig, MessageMeta } from 'koishi-core';
import './database';
export interface Schedule {
id: number;
assignee: number;
time: number;
interval: number;
command: string;
meta: MessageMeta;
}
export declare const name = "schedule";
export declare function apply(ctx: Context, config?: CommandConfig): void;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const koishi_core_1 = require("koishi-core");
function inspectSchedule({ id, assignee, meta, interval, command, time }, now = Date.now()) {
const ms_1 = __importDefault(require("ms"));
require("./database");
function inspectSchedule({ id, assignee, meta, interval, command, time }) {
if (!koishi_core_1.appMap[assignee])
return;
const now = Date.now();
const app = koishi_core_1.appMap[assignee];

@@ -36,24 +42,44 @@ if (!interval) {

}
function apply(ctx) {
koishi_core_1.onStart(async ({ database }) => {
const now = Date.now();
const databases = new Set();
exports.name = 'schedule';
function apply(ctx, config = {}) {
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, now));
schedules.forEach(schedule => inspectSchedule(schedule));
});
ctx.command('advanced')
.subcommand('schedule <time> -- <command>', '设置定时命令', { authority: 3, maxUsage: 5 })
ctx.command('schedule [time] -- <command>', '设置定时命令', { authority: 3, ...config })
.option('-i, --interval <interval>', '设置触发的间隔秒数', { default: 0, authority: 4 })
// .option('-l, --list', '查看已经设置的日程')
.option('-l, --list', '查看已经设置的日程')
.option('-d, --delete <id>', '删除已经设置的日程', { notUsage: true })
.action(async ({ meta, options, rest }, date) => {
if (options.delete) {
await ctx.app.database.removeSchedule(options.delete);
await database.removeSchedule(options.delete);
return meta.$send('日程已删除。');
}
if (options.list) {
const schedules = await database.getAllSchedules([ctx.app.selfId]);
if (!schedules.length)
return meta.$send('当前没有等待执行的日程。');
return meta.$send(schedules.map(({ id, time, interval, command }) => {
let output = `${id}. 起始时间:${new Date(time).toLocaleString()},`;
if (interval)
output += `间隔时间:${ms_1.default(interval)},`;
return output + `指令:${command}`;
}).join('\n'));
}
if (/^\d{1,2}(:\d{1,2}){1,2}$/.exec(date)) {
date = `${new Date().toLocaleDateString()} ${date}`;
}
const time = date ? new Date(date).valueOf() : Date.now();
const schedule = await ctx.app.database.createSchedule(time, ctx.app.options.selfId, options.interval * 1000, rest, meta);
inspectSchedule(schedule);
return meta.$send(`日程已创建,编号为 ${schedule.id}。`);
if (Number.isNaN(time))
return meta.$send('请输入合法的日期。');
const schedule = await database.createSchedule(time, ctx.app.selfId, options.interval * 1000, rest, meta);
await meta.$send(`日程已创建,编号为 ${schedule.id}。`);
return inspectSchedule(schedule);
});
}
exports.apply = apply;
{
"name": "koishi-plugin-schedule",
"description": "Schedule plugin for Koishi",
"version": "0.1.1",
"version": "1.0.0",
"main": "dist/index.js",

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

"devDependencies": {
"@types/ms": "^0.7.31",
"koishi-database-level": "^1.0.4",
"koishi-database-mysql": "^1.0.3"
"koishi-database-mysql": "^1.0.4",
"koishi-test-utils": "^1.1.0"
},
"dependencies": {
"koishi-core": "^1.2.0"
"koishi-core": "^1.3.0",
"koishi-utils": "^1.0.2",
"ms": "^2.1.2"
}
}

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

# [koishi-plugin-schedule](https://koishijs.github.io/plugins/schedule.html)
# [koishi-plugin-schedule](https://koishi.js.org/plugins/schedule.html)
[![npm](https://img.shields.io/npm/v/koishi-plugin-schedule?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-schedule)
import { MessageMeta, getSelfIds, injectMethods } from 'koishi-core'
import { noop } from 'koishi-utils'
import {} from 'koishi-database-mysql'
import {} from 'koishi-database-level'
import { Schedule } from '.'

@@ -22,11 +24,2 @@ declare module 'koishi-core/dist/database' {

export interface Schedule {
id: number
assignee: number
time: number
interval: number
command: string
meta: MessageMeta
}
injectMethods('mysql', 'schedule', {

@@ -64,3 +57,3 @@ createSchedule (time, assignee, interval, command, meta) {

getSchedule (id) {
return this.tables.schedule.get(id)
return this.tables.schedule.get(id).catch(noop)
},

@@ -67,0 +60,0 @@

@@ -1,6 +0,17 @@

import { Context, onStart, appMap } from 'koishi-core'
import { Schedule } from './database'
import { Context, appMap, Database, CommandConfig, MessageMeta } from 'koishi-core'
import ms from 'ms'
import './database'
function inspectSchedule ({ id, assignee, meta, interval, command, time }: Schedule, now = Date.now()) {
export interface Schedule {
id: number
assignee: number
time: number
interval: number
command: string
meta: MessageMeta
}
function inspectSchedule ({ id, assignee, meta, interval, command, time }: Schedule) {
if (!appMap[assignee]) return
const now = Date.now()
const app = appMap[assignee]

@@ -33,25 +44,45 @@

export function apply (ctx: Context) {
onStart(async ({ database }) => {
const now = Date.now()
const databases = new Set<Database>()
export const name = 'schedule'
export function apply (ctx: Context, config: CommandConfig = {}) {
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, now))
schedules.forEach(schedule => inspectSchedule(schedule))
})
ctx.command('advanced')
.subcommand('schedule <time> -- <command>', '设置定时命令', { authority: 3, maxUsage: 5 })
ctx.command('schedule [time] -- <command>', '设置定时命令', { authority: 3, ...config })
.option('-i, --interval <interval>', '设置触发的间隔秒数', { default: 0, authority: 4 })
// .option('-l, --list', '查看已经设置的日程')
.option('-l, --list', '查看已经设置的日程')
.option('-d, --delete <id>', '删除已经设置的日程', { notUsage: true })
.action(async ({ meta, options, rest }, date) => {
if (options.delete) {
await ctx.app.database.removeSchedule(options.delete)
await database.removeSchedule(options.delete)
return meta.$send('日程已删除。')
}
if (options.list) {
const schedules = await database.getAllSchedules([ctx.app.selfId])
if (!schedules.length) return meta.$send('当前没有等待执行的日程。')
return meta.$send(schedules.map(({ id, time, interval, command }) => {
let output = `${id}. 起始时间:${new Date(time).toLocaleString()},`
if (interval) output += `间隔时间:${ms(interval)},`
return output + `指令:${command}`
}).join('\n'))
}
if (/^\d{1,2}(:\d{1,2}){1,2}$/.exec(date)) {
date = `${new Date().toLocaleDateString()} ${date}`
}
const time = date ? new Date(date).valueOf() : Date.now()
const schedule = await ctx.app.database.createSchedule(time, ctx.app.options.selfId, options.interval * 1000, rest, meta)
inspectSchedule(schedule)
return meta.$send(`日程已创建,编号为 ${schedule.id}。`)
if (Number.isNaN(time)) return meta.$send('请输入合法的日期。')
const schedule = await database.createSchedule(time, ctx.app.selfId, options.interval * 1000, rest, meta)
await meta.$send(`日程已创建,编号为 ${schedule.id}。`)
return inspectSchedule(schedule)
})
}

@@ -0,0 +0,0 @@ {

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