79 lines
2.5 KiB
JavaScript
79 lines
2.5 KiB
JavaScript
const TelegramBot = require('node-telegram-bot-api');
|
|
|
|
// replace the value below with the Telegram token you receive from @BotFather
|
|
let token = require("./credentials.json").token;
|
|
|
|
// Meme creator library
|
|
let memeMaker = require('meme-maker');
|
|
|
|
//Required options for the meme creator.
|
|
let options = {
|
|
image: 'spiderman.png', // Required
|
|
outfile: 'spiderman-meme.png', // Required
|
|
topText: 'TODAY IM', // Required
|
|
bottomText: 'AN ASS', // Optional
|
|
font: '/path/to/font.ttf', // Optional
|
|
fontSize: 50, // Optional
|
|
fontFill: '#FFF', // Optional
|
|
textPos: 'center', // Optional
|
|
strokeColor: '#000', // Optional
|
|
strokeWeight: 2 // Optional
|
|
};
|
|
|
|
// Postgres
|
|
const Pool = require('pg').Pool;
|
|
|
|
// Postgres config.
|
|
let postgresConfig = require("./credentials.json").postgres;
|
|
|
|
// Postgres initialization
|
|
const pool = new Pool(postgresConfig);
|
|
|
|
// memeMaker(options, function(err) {
|
|
// if(e) throw new Error(err)
|
|
// console.log('Image saved: ' + options.outfile)
|
|
// });
|
|
|
|
// Create a bot that uses 'polling' to fetch new updates
|
|
const bot = new TelegramBot(token,
|
|
{
|
|
polling: true,
|
|
});
|
|
|
|
// Matches "/echo [whatever]"
|
|
bot.onText(/\/cuantofaltaprro/, (msg, match) => {
|
|
// 'msg' is the received Message from Telegram
|
|
// 'match' is the result of executing the regexp above on the text content
|
|
// of the message
|
|
|
|
const chatId = msg.chat.id;
|
|
const date1 = new Date(2019, 9, 26, 21, 30, 0 );
|
|
const dateNow = new Date();
|
|
const msec = date1 - dateNow;
|
|
let mins = Math.floor(msec / 60000);
|
|
let hrs = Math.floor(mins / 60);
|
|
const days = Math.floor(hrs / 24);
|
|
|
|
mins = mins - hrs*60;
|
|
hrs = hrs - days*24;
|
|
//const resp = match[1]; // the captured "whatever"
|
|
|
|
// send back the matched "whatever" to the chat
|
|
if(date1 < dateNow) {
|
|
bot.sendMessage(chatId, "Viejito prro ya estai en japón.");
|
|
} else {
|
|
bot.sendMessage(chatId, "Quedan: " + days + (days === 1 ? " día, " : " días, ") + hrs + (hrs === 1 ? " hora, " : " horas, ") + mins + (mins === 1 ? " minuto" : " minutos"));
|
|
}
|
|
});
|
|
|
|
bot.onText(/\/cuandoLaTesis/, (msg, match) => {
|
|
// 'msg' is the received Message from Telegram
|
|
// 'match' is the result of executing the regexp above on the text content
|
|
// of the message
|
|
|
|
|
|
console.log(msg.from.id);
|
|
console.log(msg.chat.id);
|
|
});
|
|
|
|
bot.on("polling_error", (err) => console.log(err)); |