koishi-plugin-disaster-warning 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands.d.ts +4 -0
- package/lib/commands.js +80 -0
- package/lib/index.js +5 -1
- package/package.json +13 -2
package/lib/commands.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyCommands = applyCommands;
|
|
4
|
+
const koishi_1 = require("koishi");
|
|
5
|
+
const logger = new koishi_1.Logger('disaster-commands');
|
|
6
|
+
function applyCommands(ctx, config, service) {
|
|
7
|
+
ctx.command('disaster', '灾害预警插件');
|
|
8
|
+
ctx.command('disaster.test', '发送测试预警消息')
|
|
9
|
+
.action(async ({ session }) => {
|
|
10
|
+
if (!session)
|
|
11
|
+
return;
|
|
12
|
+
await session.send('正在发送测试消息...');
|
|
13
|
+
const testEvent = {
|
|
14
|
+
id: 'test_event_' + Date.now(),
|
|
15
|
+
data: {
|
|
16
|
+
id: 'test_id',
|
|
17
|
+
event_id: 'test_event_id',
|
|
18
|
+
source: 'Test Source',
|
|
19
|
+
disaster_type: 'earthquake_warning',
|
|
20
|
+
shock_time: new Date().toISOString(),
|
|
21
|
+
latitude: 30.0,
|
|
22
|
+
longitude: 120.0,
|
|
23
|
+
depth: 10,
|
|
24
|
+
magnitude: 5.0,
|
|
25
|
+
intensity: 4.0,
|
|
26
|
+
place_name: '测试地点',
|
|
27
|
+
updates: 1,
|
|
28
|
+
is_final: false,
|
|
29
|
+
is_cancel: false,
|
|
30
|
+
raw_data: {}
|
|
31
|
+
},
|
|
32
|
+
source: 'test',
|
|
33
|
+
disaster_type: 'earthquake_warning',
|
|
34
|
+
receive_time: new Date().toISOString(),
|
|
35
|
+
push_count: 0,
|
|
36
|
+
raw_data: {}
|
|
37
|
+
};
|
|
38
|
+
// We can use the service's pusher to format and send,
|
|
39
|
+
// but pusher broadcasts to configured groups.
|
|
40
|
+
// Here we might want to send to the current session.
|
|
41
|
+
// Let's manually format it using a simplified version or expose pusher's formatter.
|
|
42
|
+
// For simplicity, let's just send a text message here.
|
|
43
|
+
const msg = [
|
|
44
|
+
'【测试消息】',
|
|
45
|
+
'这是一个测试用的地震预警消息。',
|
|
46
|
+
'震源:测试地点',
|
|
47
|
+
`时间:${new Date().toLocaleString()}`,
|
|
48
|
+
'震级:M5.0',
|
|
49
|
+
'最大烈度:4.0'
|
|
50
|
+
].join('\n');
|
|
51
|
+
return msg;
|
|
52
|
+
});
|
|
53
|
+
ctx.command('disaster.history', '查看最近地震记录 (CENC)')
|
|
54
|
+
.action(async ({ session }) => {
|
|
55
|
+
try {
|
|
56
|
+
const data = await ctx.http.get('https://api.wolfx.jp/cenc_eqlist.json');
|
|
57
|
+
if (!data)
|
|
58
|
+
return '获取数据失败';
|
|
59
|
+
const list = [];
|
|
60
|
+
let count = 0;
|
|
61
|
+
for (const key in data) {
|
|
62
|
+
if (key.startsWith('No') && count < 5) {
|
|
63
|
+
const eq = data[key];
|
|
64
|
+
list.push(eq);
|
|
65
|
+
count++;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (list.length === 0)
|
|
69
|
+
return '未找到最近地震记录';
|
|
70
|
+
const messages = list.map(eq => {
|
|
71
|
+
return `时间: ${eq.time}\n地点: ${eq.location}\n震级: M${eq.magnitude}\n深度: ${eq.depth}km`;
|
|
72
|
+
});
|
|
73
|
+
return messages.join('\n\n');
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
logger.error('Failed to fetch history:', e);
|
|
77
|
+
return '获取历史记录失败,请检查网络或日志。';
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.Config = exports.inject = exports.name = void 0;
|
|
|
4
4
|
exports.apply = apply;
|
|
5
5
|
const koishi_1 = require("koishi");
|
|
6
6
|
const service_1 = require("./service");
|
|
7
|
+
const commands_1 = require("./commands");
|
|
7
8
|
exports.name = 'disaster-warning';
|
|
8
9
|
exports.inject = ['database?']; // Optional database dependency if needed later
|
|
9
10
|
exports.Config = koishi_1.Schema.object({
|
|
@@ -57,5 +58,8 @@ exports.Config = koishi_1.Schema.object({
|
|
|
57
58
|
}).description('地震信息过滤器配置'),
|
|
58
59
|
});
|
|
59
60
|
function apply(ctx, config) {
|
|
60
|
-
|
|
61
|
+
const service = new service_1.DisasterWarningService(ctx, config);
|
|
62
|
+
ctx.on('ready', () => service.start());
|
|
63
|
+
ctx.on('dispose', () => service.stop());
|
|
64
|
+
(0, commands_1.applyCommands)(ctx, config, service);
|
|
61
65
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-disaster-warning",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "0.0.
|
|
3
|
+
"description": "Koishi 灾害预警插件,支持多数据源(地震、海啸、气象预警)",
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -31,5 +31,16 @@
|
|
|
31
31
|
"@types/ws": "^8.5.10",
|
|
32
32
|
"koishi": "^4.18.0",
|
|
33
33
|
"typescript": "^5.0.0"
|
|
34
|
+
},
|
|
35
|
+
"koishi": {
|
|
36
|
+
"description": {
|
|
37
|
+
"en": "Disaster warning plugin for Koishi, supporting Earthquake, Tsunami, and Weather alerts from multiple sources.",
|
|
38
|
+
"zh": "Koishi 灾害预警插件,支持多数据源(地震、海啸、气象预警)"
|
|
39
|
+
},
|
|
40
|
+
"service": {
|
|
41
|
+
"optional": [
|
|
42
|
+
"database"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
34
45
|
}
|
|
35
46
|
}
|