-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
125 lines (119 loc) · 4.74 KB
/
Copy pathserver.js
File metadata and controls
125 lines (119 loc) · 4.74 KB
1
var interval;const bot = require('./src/connect_telegram');const GetVKMedia = require('./src/mediaVK');const instagram = require('./src/mediaInstagram');const instagramConntect = require('./src/connect_instagram');const postgres = require('./src/connect_db').db;const old = require('./src/old');const hashtag = require('./src/hashtag');const location = require('./src/location');process.argv.forEach(function (val, index) { if(val==='start'){ interval = setInterval(function() { get(5, 1452699); }, 120000); } if(val==='get5'){ setTimeout(()=> get(5, 1452699),1000); } if(val==='il'){ instagramConntect.Login(); }});bot.onText(/\/start/, function (msg) { postgres.oneOrNone("SELECT isRun FROM Chat WHERE chatid=$1::text;", msg.chat.id) .then(function (results) { if(results===null) { postgres.oneOrNone("INSERT INTO Chat(chatid, chatname, isRun) VALUES($1::text, $2::text, true) RETURNING chatname;", [msg.chat.id.toString(), msg.chat.username.toString()]) .then(function (results) { console.log('Добавлен и запущен чат ' + results['chatname']); bot.sendMessage(msg.chat.id, 'Поехали!'); interval = setInterval(function() { get(5, msg.chat.id); }, 120000); }) .catch(function (error) { console.log(error); }); } else { if(results.isrun===false) { postgres.oneOrNone("UPDATE Chat SET isRun = true WHERE chatid=$1::text RETURNING chatname;", msg.chat.id) .then(function (results) { console.log('Запущен чат ' + results.chatname); bot.sendMessage(msg.chat.id, 'Поехали снова!'); interval = setInterval(function() { get(5, msg.chat.id); }, 120000); }) .catch(function (error) { console.log(error); }); } else { bot.sendMessage(msg.chat.id, 'Уже стартовали!'); } } }) .catch(function (error) { console.log("ERROR:", error); // print the error; });});bot.onText(/\/stop/, function (msg) { postgres.oneOrNone("UPDATE Chat SET isRun = false WHERE chatid=$1::text RETURNING chatname;", msg.chat.id) .then(function (results) { if(results!==null){ console.log('Остановлен чат ' + results.chatname); bot.sendMessage(msg.chat.id, 'Остановились'); clearInterval(interval); } else { bot.sendMessage(msg.chat.id, 'Уже стоим!'); } }) .catch(function (error) { console.log(error); });});bot.onText(/\/deleteme/, function (msg) { postgres.oneOrNone("delete FROM Chat WHERE chatid=$1::text RETURNING chatname;", msg.chat.id) .then(function (results) { if(results!==null){ console.log('Удален чат ' + results.chatname); bot.sendMessage(msg.chat.id, 'Удалено'); clearInterval(interval); } else { bot.sendMessage(msg.chat.id, 'Уже удалено'); } }) .catch(function (error) { console.log(error); });});bot.onText(/\/get5/, function (msg) { get(5 , msg.chat.id);});function get(countmedia , chatid) { //instagram.UpdateInstagramFollowers(); postgres.many("SELECT hashtagname FROM Hashtag WHERE chatId=$1::text;", chatid) .then(function (results) { if(results!==null) { console.log(new Date() + ' In ChatID ' + chatid); instagram.GetHashtagMedia(results, countmedia, chatid); GetVKMedia(results, countmedia, chatid); } else { bot.sendMessage(chatid,'Нет сохраненных хэштегов'); } }) .catch(function (error) { console.log("ERROR:", error); // print the error; }); postgres.many("SELECT name FROM location WHERE chatId=$1::text;", chatid) .then(function (results) { if(results!==null) { instagram.GetLocationMedia(results, countmedia, chatid); } else { bot.sendMessage(chatid,'Нет сохраненных мест'); } }) .catch(function (error) { console.log("ERROR:", error); // print the error; });}