Commit 6fa90e4b authored by nanahira's avatar nanahira

use koishi-target-def

parent 8483d418
......@@ -9,7 +9,8 @@
"version": "1.0.6",
"license": "MIT",
"dependencies": {
"koishi-thirdeye": "^9.2.12",
"koishi-target-def": "^1.0.0",
"koishi-thirdeye": "^9.2.14",
"lodash": "^4.17.21"
},
"devDependencies": {
......@@ -5222,28 +5223,40 @@
}
},
"node_modules/koishi-decorators": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.3.1.tgz",
"integrity": "sha512-UZisxMHvy9SyxyqqHntqCYVVfZ764VtO4bJ6RXKSjJAziBV0c+zLNzQC5nYWbKBsDQ4Fae44M2NJaqnmScAmNA==",
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.3.2.tgz",
"integrity": "sha512-akGFELeybKnjyPQbfHMGhLTRb3CigQPFTcArFt++SGQCSZ9sFpkpUS04V3/HlJoJLSKKq7pXd10q0cOPnfFYZQ==",
"dependencies": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"typed-reflector": "^1.0.9"
"typed-reflector": "^1.0.10"
},
"peerDependencies": {
"koishi": "^4.4.2"
}
},
"node_modules/koishi-target-def": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/koishi-target-def/-/koishi-target-def-1.0.0.tgz",
"integrity": "sha512-5fMhCcvcV4E5gM3KgBSPXz0iXKw7aHcxVO8I0nNjkcEvaV97Jy8pZlw5MV2U6RDkRRfjrDvq5ogBNh0Jd3BYjg==",
"dependencies": {
"lodash": "^4.17.21"
},
"peerDependencies": {
"koishi": "^4.4.2",
"schemastery-gen": "^3.1.3"
}
},
"node_modules/koishi-thirdeye": {
"version": "9.2.12",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.2.12.tgz",
"integrity": "sha512-cYPmXcGBzMGWboyelbg2cX8EeBhQvgh8ZJhMiMypYXeLHz5z46g1u3VDoS6dz35f3DYgzMtyMsUNQbz4SRAu6A==",
"version": "9.2.14",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.2.14.tgz",
"integrity": "sha512-K4JK6nUnX8JqDY3OAkN43NgyWfpjHp1uVjM3LQuEr+IcUVbVPGfZ7bmHET/Ao43dc7zcfFzGTj5UrHkPwIv6wQ==",
"dependencies": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
"koishi-decorators": "^1.3.1",
"koishi-decorators": "^1.3.2",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.1.2",
......@@ -6357,13 +6370,13 @@
"peer": true
},
"node_modules/schemastery-gen": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.2.tgz",
"integrity": "sha512-Vzv4nJ/HnZuEcVXMIY5IULtcNG253jrp+htPAujCq3wVC2p4hxv1e/GRht5O+tYRDfowgAsM89FLXHYXin/tEg==",
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.3.tgz",
"integrity": "sha512-Ze5SzDbXvlvGkUM2KurmHUd7cSm+asiONY4TQRD+SmxRsUA5/0DbeL8Ho27kQ3XcWqATvFhfTlDksOfj9wiZWQ==",
"dependencies": {
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"typed-reflector": "^1.0.8"
"typed-reflector": "^1.0.10"
},
"peerDependencies": {
"schemastery": "^3.1.0"
......@@ -11682,25 +11695,33 @@
}
},
"koishi-decorators": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.3.1.tgz",
"integrity": "sha512-UZisxMHvy9SyxyqqHntqCYVVfZ764VtO4bJ6RXKSjJAziBV0c+zLNzQC5nYWbKBsDQ4Fae44M2NJaqnmScAmNA==",
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-1.3.2.tgz",
"integrity": "sha512-akGFELeybKnjyPQbfHMGhLTRb3CigQPFTcArFt++SGQCSZ9sFpkpUS04V3/HlJoJLSKKq7pXd10q0cOPnfFYZQ==",
"requires": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"typed-reflector": "^1.0.9"
"typed-reflector": "^1.0.10"
}
},
"koishi-target-def": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/koishi-target-def/-/koishi-target-def-1.0.0.tgz",
"integrity": "sha512-5fMhCcvcV4E5gM3KgBSPXz0iXKw7aHcxVO8I0nNjkcEvaV97Jy8pZlw5MV2U6RDkRRfjrDvq5ogBNh0Jd3BYjg==",
"requires": {
"lodash": "^4.17.21"
}
},
"koishi-thirdeye": {
"version": "9.2.12",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.2.12.tgz",
"integrity": "sha512-cYPmXcGBzMGWboyelbg2cX8EeBhQvgh8ZJhMiMypYXeLHz5z46g1u3VDoS6dz35f3DYgzMtyMsUNQbz4SRAu6A==",
"version": "9.2.14",
"resolved": "https://registry.npmjs.org/koishi-thirdeye/-/koishi-thirdeye-9.2.14.tgz",
"integrity": "sha512-K4JK6nUnX8JqDY3OAkN43NgyWfpjHp1uVjM3LQuEr+IcUVbVPGfZ7bmHET/Ao43dc7zcfFzGTj5UrHkPwIv6wQ==",
"requires": {
"@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11",
"koishi-decorators": "^1.3.1",
"koishi-decorators": "^1.3.2",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.1.2",
......@@ -12509,13 +12530,13 @@
"peer": true
},
"schemastery-gen": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.2.tgz",
"integrity": "sha512-Vzv4nJ/HnZuEcVXMIY5IULtcNG253jrp+htPAujCq3wVC2p4hxv1e/GRht5O+tYRDfowgAsM89FLXHYXin/tEg==",
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/schemastery-gen/-/schemastery-gen-3.1.3.tgz",
"integrity": "sha512-Ze5SzDbXvlvGkUM2KurmHUd7cSm+asiONY4TQRD+SmxRsUA5/0DbeL8Ho27kQ3XcWqATvFhfTlDksOfj9wiZWQ==",
"requires": {
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"typed-reflector": "^1.0.8"
"typed-reflector": "^1.0.10"
}
},
"semver": {
......
......@@ -44,7 +44,8 @@
"testEnvironment": "node"
},
"dependencies": {
"koishi-thirdeye": "^9.2.12",
"koishi-target-def": "^1.0.0",
"koishi-thirdeye": "^9.2.14",
"lodash": "^4.17.21"
},
"peerDependencies": {
......
......@@ -3,65 +3,7 @@ import { RegisterSchema, SchemaProperty } from 'koishi-thirdeye';
import { Adapter, segment } from 'koishi';
import _ from 'lodash';
import { AlertDto } from './def';
@RegisterSchema()
export class ChannelTarget {
@SchemaProperty({ description: '频道 ID', required: true })
channelId: string;
@SchemaProperty({ description: '群组 ID' })
guildId: string;
toDesc(): string | [string, string] {
return this.guildId ? [this.channelId, this.guildId] : this.channelId;
}
}
@RegisterSchema()
export class SendTarget {
@SchemaProperty({
required: true,
description: 'bot 标识符。例如 onebot:123456789。',
})
bot: string;
@SchemaProperty({
type: String,
description: '私聊消息发送目标。',
default: [],
})
users: string[];
@SchemaProperty({
type: ChannelTarget,
description: '群聊消息发送目标。',
default: [],
})
channels: Partial<ChannelTarget>[];
async send(bots: Adapter.BotList, content: string) {
const bot = bots.get(this.bot);
if (!bot) {
throw new Error(`bot ${this.bot} not found`);
}
return _.flatten(
await Promise.all([
...this.users.map((userId) =>
bot.sendPrivateMessage
? bot.sendPrivateMessage(userId, content)
: bot.sendMessage(`@${userId}`, content),
),
...(this.channels?.length
? [
bot.broadcast(
this.channels.map((c) => c.toDesc()),
content,
),
]
: []),
]),
);
}
}
import { SendTarget } from 'koishi-target-def';
@RegisterSchema()
export class Instance {
......@@ -116,7 +58,7 @@ export class Instance {
description: '消息发送目标。',
default: [],
})
targets: Partial<SendTarget>[];
targets: SendTarget[];
async send(bots: Adapter.BotList, content: string) {
return _.flatten(
......@@ -138,7 +80,7 @@ export class AlertmanagerPluginConfig {
path: string;
@SchemaProperty({ type: Instance })
instances: Partial<Instance>[];
instances: Instance[];
getInstance(header: string) {
const token = header?.startsWith('Bearer ') ? header.slice(7) : header;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment