diff --git a/.gitignore b/.gitignore index d333b23..ee73f1b 100644 --- a/.gitignore +++ b/.gitignore @@ -107,3 +107,7 @@ dist # Stores VSCode versions used for testing VSCode extensions .vscode-test +credentials.json + +.idea +package-lock.json \ No newline at end of file diff --git a/bot.js b/bot.js new file mode 100644 index 0000000..07c3127 --- /dev/null +++ b/bot.js @@ -0,0 +1,80 @@ +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; +console.log(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); + console.log(msg.user.id); + console.log(msg.chat.id); +}); + +//bot.on("polling_error", (err) => console.log(err)); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..163df19 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "version": "5.4.0", + "private": true, + "scripts": {}, + "dependencies": { + "meme-maker": "^2.1.2", + "node-telegram-bot-api": "^0.30.0", + "pg": "^7.18.2", + "socks5-https-client": "latest" + }, + "devDependencies": {} +}