const fs = require('fs'); const Markup = require('telegraf/markup'); const Extra = require('telegraf/extra'); const request = require('request'); const rev = require("./reverser.js"); //=== TOOL FUNCTIONS var download = function(uri, filename, callback){ request(uri).on('error', function(err) { throw err; }).pipe(fs.createWriteStream(filename)).on('close', callback); }; //=== MAIN MODULE CONFIG module.exports = function(){ return { name : "Reverser", key : 'revrs', version : 0.1, requirements : { gps: false, }, text : [ { trigger : ["/reverse"], public : true, desc : { 0: "Reverses a video/...", 1: "Inverse une video/...", }, requirements : (bot,event,message)=>{ return new Promise((resolve, reject)=>{ if(message.reply_to_message){ return resolve(200); } return reject(430); }); }, action : (bot,event,message)=>{ var id; var vid = false; if(message.reply_to_message.document){ id = message.reply_to_message.document.file_id; if(message.reply_to_message.document.mime_type.indexOf('image')==0){ return; }else if(message.reply_to_message.document.mime_type.indexOf('video')==0){ console.log(message.reply_to_message.document); vid = true; if(message.reply_to_message.document.mime_type.indexOf('mp4')>0){ vid = "mp4"; }else if(message.reply_to_message.document.mime_type.indexOf('avi')>0){ vid = "avi"; }else if(message.reply_to_message.document.mime_type.indexOf('mkv')>0){ vid = "mkv"; }else{ return; } }else{ return; } }else if(message.reply_to_message.sticker){ id = message.reply_to_message.sticker.file_id; return; }else if(message.reply_to_message.video){ console.log(message.reply_to_message.video); if(message.reply_to_message.video.mime_type.indexOf('mp4')>0){ id = message.reply_to_message.video.file_id; vid = "mp4"; }else if(message.reply_to_message.video.mime_type.indexOf('avi')>0){ id = message.reply_to_message.video.file_id; vid = "avi"; }else if(message.reply_to_message.video.mime_type.indexOf('mkv')>0){ id = message.reply_to_message.video.file_id; vid = "mkv"; }else{ return; } }else { return; } if(!vid) return; return bot.telegram.getFileLink(id).then(link=>{ const file = "/tmp/"+id+"."+vid; download(link,file,function(){ rev.reverse(file).then(res=>{ return event.replyWithVideo({source: res.path}); }).catch(err=>{bot.error(err)}); }); }).catch(err=>{bot.error(err)}); } }, ], reply : [], regex : [], media : [], callback : [], inline : [], new_member : (bot,event)=>{}, weburl : [], cron : [], } }