Skip to content

Instantly share code, notes, and snippets.

@nesffer
Last active November 3, 2016 06:22
Show Gist options
  • Save nesffer/39cbc13e2ceccc62b78a0c6e2310964d to your computer and use it in GitHub Desktop.
Save nesffer/39cbc13e2ceccc62b78a0c6e2310964d to your computer and use it in GitHub Desktop.
bot.javascript.js
const javascript = require('./modules/javascript');
var jsRegex = new RegExp('^/js(' + BOTNAME + ')?$', 'i');
bot.onText(jsRegex, (msg, match) => {
var messageId = msg.message_id;
var chatId = msg.chat.id;
var fromId = msg.from.id;
var opts = {
reply_markup: JSON.stringify({force_reply: true, selective: true}),
reply_to_message_id: messageId
};
if (fromId === ADMINID) {
bot.sendMessage(chatId, 'JavaScript 코드를 입력하세요.', opts)
.then((sended) => {
var chatId = sended.chat.id;
var messageId = sended.message_id;
bot.onReplyToMessage(chatId, messageId, (message) => {
javascript(message.text, (error, data) => {
if (error) {
bot.sendMessage(chatId, error, {reply_to_message_id: message.message_id});
} else {
if (data) {
bot.sendMessage(chatId, data, {reply_to_message_id: message.message_id});
} else {
bot.sendMessage(chatId, 'Error! 출력값이 없습니다!', {reply_to_message_id: message.message_id});
}
}
});
});
});
}
});
var jsArgRegex = new RegExp('^/js(' + BOTNAME + ')? (.+)', 'i');
bot.onText(jsArgRegex, (msg, match) => {
var messageId = msg.message_id;
var chatId = msg.chat.id;
var fromId = msg.from.id;
if (fromId === ADMINID) {
javascript(match[2], (error, data) => {
if (error) {
bot.sendMessage(chatId, error, {reply_to_message_id: messageId});
} else {
bot.sendMessage(chatId, data, {reply_to_message_id: messageId});
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment