Last active
November 3, 2016 06:22
-
-
Save nesffer/39cbc13e2ceccc62b78a0c6e2310964d to your computer and use it in GitHub Desktop.
bot.javascript.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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