bot
This commit is contained in:
parent
825516f0ae
commit
e0d57865a8
4
.gitignore
vendored
4
.gitignore
vendored
@ -107,3 +107,7 @@ dist
|
|||||||
# Stores VSCode versions used for testing VSCode extensions
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
.vscode-test
|
.vscode-test
|
||||||
|
|
||||||
|
credentials.json
|
||||||
|
|
||||||
|
.idea
|
||||||
|
package-lock.json
|
80
bot.js
Normal file
80
bot.js
Normal file
@ -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));
|
12
package.json
Normal file
12
package.json
Normal file
@ -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": {}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user