@Kur8m8

mail@pastecode.io avatar
unknown
javascript
2 years ago
766 B
19
Indexable
Never
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",
  });
});