소스 검색

Initial commit.

master
Morgan Bazalgette 4 년 전
커밋
46306ed6e2
9개의 변경된 파일330개의 추가작업 그리고 0개의 파일을 삭제
  1. 4
    0
      .gitignore
  2. 4
    0
      config.sample.js
  3. 254
    0
      index.js
  4. 23
    0
      lngthg.js
  5. 18
    0
      package.json
  6. 11
    0
      peppysentences.js
  7. 11
    0
      run.js
  8. 0
    0
      tmp/.keep
  9. 5
    0
      utils.js

+ 4
- 0
.gitignore 파일 보기

@@ -0,0 +1,4 @@
config.js
node_modules
tmp/*
!tmp/.keep

+ 4
- 0
config.sample.js 파일 보기

@@ -0,0 +1,4 @@
module.exports = {
token: "",
maxQueue: 20
};

+ 254
- 0
index.js 파일 보기

@@ -0,0 +1,254 @@
var Bot = require('node-telegram-bot');
var request = require('request');
var fs = require("fs");
var token = require("./config").token;
var maxQueue = require("./config").maxQueue;
var peppysentences = require("./peppysentences");
var strings = require("./lngthg");
var utils = require("./utils");
var memoryData = {
myName: "",
users: []
};
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
}
Array.prototype.randomElement = function () {
return this[Math.floor(Math.random() * this.length)]
}
var newMember = function(memberName, chatID) {
if (memberName == memoryData.myName) {
sendWelcomeGroup();
return;
}
bot.sendMessage({
chat_id: chatID,
text: strings.userWelcomeInGroup.randomElement().format(memberName)
});
};
var sendWelcomeGroup = function(chatID) {
bot.sendMessage({
chat_id: chatID,
text: strings.welcomeGroup
});
};
var sendWelcomeUser = function(chatID) {
var userPref = getUserInMemory(chatID);
bot.sendMessage({
chat_id: chatID,
text: strings.welcomeUser.format((userPref.last_tags === null ? strings.noPreviousTags : strings.lastTagsWere.format(userPref.last_tags)), userPref.rating, maxQueue)
});
};
var sendPic = function(userID, chatID) {
// Get the user preferences
var user = getUserInMemory(userID);
console.log("[BOT STATUS] Sending hentai picture to {0}...".format(userID));
// 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) {
if (err)
throw err;
utils.parseXml(body, function(err, result) {
if (err)
throw err;
postCount = result.posts.$.count;
if (postCount == 0) {
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."
});
memoryData.users[userID].last_tags = null;
return;
}
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) {
utils.parseXml(body, function(err, result) {
postUrl = result.posts.post[0].$.file_url;
actualPostID = result.posts.post[0].$.id;
splitPostUrl = postUrl.split("/");
filename = splitPostUrl[splitPostUrl.length - 1];
temp_filename = 'tmp/' + utils.r(0, 2000) + filename;
request(postUrl, function(err, re, body) {
bot.sendPhoto(
{
chat_id: chatID,
files: {
photo: temp_filename
},
caption: "source: http://gelbooru.com/index.php?page=post&s=view&id=" + actualPostID
}, function(){
fs.unlink(temp_filename, function(){});
memoryData.users[userID].queue -= 1;
if (memoryData.users[userID].queue > 0) {
sendPic(userID, chatID);
}
}
);
}).pipe(fs.createWriteStream(temp_filename));
});
});
});
});
};
var slashGet = function(userID, chatID, command) {
var tags;
if (command.indexOf(" ") !== -1)
tags = command.trim().substr(command.indexOf(" ")).trim();
else
tags = null;
getUserInMemory(userID);
memoryData.users[userID].last_tags = tags;
multiple(userID, chatID, 1);
};
var changeRating = function(userID, chatID, newRating) {
getUserInMemory(userID);
if (newRating !== "everything" && newRating !== "explicit"
&& newRating !== "questionable" && newRating !== "safe")
memoryData.users[userID].rating = newRating;
else
bot.sendMessage({
chat_id: chatID,
text: "You what. That isn't a valid rating. Say /start privately to me to know how to do a proper /rating command."
});
multiple(userID, chatID, 1);
};
var multiple = function(userID, chatID, times) {
// just to create if doesn't exist
getUserInMemory(userID);
memoryData.users[userID].queue += times;
if (memoryData.users[userID].queue > maxQueue) {
memoryData.users[userID].queue = maxQueue;
bot.sendMessage({
chat_id: chatID,
text: "Calm down a bit! You're requesting too many images. I've set the queue to send {0} images, although please do not abuse the system!".format(maxQueue)
});
}
sendPic(userID, chatID);
}
// reminder to self: in sendPic, add a try {} catch (e) {sendpic again} or whatever system
// reminder to self: setting to just give url to gelbooru pic, that is default to true because it reduces bandwith, a lot.
var getUserInMemory = function(user) {
if (typeof memoryData.users[user] === "undefined") {
// default values
memoryData.users[user] = {
last_tags: "-futanari",
rating: "explicit",
queue: 0
};
}
return memoryData.users[user];
};
var bot = new Bot({
// Token is in config.js. Check top of this script.
token: token
});
bot.on('message', function (message) {
//console.log(message); // Comment if too verbose.
var isGroup = (message.from.id != message.chat.id);
message.text = (message.text ? message.text : "no text");
if (isGroup)
console.log("{0} => {1}: {2}".format(message.from.first_name, message.chat.title, message.text));
else
console.log("{0}: {1}".format(message.from.first_name, message.text));
if (message.new_chat_participant) {
newMember(message.new_chat_participant.first_name, message.chat.id);
return;
}
// command
if (message.text[0] == "/") {
var command = message.text.substr(1).split(" ");
// if there's a @boorubot at the end of the first parameter, trim it
command[0] = (command[0].substr(-9) == "@boorubot" ? command[0].substr(0, command[0].length - 9) : command[0]);
switch (command[0].toLowerCase()) {
case "start":
case "help":
if (isGroup)
sendWelcomeGroup(message.chat.id);
else
sendWelcomeUser(message.chat.id);
break;
case "peppy":
bot.sendMessage({
chat_id: message.chat.id,
text: peppysentences.randomElement()
});
break;
case "get":
slashGet(message.from.id, message.chat.id, message.text);
break;
case "rating":
changeRating(message.from.id, message.chat.id, command[1]);
break;
case "multiple":
if (!isGroup) {
var actualnum = parseInt(command[1]);
if (actualnum === NaN) {
bot.sendMessage({
chat_id: message.chat.id,
text: "What the fuck is '{0}'?! For sure not a number.".format(command[1])
});
return;
}
if (actualnum < 1) {
bot.sendMessage({
chat_id: message.chat.id,
text: "https://www.youtube.com/watch?v=cjZdFg3F05E"
});
return;
}
multiple(message.from.id, message.chat.id, actualnum);
}
else {
bot.sendMessage({
chat_id: message.chat.id,
text: "Yo, {0}. I can't send multiple pics in a group, you know.".format(message.from.first_name)
});
}
break;
default:
if (!isGroup)
bot.sendMessage({
chat_id: message.chat.id,
text: "I-I'm sorry {0}-san, senpai didn't teach me how to reply to that command...".format(message.from.first_name)
});
break;
}
}
else {
switch (message.text.toLowerCase().trim()) {
case "hentai!":
case "hlkup":
multiple(message.from.id, message.chat.id, 1);
break;
case "h":
if (!isGroup)
multiple(message.from.id, message.chat.id, 1);
break;
case "ping":
bot.sendMessage({
chat_id: message.chat.id,
text: ["pong I guess?", "Ciao mauro!", "You what, we're not playing bloody ping pong.", "Pinging 8.8.8.8 with 32 bytes of data:\nReply from 8.8.8.8: bytes=32 time=53ms TTL=56", "Hey, I'm alive!", "/me tips fedora"].randomElement()
});
break;
}
}
})
.start()
.getMe(function(err, res) {
if (err !== null)
throw err;
console.log("Oh hey there young ladies! boorugram here, running on @" + res.username + " under the name " + res.first_name + ". Ready to serve!");
memoryData.myName = res.first_name;
});

+ 23
- 0
lngthg.js 파일 보기

@@ -0,0 +1,23 @@
exports.userWelcomeInGroup = ["Well, it looks like {0} has been forced to join the circle jerking. Welcome!", "What the fuck is {0} doing here? He's got a small pe- nothing.", "Hey {0}, I hope you enjoy hentai. I'm gonna post a lot in here ;)", "Yet another pervert named {0} has joined the perverts club™. Welcome!", "Hey {0}, I'm that one bot who posts hentai pics. If you don't know what hentai is, I suggest you to lookup 'ahegao' on google. You might find something good to unzip your trousers for."];
exports.welcomeGroup = "O hay thar. If someone in here would like their friend's mother discover they fap to 2D anime girls, just say \"hentai!\" or \"hlkup\" and I'll take care of the rest. The sauce is gelbooru, btw.";
exports.welcomeUser = "Hello there! I am a bot written by @dahhowl that is going to be your best friend during lonely nights. Only you, your phone, and the bot, providing you with some nice pictures taken from the best website in the world for fap material, and that is: gelbooru! We (will) also support search and plenty of other functionalities. If you want to do some circle jerking, you can invite this bot in a group, too!\n\
\n\
Here are a few commands to start off:\n\
/get [tags]\n\
/rating <safe/questionable/explicit/everything>\n\
/peppy\n\
/multiple <number>\n\
h\n\
hentai!\n\
hlkup\n\
ping\n\
\n\
/get is the way to go if you want to lookup hentai with some tags. You must format the tags as explained on the gelbooru cheatsheet (http://gelbooru.com/index.php?page=help&topic=cheatsheet). If you /get without any parameters, it resets your tags and just gets whatever picture. Current tags: \"{0}\" (if only -futanari shows up, that's normal. it's just a way to prevent you having an heart attack because SUDDENLY DICKS)\n\
If you prefer not to see lolis being fucked by 60-year-olds, you can also set /rating to safe, so that I know I should only deliver you cute anime girls without the dicks. By default this is set on \"explicit\", because hentai is what I was developed for. If you'd rather also see safe and questionable content, you can set /rating to everything. Current rating of pictures: {1}\n\
You can get multiple pictures by typing /multiple followed by a number, which is the number of pictures I should post to you. Please note this does not work in group chats. The maximum number of pictures an user can have in a queue is {2}.\n\
If you want me to send you some hentai without changing your tags, you can use 'h', 'hentai!' or 'hlkup'. 'h' doesn't work in groups, though.\n\
If you require to see if the bot is alive, saying 'ping' will do it.\n\
And that's pretty much it! If you have any questions, do not hesitate to contact @dahhowl on telegram, or shoot me an email at the@howl.moe. This includes suggestions, bug reporting, and whatever.\n\
(psst! We are open source! You can freely implement features or make your own fork! Have a look at the source code here: https://github.com/TheHowl/boorugram)";
exports.noPreviousTags = "You have no previous tags, or you have reset them. Use /get to make your last tags appear here!";
exports.lastTagsWere = "Your last tags were: {0}";

+ 18
- 0
package.json 파일 보기

@@ -0,0 +1,18 @@
{
"name": "boorugram",
"version": "1.0.0",
"description": "using booru browsers for fapping is mainstream. get a bot that deliveries all your fapping needs, straight into the best messaging app!",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Howl <the@howl.moe>",
"license": "MIT",
"dependencies": {
"forever-monitor": "^1.6.0",
"node-telegram-bot": "^0.1.2",
"request": "^2.61.0",
"sqlite3": "^3.1.0",
"xml2js": "^0.4.12"
}
}

+ 11
- 0
peppysentences.js 파일 보기

@@ -0,0 +1,11 @@
module.exports = [
"fuck a donkey",
"suck on my 8-inch dick",
"marcostudios is a cunt",
"i swear god humanity wasn't always this gay",
"go for it 🎱",
"Hello. peppy here. Ex-owner of OH-SUE and prime minister of Australia.",
"don't worry about the server load. that's my problem.",
"I heard of a potato who is publicly accusing us of using 'bad' encryption",
"you fucking shitlord cunt"
];

+ 11
- 0
run.js 파일 보기

@@ -0,0 +1,11 @@
var forever = require('forever-monitor');
var child = new (forever.Monitor)('index.js', {
});
child.on('exit', function () {
console.log('forever has stopped');
});
child.start();

+ 0
- 0
tmp/.keep 파일 보기


+ 5
- 0
utils.js 파일 보기

@@ -0,0 +1,5 @@
var xml2js = require('xml2js');
exports.parseXml = xml2js.parseString;
exports.r = function(min,max) {
return Math.floor(Math.random()*(max-min+1)+min);
};

Loading…
취소
저장