-
-
Save anonymous/a0619c190cb5837d20272445f9642b9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(grunt){ | |
var $request = require('request-promise'); | |
var $q = require('q'); | |
var API_URL = 'http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC'; | |
var USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36'; | |
var USER_ACCOUNT = { | |
'username': '*****', | |
'password': '*****' | |
}; | |
function _login() { | |
return $request({ | |
'method': 'POST', | |
'uri': 'http://board.es.aion.gameforge.com/index.php?form=UserLogin', | |
'headers': { | |
'user-agent': USER_AGENT | |
}, | |
'form': { | |
'loginForm': 'loginForm', | |
'username': USER_ACCOUNT['username'], | |
'password': USER_ACCOUNT['password'], | |
}, | |
'resolveWithFullResponse': true | |
}).then(function(response){ | |
grunt.file.write('login.json', JSON.stringify(response, null, ' ')); | |
grunt.file.write('login.html', response.body); | |
if(response['headers']['set-cookie']) { | |
return response['headers']['set-cookie'][0].split(';')[0]; | |
} else { | |
return null; | |
} | |
}); | |
} | |
//Posts the image | |
function _postImage(cookie, gif){ | |
return $request({ | |
'method': 'POST', | |
'uri': 'http://board.es.aion.gameforge.com/index.php?form=PostAdd&threadID=7647', | |
'headers': { | |
'user-agent': USER_AGENT, | |
'cookie': cookie, | |
}, | |
'form': { | |
'subject': '', | |
'text': '[img]' + gif + '[/gif]\nAutomatic post ^^', | |
'mce_editor_0_fontNameSelect': '', | |
'mce_editor_0_fontSizeSelect': 0, | |
'wysiwygEditorHeight': 343, | |
'wysiwygEditorMode': 0, | |
'parseURL': 1, | |
'enableSmilies': 1, | |
'enableBBCodes': 1, | |
'showSignature': 1, | |
'subscription': 1, | |
'hideEditNote': 1, | |
'upload': [], | |
'memoID': 18, | |
'activeTab': 'smilies', | |
'send': 'Submit' | |
}, | |
'resolveWithFullResponse': true | |
}).then(function(fullResponse){ | |
grunt.file.write('output.json', JSON.stringify(fullResponse, null, ' ')); | |
}).catch(function(error){ | |
grunt.file.write('output.json', JSON.stringify(error, null, ' ')); | |
grunt.file.write('output.html', error.response.body); | |
}); | |
} | |
//Retrieves a random gif | |
function _getRandomGif() { | |
return $request({ | |
'method': 'GET', | |
'uri': API_URL, | |
'json': true | |
}).then(function(response){ | |
return response.data['image_url']; | |
}); | |
} | |
grunt.registerTask('default', 'task when u type just grunt', function(){ | |
var done = this.async(); | |
var $$q = _login(); | |
$$q = $$q.then(function(cookie) { | |
return _getRandomGif().then(function(gif) { | |
return { | |
'cookie': cookie, | |
'gif': gif | |
}; | |
}); | |
}); | |
$$q = $$q.then(function(data){ | |
grunt.log.ok('posting image, %s', data.cookie); | |
return _postImage(data.cookie, data.gif); | |
}); | |
$$q.finally(done); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment