Browse Source

whatever the fuck i am doing, it seems to work now

master
Morgan Bazalgette 4 years ago
parent
commit
b84dc51448
1 changed files with 7 additions and 3 deletions
  1. 7
    3
      index.js

+ 7
- 3
index.js View File

@@ -56,7 +56,7 @@ var sendPic = function(userID, chatID) {
var user = getUserInMemory(userID);
console.log("[BOT STATUS] Sending hentai picture to {0}...".format(chatID));
// First request, just to get the count of posts.
request("http://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=0&tags=" + encodeURIComponent((user.last_tags === null? "" : user.last_tags) + " -webm " + (user.rating != "everything"? "rating:" + user.rating : "")), function(err, re, body) {
request("http://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=0" + tagsString(user.last_tags, user.rating), function(err, re, body) {
if (err)
throw err;
utils.parseXml(body, function(err, result) {
@@ -64,9 +64,9 @@ var sendPic = function(userID, chatID) {
throw err;
postCount = result.posts.$.count;
postID = utils.r(1, (+postCount));
request("http://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=1&tags=" + encodeURIComponent((user.last_tags === null? "" : user.last_tags) + " -webm " + (user.rating != "everything"? "rating:" + user.rating : "")) + "&pid=" + postID, function (err, re, body) {
request("http://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=1" + tagsString(user.last_tags, user.rating) + "&pid=" + postID, function (err, re, body) {
utils.parseXml(body, function(err, result) {
if (typeof result.posts.post[0] !== "undefined") {
if (typeof result.posts.post[0] === "undefined") {
bot.sendMessage({
chat_id: userID,
text: "I'm sorry, but I was unable to find any images for those tags. Perhaps try again? I have reset the tags for you, btw."
@@ -79,6 +79,7 @@ var sendPic = function(userID, chatID) {
splitPostUrl = postUrl.split("/");
filename = splitPostUrl[splitPostUrl.length - 1];
temp_filename = 'tmp/' + utils.r(0, 2000) + filename;
console.log("total derp. {0} - {1} - {2} - {3}".format(userID, chatID, temp_filename));
request(postUrl, function(err, re, body) {
bot.sendPhoto(
{
@@ -101,6 +102,9 @@ var sendPic = function(userID, chatID) {
});
});
};
var tagsString = function(lastTags, rating) {
return "&tags=" + encodeURIComponent((lastTags === null? "" : lastTags) + " -webm " + (rating != "everything"? "rating:" + rating : ""));
}
var slashGet = function(userID, chatID, command) {
var tags;
if (command.indexOf(" ") !== -1)

Loading…
Cancel
Save