Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
why use markdown?
Browse files Browse the repository at this point in the history
  • Loading branch information
pureink committed Aug 8, 2021
1 parent 37a8c7c commit 1a34b99
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
14 changes: 7 additions & 7 deletions notifications/telegram.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { config } from "../config";
const Telegram = require("telegraf/telegram");
import { telegraph } from "../utils/telegraph";
import { md } from "../utils/markdown";
import { html } from "../utils/html";
let sendto = config.TG_SENDID;
export async function reply(feed, item) {
const telegram = new Telegram(config.TG_TOKEN);
await telegram.sendMessage(
sendto,
`*${md(feed.title)}*\n${md(item.title)}\n${
`<b>${html(feed.title)}</b>\n${html(item.title)}\n${
feed.telegraph
? item.content
? `[telegraph](${await telegraph(item)})`
? `<a href="${await telegraph(item)}">telegraph</a>`
: ""
: ""
} ${item.link ? `[查看原文](${item.link})` : ""}`,
{ parse_mode: "MARKDOWN" }
} ${item.link ? `<a href="${item.link}">origin</a>` : ""}`,
{ parse_mode: "HTML" }
);
}
export async function replyWhenError(feed) {
const telegram = new Telegram(config.TG_TOKEN);
await telegram.sendMessage(
sendto,
`*${md(feed.title)}*\n 连续多次失败,将暂停更新,请检查订阅源是否正常。`,
{ parse_mode: "MARKDOWN" }
`<b>${html(feed.title)}</b>\n 连续多次失败,将暂停更新,请检查订阅源是否正常。`,
{ parse_mode: "HTML" }
);
}
6 changes: 6 additions & 0 deletions utils/html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const map = {
"<": "&lt;",
">": "&gt;",
"&": "&amp;",
};
export const html = (string) => string.replace(/[\<\>\&]/g, (m) => map[m]);
18 changes: 0 additions & 18 deletions utils/markdown.js

This file was deleted.

6 changes: 3 additions & 3 deletions utils/tgbot_command/list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { md } from "../markdown";
import { html} from "../html";
export async function botList(ctx) {
let subraw = (await KV.get("sub")) || "[]";
const sub = JSON.parse(subraw);
Expand All @@ -7,8 +7,8 @@ export async function botList(ctx) {
} else {
let msg = "";
for (let i = 0; i < sub.length; i++) {
msg += `[${md(sub[i].title)}](${sub[i].url})\n`;
msg += `[${html(sub[i].title)}](${sub[i].url})\n`;
}
await ctx.reply(msg, { parse_mode: "Markdown" });
await ctx.reply(msg, { parse_mode: "HTML" });
}
}

0 comments on commit 1a34b99

Please sign in to comment.