@Kur8m8

 avatar
unknown
javascript
3 years ago
766 B
23
Indexable
function styleAdder(text, style, url) {
  const styles = {
    bold: "*",
    italic: "_",
    code: "`",
    pre: "```",
    strikethrough: "~",
    underline: "__",
    spoiler: "||",
  };
  if (style == "text_link") return `[${text}](${url})`;
  if (!styles.hasOwnProperty(style)) return text;
  return `${styles[style]}${text}${styles[style]}`;
}
bot.onText(/\/send (.+)/, async (msg, message) => {
  let creation = "";
  msg?.entities?.forEach((e) => {
    console.log(e);
    creation += styleAdder(
      message.input.substring(e.offset, e.length + e.offset) + " ",
      e.type,
      e?.url
    );
  });
  creation = creation.split("/send ")[1];
  bot.sendMessage(msg.chat.id, creation, {
    parse_mode: "MarkdownV2",
  });
});
Editor is loading...