koishi-plugin-rina-currency 0.0.6 → 0.1.0
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/config.d.ts +1 -0
- package/lib/index.d.ts +4 -1
- package/lib/index.js +63 -11
- package/lib/qq.d.ts +13 -0
- package/package.json +2 -7
package/lib/config.d.ts
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { Context } from 'koishi';
|
|
|
2
2
|
import 'koishi-plugin-cron';
|
|
3
3
|
import { Config as ConfigSchema, Config as PluginConfig } from './config';
|
|
4
4
|
export declare const name = "rina-currency";
|
|
5
|
-
export declare const inject:
|
|
5
|
+
export declare const inject: {
|
|
6
|
+
required: string[];
|
|
7
|
+
optional: string[];
|
|
8
|
+
};
|
|
6
9
|
export type Config = PluginConfig;
|
|
7
10
|
export declare const Config: import("schemastery")<ConfigSchema>;
|
|
8
11
|
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -52,9 +52,9 @@ var RateTypeSchema = import_koishi.Schema.union([
|
|
|
52
52
|
]);
|
|
53
53
|
var BroadcastSchema = import_koishi.Schema.object({
|
|
54
54
|
enabled: import_koishi.Schema.boolean().default(true).description("启用这条播报规则"),
|
|
55
|
-
platform: import_koishi.Schema.string().required().description("平台名称,例如 onebot、
|
|
56
|
-
selfId: import_koishi.Schema.string().required().description("用于发送的机器人账号 ID"),
|
|
57
|
-
channelId: import_koishi.Schema.string().required().description("
|
|
55
|
+
platform: import_koishi.Schema.string().required().description("平台名称,例如 qq、onebot、telegram"),
|
|
56
|
+
selfId: import_koishi.Schema.string().required().description("用于发送的机器人账号 ID(QQ 官方机器人填 AppID)"),
|
|
57
|
+
channelId: import_koishi.Schema.string().required().description("目标群组 ID(QQ 官方支持直接填 group_openid,或在启用 rina-qq-bridge 时填已映射群号)"),
|
|
58
58
|
hour: import_koishi.Schema.number().min(0).max(23).default(9).description("北京时间小时"),
|
|
59
59
|
minute: import_koishi.Schema.number().min(0).max(59).default(0).description("北京时间分钟"),
|
|
60
60
|
includeChart: import_koishi.Schema.boolean().default(true).description("附上趋势图"),
|
|
@@ -65,9 +65,9 @@ var ThresholdSchema = import_koishi.Schema.object({
|
|
|
65
65
|
bank: BankSchema.default("boc"),
|
|
66
66
|
rateType: RateTypeSchema.default("spotSell"),
|
|
67
67
|
changePercent: import_koishi.Schema.number().min(0.01).max(100).required().description("相邻采样点的绝对涨跌幅达到此百分比时提醒,例如 0.5 表示上涨或下跌 0.5%"),
|
|
68
|
-
platform: import_koishi.Schema.string().required().description("
|
|
69
|
-
selfId: import_koishi.Schema.string().required().description("机器人账号 ID"),
|
|
70
|
-
channelId: import_koishi.Schema.string().required().description("
|
|
68
|
+
platform: import_koishi.Schema.string().required().description("平台名称,例如 qq、onebot"),
|
|
69
|
+
selfId: import_koishi.Schema.string().required().description("机器人账号 ID(QQ 官方机器人填 AppID)"),
|
|
70
|
+
channelId: import_koishi.Schema.string().required().description("目标群组 ID(QQ 官方支持 group_openid 或已映射群号)")
|
|
71
71
|
});
|
|
72
72
|
var Config = import_koishi.Schema.object({
|
|
73
73
|
defaultBank: BankSchema.default("boc").description("购汇成本与单银行趋势的默认参考银行"),
|
|
@@ -79,6 +79,7 @@ var Config = import_koishi.Schema.object({
|
|
|
79
79
|
collectOnStart: import_koishi.Schema.boolean().default(true).description("插件启动后立即采集一次"),
|
|
80
80
|
chartWidth: import_koishi.Schema.number().min(600).max(2e3).default(1200).description("趋势图宽度"),
|
|
81
81
|
chartHeight: import_koishi.Schema.number().min(360).max(1200).default(680).description("趋势图高度"),
|
|
82
|
+
qqCombineImageAndText: import_koishi.Schema.boolean().default(true).description("在 QQ 官方群(platform=qq)下合并发送图片与文字摘要,节省消息配额"),
|
|
82
83
|
broadcasts: import_koishi.Schema.array(BroadcastSchema).default([]).description("每日定时播报目标"),
|
|
83
84
|
thresholdAlerts: import_koishi.Schema.array(ThresholdSchema).default([]).description("跌破阈值提醒规则")
|
|
84
85
|
});
|
|
@@ -163,6 +164,7 @@ function formatSnapshot(snapshot, defaultBank, rateType) {
|
|
|
163
164
|
const sign = difference >= 0 ? "+" : "";
|
|
164
165
|
lines.push(`工行较中行:${sign}${formatRate(difference)}(购汇 100,000 JPY 约${difference >= 0 ? "多" : "少"} ${formatMoney(Math.abs(difference) * 1e3)} CNY)`);
|
|
165
166
|
}
|
|
167
|
+
lines.push("数据来源:中国银行、工商银行;实际成交以银行渠道为准。");
|
|
166
168
|
return lines.join("\n");
|
|
167
169
|
}
|
|
168
170
|
__name(formatSnapshot, "formatSnapshot");
|
|
@@ -172,7 +174,8 @@ function formatCost(amount, quote, type) {
|
|
|
172
174
|
`按${BANK_LABELS[quote.bank]}${RATE_TYPE_LABELS[type]}计算:`,
|
|
173
175
|
`${amount.toLocaleString("zh-CN")} JPY ≈ ${formatMoney(costForYen(amount, quote, type))} CNY`,
|
|
174
176
|
`牌价:100 JPY = ${formatRate(quote[type])} CNY`,
|
|
175
|
-
`牌价时间:${formatDateTime(quote.publishedAt)}
|
|
177
|
+
`牌价时间:${formatDateTime(quote.publishedAt)}`,
|
|
178
|
+
"实际成交以银行渠道为准。"
|
|
176
179
|
].join("\n");
|
|
177
180
|
}
|
|
178
181
|
__name(formatCost, "formatCost");
|
|
@@ -357,6 +360,22 @@ function registerCommands(ctx, service, config) {
|
|
|
357
360
|
if (!metrics) return `暂无${BANK_LABELS[bank]}的历史牌价,已尝试采集,请稍后重试。`;
|
|
358
361
|
const summary = formatTrendSummary(bank, type, metrics, days);
|
|
359
362
|
if (!session) return summary;
|
|
363
|
+
if (session.platform === "qq" && config.qqCombineImageAndText) {
|
|
364
|
+
try {
|
|
365
|
+
const image = await renderTrendChart(metrics, type, {
|
|
366
|
+
width: config.chartWidth,
|
|
367
|
+
height: config.chartHeight,
|
|
368
|
+
days
|
|
369
|
+
});
|
|
370
|
+
await session.send([import_koishi2.h.image(image, "image/png"), import_koishi2.h.text(summary)]);
|
|
371
|
+
} catch (error) {
|
|
372
|
+
ctx.logger("rina-currency").warn(`生成趋势图失败:${String(error)}`);
|
|
373
|
+
await session.send(`${summary}
|
|
374
|
+
|
|
375
|
+
趋势图生成失败,已返回文字摘要。`);
|
|
376
|
+
}
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
360
379
|
await session.send(summary);
|
|
361
380
|
try {
|
|
362
381
|
const image = await renderTrendChart(metrics, type, {
|
|
@@ -585,8 +604,42 @@ var IcbcProvider = class {
|
|
|
585
604
|
}
|
|
586
605
|
};
|
|
587
606
|
|
|
588
|
-
// src/
|
|
607
|
+
// src/qq.ts
|
|
589
608
|
var import_koishi3 = require("koishi");
|
|
609
|
+
function getQqBridge(ctx) {
|
|
610
|
+
return ctx.rinaQq;
|
|
611
|
+
}
|
|
612
|
+
__name(getQqBridge, "getQqBridge");
|
|
613
|
+
function isPlainNumericId(value) {
|
|
614
|
+
return /^\d{5,16}$/.test(value.trim());
|
|
615
|
+
}
|
|
616
|
+
__name(isPlainNumericId, "isPlainNumericId");
|
|
617
|
+
async function sendTargetMessage(ctx, logger, bot, channelId, content, image, combineImageAndText) {
|
|
618
|
+
const bridge = getQqBridge(ctx);
|
|
619
|
+
if (bridge) {
|
|
620
|
+
await bridge.sendGroupMessage(bot, channelId, {
|
|
621
|
+
text: content,
|
|
622
|
+
image,
|
|
623
|
+
mimeType: "image/png",
|
|
624
|
+
combineImageAndText
|
|
625
|
+
});
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
if (bot.platform === "qq") {
|
|
629
|
+
if (isPlainNumericId(channelId)) {
|
|
630
|
+
logger.warn(`QQ 群目标 ${channelId} 看起来是纯数字群号,且未启用 rina-qq-bridge 映射服务,可能无法被官方接口识别为 group_openid。`);
|
|
631
|
+
}
|
|
632
|
+
if (image && content && combineImageAndText) {
|
|
633
|
+
await bot.sendMessage(channelId, [import_koishi3.h.image(image, "image/png"), import_koishi3.h.text(content)]);
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
await bot.sendMessage(channelId, content);
|
|
638
|
+
if (image) await bot.sendMessage(channelId, import_koishi3.h.image(image, "image/png"));
|
|
639
|
+
}
|
|
640
|
+
__name(sendTargetMessage, "sendTargetMessage");
|
|
641
|
+
|
|
642
|
+
// src/scheduler.ts
|
|
590
643
|
function chinaClock(now = /* @__PURE__ */ new Date()) {
|
|
591
644
|
const parts = new Intl.DateTimeFormat("en-CA", {
|
|
592
645
|
timeZone: "Asia/Shanghai",
|
|
@@ -670,8 +723,7 @@ var Scheduler = class {
|
|
|
670
723
|
this.logger.warn(`未找到机器人 ${target.platform}:${target.selfId},无法向 ${target.channelId} 发送汇率消息。`);
|
|
671
724
|
return;
|
|
672
725
|
}
|
|
673
|
-
await bot
|
|
674
|
-
if (image) await bot.sendMessage(target.channelId, import_koishi3.h.image(image, "image/png"));
|
|
726
|
+
await sendTargetMessage(this.ctx, this.logger, bot, target.channelId, content, image, this.config.qqCombineImageAndText);
|
|
675
727
|
}
|
|
676
728
|
async collectAndAlert(options = {}) {
|
|
677
729
|
try {
|
|
@@ -827,7 +879,7 @@ var RateService = class {
|
|
|
827
879
|
|
|
828
880
|
// src/index.ts
|
|
829
881
|
var name = "rina-currency";
|
|
830
|
-
var inject = ["database", "cron"];
|
|
882
|
+
var inject = { required: ["database", "cron"], optional: ["rinaQq"] };
|
|
831
883
|
var Config2 = Config;
|
|
832
884
|
function apply(ctx, config) {
|
|
833
885
|
extendModel(ctx);
|
package/lib/qq.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Bot, Context, Logger } from 'koishi';
|
|
2
|
+
export interface OptionalQqBridge {
|
|
3
|
+
resolveGroupId(platform: string, botSelfId: string, configuredGroupId: string): Promise<string>;
|
|
4
|
+
sendGroupMessage(bot: Bot, channelId: string, options: {
|
|
5
|
+
text?: string;
|
|
6
|
+
image?: Buffer;
|
|
7
|
+
mimeType?: string;
|
|
8
|
+
combineImageAndText?: boolean;
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare function getQqBridge(ctx: Context): OptionalQqBridge | undefined;
|
|
12
|
+
export declare function isPlainNumericId(value: string): boolean;
|
|
13
|
+
export declare function sendTargetMessage(ctx: Context, logger: Logger, bot: Bot, channelId: string, content: string, image: Buffer | undefined, combineImageAndText: boolean): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-rina-currency",
|
|
3
3
|
"description": "面向购汇决策的日元汇率插件,基于中行和工行数据",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -9,11 +9,6 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"homepage": "https://github.com/738NGX/rinachanbot",
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/738NGX/rinachanbot.git"
|
|
16
|
-
},
|
|
17
12
|
"scripts": {
|
|
18
13
|
"typecheck": "tsc --noEmit"
|
|
19
14
|
},
|
|
@@ -45,4 +40,4 @@
|
|
|
45
40
|
]
|
|
46
41
|
}
|
|
47
42
|
}
|
|
48
|
-
}
|
|
43
|
+
}
|