kykint

Implement '/t(ranslate)' command

Usage: /t [Whatever]
       or /translate [Whatever]

- Translate the 'whatever' and show the result in any kind of chatroom.
  Also, if the given '/t' message is a reply to another message,
  translate the reply target message as well.
Showing 1 changed file with 25 additions and 0 deletions
......@@ -112,3 +112,28 @@ bot.onText(/^(?!\/)((.|\n)+)/, (msg, match) => {
translate(received_msg, chatId);
});
// /t(ranslate) [Whatever]
// Translate the 'whatever' and show the result in any kind of chatroom.
// Also, if the given '/t' message is a reply to another message,
// translate the reply target message as well.
bot.onText(/^\/(t|translate)($| ((.|\n)+))/, (msg, match) => {
const chatId = msg.chat.id;
const chatType = msg.chat.type;
const received_msg = match[3];
// Whether the given '/t' message is a reply to another message
const isReply = msg.reply_to_message != undefined;
// Whether a message has been given after '/t' command
const msgExists = received_msg != undefined;
// Translate the reply's target message
if (isReply) {
const replyMsg = msg.reply_to_message.text;
translate(replyMsg, chatId);
}
// Translate the message after '/t' if exists
if (msgExists) {
translate(received_msg, chatId);
}
});
......