copilot-core
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -5,6 +5,8 @@ "use strict"; | ||
const run_complete_1 = require("./run-complete"); | ||
const run_timeout_1 = require("./run-timeout"); | ||
const actions = { | ||
cmd: cmd.cmd, | ||
complete: run_complete_1.complete | ||
complete: run_complete_1.complete, | ||
timeout: run_timeout_1.timeout | ||
}; | ||
exports.default = actions; |
@@ -32,4 +32,11 @@ "use strict"; | ||
e.cmd = alias[e.cmd]; | ||
let args = speicalSplit(e.rest.trim()); | ||
e.cmd = e.cmd.replace(/__arg[0-9]+__/g, (m) => { | ||
if (args.length) { | ||
return args.shift(); | ||
} | ||
return m; | ||
}); | ||
if (e.cmd.includes("__arg__")) { | ||
e.cmd = e.cmd.replace(/__arg__/g, e.rest.trim()); | ||
e.cmd = e.cmd.replace(/__arg__/g, args.join(" ")); | ||
e.rest = ""; | ||
@@ -50,1 +57,43 @@ } | ||
exports.prepare = prepare; | ||
function speicalSplit(str, by = /\s/) { | ||
let parts = []; | ||
let currentPart = ""; | ||
let inStr = 1; | ||
let inSingleQuotedStr = 2; | ||
let state = 0; | ||
let init = 0; | ||
for (let i = 0; i < str.length; i++) { | ||
let char = str.charAt(i); | ||
switch (state) { | ||
case inStr: | ||
if (char === '"') { | ||
state = init; | ||
} | ||
currentPart += char; | ||
break; | ||
case inSingleQuotedStr: | ||
if (char === "'") { | ||
state = init; | ||
} | ||
currentPart += char; | ||
break; | ||
case init: | ||
if (char === '"') { | ||
state = inStr; | ||
} | ||
else if (char === "'") { | ||
state = inSingleQuotedStr; | ||
} | ||
else if (by.test(char)) { | ||
parts.push(currentPart); | ||
currentPart = ""; | ||
continue; | ||
} | ||
currentPart += char; | ||
} | ||
} | ||
if (currentPart) { | ||
parts.push(currentPart); | ||
} | ||
return parts; | ||
} |
@@ -7,5 +7,19 @@ import { IOption } from "../types"; | ||
}[]; | ||
export declare function lucky(): { | ||
export declare function lucky(): ({ | ||
title: string; | ||
text: string; | ||
} | { | ||
title: string; | ||
text: string; | ||
value: string; | ||
})[]; | ||
export declare function who(op: IOption): ({ | ||
title: string; | ||
text: string; | ||
} | { | ||
title: string; | ||
text: string; | ||
value: string; | ||
})[] | { | ||
text: string; | ||
}[]; |
@@ -19,5 +19,29 @@ "use strict"; | ||
title: "", | ||
text: `Yongyong ${days[(Math.random() * days.length) | 0]} 是 ${animals[(Math.random() * animals.length) | 0]}` | ||
text: `雍雍${days[(Math.random() * days.length) | 0]}是${animals[(Math.random() * animals.length) | 0]}` | ||
}, { | ||
title: "", | ||
text: "广告位招租", | ||
value: "It's a joke", | ||
}]; | ||
} | ||
exports.lucky = lucky; | ||
function who(op) { | ||
let who = op.who || ["雍雍", "雍雍", "雍雍", "雍雍", "GG"]; | ||
let something = op.something || ["洗碗"]; | ||
if (op.t) { | ||
return [{ | ||
title: "", | ||
text: `今天${who[(Math.random() * who.length) | 0]}${something}` | ||
}, { | ||
title: "", | ||
text: "广告位招租", | ||
value: "It's a joke", | ||
}]; | ||
} | ||
else { | ||
return [{ | ||
text: "Who will go to do ? trigger by -t" | ||
}]; | ||
} | ||
} | ||
exports.who = who; |
@@ -30,1 +30,25 @@ import { IResult, IOption } from "../types"; | ||
}[]; | ||
export declare function echo(op: IOption): { | ||
title: string; | ||
text: string; | ||
value: string; | ||
}[]; | ||
export declare function timeout(op: IOption, list: IResult[]): { | ||
title: string; | ||
text: string; | ||
value: string; | ||
param: { | ||
action: string; | ||
timeout: number; | ||
original: IResult; | ||
}; | ||
}[]; | ||
export declare function notify(op: IOption, list: IResult[]): { | ||
title: string; | ||
text: any; | ||
param: { | ||
action: string; | ||
cmd: string; | ||
args: any[]; | ||
}; | ||
}[]; |
@@ -66,1 +66,47 @@ "use strict"; | ||
exports.calc = calc; | ||
function echo(op) { | ||
let text = op.strings.join(" "); | ||
return [{ | ||
title: text, | ||
text, | ||
value: text | ||
}]; | ||
} | ||
exports.echo = echo; | ||
function timeout(op, list) { | ||
let timeout = Number(op.min) * 60 * 1000 || Number(op.sec) * 1000 || 0; | ||
return list.map(item => ({ | ||
title: "Do after time out", | ||
text: `After ${timeout / 1000}s ${item.title}`, | ||
value: `After ${timeout / 1000}s ${item.title}`, | ||
param: { | ||
action: "timeout", | ||
timeout, | ||
original: item | ||
} | ||
})); | ||
} | ||
exports.timeout = timeout; | ||
function notify(op, list) { | ||
if (list.length) { | ||
return list.map(item => (Object.assign({}, item, { title: "Send notification", param: { | ||
action: "cmd", | ||
cmd: "notify-send", | ||
args: [item.title, item.value] | ||
} }))); | ||
} | ||
else { | ||
let summary = op.summary || op.strings.join(" "); | ||
let body = op.body || ""; | ||
return [{ | ||
title: `Send notification`, | ||
text: summary, | ||
param: { | ||
action: "cmd", | ||
cmd: "notify-send", | ||
args: [summary, body] | ||
} | ||
}]; | ||
} | ||
} | ||
exports.notify = notify; |
@@ -43,1 +43,5 @@ export declare type Processor = (op: any, list: IResult[]) => IResult[]; | ||
}; | ||
export declare type ITimeoutParam = IRunParam & { | ||
timeout: number; | ||
original: IResult; | ||
}; |
{ | ||
"name": "copilot-core", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "copilot", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
54807
51
1620