Merge branch 'f0ckdev' into 'master'
fixed some bugs in parser See merge request !17
This commit is contained in:
		
							
								
								
									
										2
									
								
								bot.js
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								bot.js
									
									
									
									
									
								
							@@ -26,7 +26,7 @@ var child = new (forever.Monitor)(__dirname+'/src/main.js', {
 | 
				
			|||||||
  silent: false,
 | 
					  silent: false,
 | 
				
			||||||
  cwd: __dirname,
 | 
					  cwd: __dirname,
 | 
				
			||||||
  args: [],
 | 
					  args: [],
 | 
				
			||||||
  spinSleepTime: 2000,
 | 
					  spinSleepTime: 5000,
 | 
				
			||||||
  watch: true,
 | 
					  watch: true,
 | 
				
			||||||
  watchIgnoreDotFiles: true,
 | 
					  watchIgnoreDotFiles: true,
 | 
				
			||||||
  watchIgnorePatterns: [
 | 
					  watchIgnorePatterns: [
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,9 +48,14 @@ module.exports = (lib) => {
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
                  });
 | 
					                  });
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else
 | 
					                else {
 | 
				
			||||||
                  if(cb.msg != '')
 | 
					                  fs.stat('./b/' + cb.file, (err, stat) => {
 | 
				
			||||||
                    e.reply(cb.msg);
 | 
					                    if(cb.msg !== '')
 | 
				
			||||||
 | 
					                      e.reply(cb.msg);
 | 
				
			||||||
 | 
					                    if(!err && stat.isFile())
 | 
				
			||||||
 | 
					                      fs.unlinkSync('./b/' + cb.file);
 | 
				
			||||||
 | 
					                  });
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
              });
 | 
					              });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
@@ -64,8 +69,8 @@ module.exports = (lib) => {
 | 
				
			|||||||
    var yt = /https?:\/\/(www\.)?youtu(\.be\/|be\.com\/)((.+\/)?(watch(\?v=|.+&v=))?(v=)?)([\w_-]{11})(&.+)?/gi;
 | 
					    var yt = /https?:\/\/(www\.)?youtu(\.be\/|be\.com\/)((.+\/)?(watch(\?v=|.+&v=))?(v=)?)([\w_-]{11})(&.+)?/gi;
 | 
				
			||||||
    var sc = /https?:\/\/(www\.)?(soundcloud\.com|snd\.sc)(\/\S*)(\/\S*)/gi;
 | 
					    var sc = /https?:\/\/(www\.)?(soundcloud\.com|snd\.sc)(\/\S*)(\/\S*)/gi;
 | 
				
			||||||
    lib.checkRepost(url, (cbcr) => {
 | 
					    lib.checkRepost(url, (cbcr) => {
 | 
				
			||||||
 | 
					      var tmpdest = uuid.v1().split('-')[0];
 | 
				
			||||||
      if(cbcr === true) {
 | 
					      if(cbcr === true) {
 | 
				
			||||||
        var tmpdest = uuid.v1().split('-')[0];
 | 
					 | 
				
			||||||
        var dat = fs.createWriteStream('./b/' + tmpdest);
 | 
					        var dat = fs.createWriteStream('./b/' + tmpdest);
 | 
				
			||||||
        var info;
 | 
					        var info;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
@@ -79,9 +84,8 @@ module.exports = (lib) => {
 | 
				
			|||||||
                  .on('response', (res) => {
 | 
					                  .on('response', (res) => {
 | 
				
			||||||
                    if(res.headers['content-length'] > cfg.maxFileSize) {
 | 
					                    if(res.headers['content-length'] > cfg.maxFileSize) {
 | 
				
			||||||
                      res.destroy();
 | 
					                      res.destroy();
 | 
				
			||||||
                      dat.close();
 | 
					                      dat.end();
 | 
				
			||||||
                      fs.unlinkSync('./b/' + tmpdest);
 | 
					                      cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(res.headers['content-length'])+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
 | 
				
			||||||
                      cb({ success: false, msg: 'f0ck! your file is too big (~'+lib.formatSize(res.headers['content-length'])+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    else {
 | 
					                    else {
 | 
				
			||||||
                      info = {
 | 
					                      info = {
 | 
				
			||||||
@@ -94,16 +98,14 @@ module.exports = (lib) => {
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
                  })
 | 
					                  })
 | 
				
			||||||
                  .on('error', (err) => {
 | 
					                  .on('error', (err) => {
 | 
				
			||||||
                    dat.close();
 | 
					                    dat.end();
 | 
				
			||||||
                    fs.unlinkSync('./b/' + tmpdest);
 | 
					                    cb({ success: false, file: tmpdest, msg: err.message });
 | 
				
			||||||
                    cb({ success: false, msg: ex });
 | 
					 | 
				
			||||||
                  })
 | 
					                  })
 | 
				
			||||||
                  .pipe(dat);
 | 
					                  .pipe(dat);
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
              catch(ex) {
 | 
					              catch(ex) {
 | 
				
			||||||
                dat.close();
 | 
					                dat.end();
 | 
				
			||||||
                fs.unlinkSync('./b/' + tmpdest);
 | 
					                cb({ success: false, file: tmpdest, msg: ex.message });
 | 
				
			||||||
                cb({ success: false, msg: ex });
 | 
					 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
@@ -123,9 +125,8 @@ module.exports = (lib) => {
 | 
				
			|||||||
              };
 | 
					              };
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else {
 | 
					            else {
 | 
				
			||||||
              dat.close();
 | 
					              dat.end();
 | 
				
			||||||
              fs.unlinkSync('./b/' + tmpdest);
 | 
					              cb({ success: false, file: tmpdest, msg: 'f0ck sc-api' });
 | 
				
			||||||
              cb({ success: false, msg: 'f0ck sc-api' });
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -141,7 +142,6 @@ module.exports = (lib) => {
 | 
				
			|||||||
              lib.log('MimeType: '+type);
 | 
					              lib.log('MimeType: '+type);
 | 
				
			||||||
              var length = res.headers['content-length'];
 | 
					              var length = res.headers['content-length'];
 | 
				
			||||||
              if(cfg.allowedMimes.hasOwnProperty(type)) {
 | 
					              if(cfg.allowedMimes.hasOwnProperty(type)) {
 | 
				
			||||||
                //if(length <= cfg.maxFileSize) {
 | 
					 | 
				
			||||||
                if(data.length <= cfg.maxFileSize) {
 | 
					                if(data.length <= cfg.maxFileSize) {
 | 
				
			||||||
                  var s = new Readable
 | 
					                  var s = new Readable
 | 
				
			||||||
                  s.push(data);
 | 
					                  s.push(data);
 | 
				
			||||||
@@ -156,21 +156,18 @@ module.exports = (lib) => {
 | 
				
			|||||||
                  };
 | 
					                  };
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else {
 | 
					                else {
 | 
				
			||||||
                  dat.close();
 | 
					                  dat.end();
 | 
				
			||||||
                  fs.unlinkSync('./b/' + tmpdest);
 | 
					                  cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(data.length)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
 | 
				
			||||||
                  cb({ success: false, msg: 'f0ck! your file is too big (~'+lib.formatSize(data.length)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
              else {
 | 
					              else {
 | 
				
			||||||
                dat.close();
 | 
					                dat.end();
 | 
				
			||||||
                fs.unlinkSync('./b/' + tmpdest);
 | 
					                cb({ success: false, file: tmpdest, msg: '' });
 | 
				
			||||||
                cb({ success: false, msg: '' });
 | 
					 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else {
 | 
					            else {
 | 
				
			||||||
              dat.close();
 | 
					              dat.end();
 | 
				
			||||||
              fs.unlinkSync('./b/' + tmpdest);
 | 
					              cb({ success: false, file: tmpdest, msg: err });
 | 
				
			||||||
              cb({ success: false, msg: err });
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -178,32 +175,36 @@ module.exports = (lib) => {
 | 
				
			|||||||
        dat
 | 
					        dat
 | 
				
			||||||
          .on('finish', () => {
 | 
					          .on('finish', () => {
 | 
				
			||||||
            var size = dat.bytesWritten;
 | 
					            var size = dat.bytesWritten;
 | 
				
			||||||
            dat.close();
 | 
					            dat.end();
 | 
				
			||||||
            if(size > cfg.maxFileSize)
 | 
					            if(size > cfg.maxFileSize)
 | 
				
			||||||
              cb({ success: false, msg: 'f0ck! your file is too big (~'+lib.formatSize(size)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
 | 
					              cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(size)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
 | 
				
			||||||
            else {
 | 
					            else {
 | 
				
			||||||
              lib.getCheckSum('./b/' + tmpdest, (cbcs) => {
 | 
					              fs.stat('./b/' + tmpdest, (err, stat) => {
 | 
				
			||||||
                lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
 | 
					                if(!err && stat.isFile() && stat.size > 300) {
 | 
				
			||||||
                  if(cbcrcs === true) {
 | 
					                  lib.log('Datei '+tmpdest+' existiert');
 | 
				
			||||||
                    var mime = fileType(readChunk.sync('./b/' + tmpdest, 0, 262));
 | 
					                  lib.getCheckSum('./b/' + tmpdest, (cbcs) => {
 | 
				
			||||||
                    if(cfg.allowedMimes.hasOwnProperty(mime.mime) || info.type === 'soundcloud')
 | 
					                    lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
 | 
				
			||||||
                      cb({ success: true, info: info, size: size, file: './b/' + tmpdest, checksum: cbcs });
 | 
					                      if(cbcrcs === true) {
 | 
				
			||||||
                    else
 | 
					                        var mime = fileType(readChunk.sync('./b/' + tmpdest, 0, 262));
 | 
				
			||||||
                      cb({ success: false, msg: 'lol, go f0ck yourself ('+mime+')' });
 | 
					                        if(cfg.allowedMimes.hasOwnProperty(mime.mime) || info.type === 'soundcloud')
 | 
				
			||||||
                  }
 | 
					                          cb({ success: true, info: info, size: size, file: './b/' + tmpdest, checksum: cbcs });
 | 
				
			||||||
                  else
 | 
					                        else
 | 
				
			||||||
                    cb({ success: false, msg: 'repost motherf0cker: '+cfg.url+'/'+cbcrcs });
 | 
					                          cb({ success: false, file: tmpdest, msg: 'lol, go f0ck yourself ('+mime+')' });
 | 
				
			||||||
                });
 | 
					                      }
 | 
				
			||||||
 | 
					                      else
 | 
				
			||||||
 | 
					                        cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+cfg.url+'/'+cbcrcs });
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					                  });
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
              });
 | 
					              });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          })
 | 
					          })
 | 
				
			||||||
          .on('error', (err) => {
 | 
					          .on('error', (err) => {
 | 
				
			||||||
            fs.unlinkSync('./b/' + tmpdest);
 | 
					            cb({ success: false, file: tmpdest, msg: err });
 | 
				
			||||||
            cb({ success: false, msg: err });
 | 
					 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      else
 | 
					      else
 | 
				
			||||||
        cb({ success: false, msg: 'repost motherf0cker: '+cfg.url+'/'+cbcr });
 | 
					        cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+cfg.url+'/'+cbcr });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
		Reference in New Issue
	
	Block a user