Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var cfg = require("./tgcfg");
- const TOKEN = cfg.TOKEN;
- var api = require("node-telegram-bot-api");
- var fs = require("fs");
- var request = require("request");
- request = request.defaults({ jar: true });
- var config = require("./config");
- var ibf = require("isbinaryfile");
- //var mirror = require("./mirror");
- //var sleep = require("sleep");
- //var san = require("sanitize-filename");
- var bot = new api(TOKEN, {polling: true});
- bot.onText(/\/log(|@osumirrorbot) (chat|dump)/i, (msg, match) => {
- if(cfg.admin == msg.from.id) {
- if(match[2] == "dump") {
- bot.sendMessage(msg.chat.id, "Sending useless message as response at dump logger.");
- }
- console.log("Got log in " + msg.chat.id + ", " + msg.chat.title + " with data " + match[2]);
- console.log(msg);
- }
- else {
- bot.sendMessage(msg.chat.id, "Sorry, you are not premitted to use /log command");
- console.log(msg.from.id + ", " + msg.from.username + " in " + msg.chat.title + " not premitted to logging");
- }
- });
- bot.onText(/^\/get(|@osumirrorbot) (https:\/\/osu.ppy.sh\/(d|s)\/(\d+$))/i, (msg, match) => {
- var loginObject = {
- username: config.user,
- password: config.password,
- autologin: "on",
- sid: "",
- redirect: "index.php",
- viewonline: "off",
- login: "Login"
- };
- var filename;
- var apilink = "https://osu.ppy.sh/api/get_beatmaps?k=" + config.apiKey + "&b=" + match[4];
- try {
- request(apilink, (err, resp, body) => {
- console.log(body);
- body = JSON.parse(body);
- console.log(body[0].beatmap_id);
- filename = body[0].beatmap_id + ".osz";
- });
- }
- catch (e) {
- bot.sendMessage(msg.chat.id, "404!");
- }
- bot.sendMessage(msg.chat.id, msg.from.username + ", starting download, this may take a while");
- request.post({ url: "https://osu.ppy.sh/forum/ucp.php?mode=login", form: loginObject }, (err,httpResponse,body) => {
- if (err === null)
- console.log("Page downloading success!");
- else
- bot.sendMessage(msg.chat.id, "Sorry, something went wrong");
- var gotl = match[2];
- gotl[19] = "d";
- var needl = gotl + "n";
- request(needl, function() {
- console.log("done. checking download worked...");
- console.log(filename);
- if (!ibf("./" + filename)) {
- console.log("Something went wrong. The test beatmap isn't a binary file. Perhaps you wrote the wrong password?");
- }
- bot.sendMessage(msg.chat.id, msg.from.username + ", looks like map downloaded, sending");
- var file = String(filename);
- bot.sendDocument(msg.chat.id, String(file)).then(() => {
- bot.sendMessage(msg.chat.id, "Here is your file");
- fs.unlink(filename);
- }, (err) => {
- bot.sendMessage(msg.chat.id, "Sorry, I can't send you file");
- });
- console.log("Sending...");
- }).pipe(fs.createWriteStream(filename));
- });
- });
- process.stdin.resume();
- process.on('SIGINT', () => {
- console.log("\nGot SIGINT. Exiting...");
- process.exit();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement