112 lines
3.8 KiB
JavaScript
112 lines
3.8 KiB
JavaScript
const fs = require('fs');
|
|
|
|
const Markup = require('telegraf/markup');
|
|
const Extra = require('telegraf/extra');
|
|
|
|
const request = require('request');
|
|
const rev = require("./reverser.js");
|
|
|
|
const supported_mime = ['video/mp4','video/avi','video/mkv'];
|
|
|
|
//=== 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){
|
|
if(message.reply_to_message.document.mime_type == 'video/mp4'){
|
|
vid = "mp4";
|
|
}else if(message.reply_to_message.document.mime_type == 'video/avi'){
|
|
vid = "avi";
|
|
}else if(message.reply_to_message.document.mime_type == 'video/mkv'){
|
|
vid = "mkv";
|
|
}else{
|
|
console.log(message.reply_to_message.document);
|
|
return;
|
|
}
|
|
}else{
|
|
return;
|
|
}
|
|
}else if(message.reply_to_message.sticker){
|
|
id = message.reply_to_message.sticker.file_id;
|
|
console.log(message.reply_to_message.video);
|
|
return;
|
|
}else if(message.reply_to_message.video){
|
|
id = message.reply_to_message.video.file_id;
|
|
if(message.reply_to_message.video.mime_type == 'video/mp4'){
|
|
vid = "mp4";
|
|
}else if(message.reply_to_message.video.mime_type == 'video/avi'){
|
|
vid = "avi";
|
|
}else if(message.reply_to_message.video.mime_type == 'video/mkv'){
|
|
vid = "mkv";
|
|
}else{
|
|
console.log(message.reply_to_message.video);
|
|
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 : [],
|
|
register_bot: (bot)=>{
|
|
this.bot = bot;
|
|
}
|
|
}
|
|
|
|
} |