koishi-plugin-node-async-bot-all 2.24.1 → 2.24.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 +2 -2
- package/lib/index.js +24 -16
- package/package.json +1 -1
package/lib/commands.d.ts
CHANGED
|
@@ -76,7 +76,7 @@ export declare function getQQInfo(ctx: Context, session: Session, qq: string): P
|
|
|
76
76
|
export declare function getMsg(ctx: Context, session: Session): Promise<number>;
|
|
77
77
|
export declare function getNewsMsg(ctx: Context, type: number): Promise<{
|
|
78
78
|
success: boolean;
|
|
79
|
-
data
|
|
80
|
-
msg
|
|
79
|
+
data?: Buffer;
|
|
80
|
+
msg: string;
|
|
81
81
|
}>;
|
|
82
82
|
export {};
|
package/lib/index.js
CHANGED
|
@@ -854,14 +854,23 @@ async function getMsg(ctx, session) {
|
|
|
854
854
|
__name(getMsg, "getMsg");
|
|
855
855
|
async function getNewsMsg(ctx, type) {
|
|
856
856
|
const log = ctx.logger("getNewsMsg");
|
|
857
|
-
const response = await request("
|
|
857
|
+
const response = await request("http://127.0.0.1:8080/tasa/index.old/v.json", {}, ctx.config.timeout, log);
|
|
858
858
|
if (response.success) {
|
|
859
859
|
if ((await ctx.database.get("botData", "newsId"))[0]?.data == response.data.appnews.newsitems[0].gid && type != 1) {
|
|
860
860
|
log.debug("无新闻");
|
|
861
|
-
return { success: false,
|
|
861
|
+
return { success: false, msg: "无可用新闻" };
|
|
862
|
+
}
|
|
863
|
+
const db = await ctx.database.get("botData", response.data.appnews.newsitems[0].gid);
|
|
864
|
+
let html = [];
|
|
865
|
+
if (db[0]) {
|
|
866
|
+
html[0] = db[0].data;
|
|
867
|
+
} else {
|
|
868
|
+
html = await readNewsFile(response.data, log);
|
|
869
|
+
if (html[1]) return { success: false, msg: `渲染图片失败` };
|
|
870
|
+
await ctx.database.upsert("botData", [
|
|
871
|
+
{ id: response.data.appnews.newsitems[0].gid, data: html[0] }
|
|
872
|
+
]);
|
|
862
873
|
}
|
|
863
|
-
const html = await readNewsFile(response.data, log);
|
|
864
|
-
if (html[1]) return { success: false, data: `渲染图片失败` };
|
|
865
874
|
const page = await ctx.puppeteer.page();
|
|
866
875
|
try {
|
|
867
876
|
await page.setViewport({
|
|
@@ -884,21 +893,21 @@ async function getNewsMsg(ctx, type) {
|
|
|
884
893
|
if (type == 0) await ctx.database.upsert("botData", [
|
|
885
894
|
{ id: "newsId", data: response.data.appnews.newsitems[0].gid }
|
|
886
895
|
]);
|
|
887
|
-
return { success: true, data:
|
|
896
|
+
return { success: true, data: image, msg: "NorthWood 发布了一个新闻(原文+机翻):" + response.data.appnews.newsitems[0].title };
|
|
888
897
|
} catch (err) {
|
|
889
898
|
log.error("图片渲染失败:", err);
|
|
890
|
-
return { success: false,
|
|
899
|
+
return { success: false, msg: "图片渲染失败" };
|
|
891
900
|
} finally {
|
|
892
901
|
if (page && !page.isClosed()) await page.close();
|
|
893
902
|
}
|
|
894
903
|
} else {
|
|
895
|
-
return { success: false,
|
|
904
|
+
return { success: false, msg: "请求 Steam API 失败" };
|
|
896
905
|
}
|
|
897
906
|
}
|
|
898
907
|
__name(getNewsMsg, "getNewsMsg");
|
|
899
908
|
|
|
900
909
|
// package.json
|
|
901
|
-
var version = "2.24.
|
|
910
|
+
var version = "2.24.3";
|
|
902
911
|
|
|
903
912
|
// src/index.ts
|
|
904
913
|
var inject = ["database", "installer", "puppeteer", "cron"];
|
|
@@ -967,13 +976,12 @@ function apply(ctx) {
|
|
|
967
976
|
ctx.command("slnews").action(async () => {
|
|
968
977
|
const log = ctx.logger("slnews");
|
|
969
978
|
const outMsg = await getNewsMsg(ctx, 1);
|
|
970
|
-
if (outMsg.
|
|
979
|
+
if (outMsg.data) {
|
|
971
980
|
return `${outMsg.msg}
|
|
972
|
-
${
|
|
981
|
+
${import_koishi3.h.image(outMsg.data, "image/png")}`;
|
|
973
982
|
} else {
|
|
974
983
|
log.warn(outMsg);
|
|
975
|
-
|
|
976
|
-
return outMsg.data;
|
|
984
|
+
return outMsg.msg;
|
|
977
985
|
}
|
|
978
986
|
});
|
|
979
987
|
ctx.cron("0 * * * *", async () => {
|
|
@@ -984,12 +992,12 @@ ${(0, import_koishi3.h)("image", { url: `data:image/jpg;base64,${outMsg.data}` }
|
|
|
984
992
|
});
|
|
985
993
|
ctx.on("node-async/news", async () => {
|
|
986
994
|
const outMsg = await getNewsMsg(ctx, 0);
|
|
987
|
-
if (outMsg.
|
|
995
|
+
if (outMsg.data) {
|
|
988
996
|
await ctx.broadcast(ctx.config.slNews, `${outMsg.msg}
|
|
989
|
-
${
|
|
997
|
+
${import_koishi3.h.image(outMsg.data, "image/png")}`);
|
|
990
998
|
} else {
|
|
991
|
-
if (outMsg.
|
|
992
|
-
await ctx.broadcast(ctx.config.slNews, outMsg.
|
|
999
|
+
if (outMsg.msg == "无可用新闻") return;
|
|
1000
|
+
await ctx.broadcast(ctx.config.slNews, outMsg.msg);
|
|
993
1001
|
}
|
|
994
1002
|
});
|
|
995
1003
|
ctx.command("cxGame").action(async ({ session }) => {
|