Fooksie

sandbot.js

Jul 14th, 2017
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var https=require("https");
  2. var dat_em={
  3.     host: "epicmafia.com",
  4.     path: "/lobby",
  5.     headers: {
  6.         // you can find these set as cookies, just copy/paste
  7.         "cookie": "never.give.away.this.key=[[KEY_HERE]];__cfduid=[[CFD_HERE]]"
  8.         }
  9.     };
  10. var dat_discord={
  11.     method: "POST",
  12.     host: "discordapp.com",
  13.     // you'll need a new webhook if you want the discord announcements
  14.     // i think if you just leave this alone it'll fail gracefully
  15.     path: "/api/webhooks/???/???",
  16.     headers: {
  17.         "content-type": "application/json"
  18.         }
  19.     }
  20. var set_ft=[];
  21. const SETUPS=[
  22.     {   // standard 12p closed
  23.         type: "/double_points",
  24.         pool: [1378565, 1390329, 1407228, 1414719, 1415080, 1415276, 1419237]
  25.         },
  26.     {   // standard 6p closed
  27.         type: "/double_points",
  28.         pool: [1415092, 1415456]
  29.         },
  30.     {   // unique closed
  31.         type: "/lobby_sticky",
  32.         pool: [1376390, 1376423, 1378029, 1393178, 1413309, 1414936, 1415608, 1416161, 1418987]
  33.         },
  34.     {   // unique open
  35.         type: "/lobby_sticky",
  36.         pool: [356450, 564946, 676322, 929891, 1351981, 1372345, 1376463, 1386893, 1391372, 1415574]
  37.         }
  38.     ];
  39. const BANNERS=[
  40.     [   // funky friday
  41.         "http://i.imgur.com/8lM5Vs3.png#chris"
  42.         ],
  43.     [   // weekly
  44.         "http://i.imgur.com/xYj9Xzc.png#chris",
  45.         "http://i.imgur.com/xPJoyMv.png#chris",
  46.         "http://i.imgur.com/pXpcBGs.jpg#ckrox",
  47.         "http://i.imgur.com/5NDtjZO.png#ben"
  48.         ]
  49.     ];
  50. const BIO_BODY="\n\nSandbox games are *not* moderated, but community guidelines still apply\nhttps://epicmafia.com/lobby/rules#siterulecategory_21\n\n";
  51. const BIO_TAG=[
  52.     "Feeling chilly? \u26c4",
  53.     "Have a wonderful day! \u2764",
  54.     "Honesty is the best policy",
  55.     "Lightkeeper is a mafia role",
  56.     "Mods can't save you.",
  57.     "Please don't feed the weebs",
  58.     "Rise and shine! \u26c5",
  59.     "Welcome to the jungle"
  60.     ];
  61. const BIO_LINK=[
  62.     "Check out the latest so-called updates\nhttps://epicmafia.com/topic/85248",
  63.     "What's new?\nhttps://epicmafia.com/topic/85248",
  64.     "Come spam with us!\nhttps://discord.gg/yFHM4yF",
  65.     "Need someone to talk to?\nhttps://discord.gg/yFHM4yF",
  66.     "Love cool setups? Post some here\nhttps://epicmafia.com/topic/85150",
  67.     "Get your setup featured today!\nhttps://epicmafia.com/topic/85150",
  68.     "Is graphic design your passion?\nhttps://epicmafia.com/topic/85149",
  69.     "Submit your lobby banner today!\nhttps://epicmafia.com/topic/85149"
  70.     ];
  71. const JABBER=[
  72.     ":pushpin: Reminder to submit your setups here!\nhttps://epicmafia.com/topic/85150",
  73.     ":pushpin: Try something different, why don't you?\nhttps://epicmafia.com/topic/85150",
  74.     ":pushpin: We could really use some more early morning setups!\nhttps://epicmafia.com/topic/85150",
  75.     ":frame_photo: Is graphic design your passion? It doesn't matter, I'm desperate for banners.\nhttps://epicmafia.com/topic/85149",
  76.     ":frame_photo: Get your sloppy doodles featured today!\nhttps://epicmafia.com/topic/85149",
  77.     ":frame_photo: Why are you holding out on me? Come on.\nhttps://epicmafia.com/topic/85149",
  78.     ":grey_question: Do these messages suck? Too bad.",
  79.     ":grey_question: Did you know Tatsumaki is gay?",
  80.     ":grey_question: Remember, you can post community- and mafia-related suggestions in their respective forums!",
  81.     ":grey_question: I'm running out of quirky messages, please donate!",
  82.     ":grey_question: VIP and above can add emojis, in case you didn't know.",
  83.     ":grey_question: These messages appear once every 6 hours, which means they'll annoy you on four different occasions every day!"
  84.     ];
  85.  
  86. https.get(dat_em, function(response) {
  87.     var body="";
  88.     response.on("data", function(data) {
  89.         body+=data;
  90.         });
  91.     response.on("end", function() {
  92.         set_ft=JSON.parse(
  93.             body.match(/"double_setups":(\[.+?\])/)[1]
  94.             ).concat(
  95.                 JSON.parse(
  96.                     body.match(/"stickied_setups":(\[.+?\])/)[1]
  97.                     )
  98.                 );
  99.         for(var i=0; i<set_ft.length; i++) {
  100.             set_ft[i]=set_ft[i].id;
  101.             }
  102.         console.log("Loaded featured: %s", set_ft.join(", "));
  103.         rotate_setups(0, false);
  104.         });
  105.     });
  106.  
  107. function random(list) {
  108.     return list[Math.floor(Math.random()*list.length)];
  109.     }
  110.  
  111. function discord_chat(message) {
  112.     https.request(dat_discord).end(
  113.         JSON.stringify({
  114.             content: message
  115.             })
  116.         );
  117.     }
  118.  
  119. function rotate_setups(i, done) {
  120.     var setup=done ? random(SETUPS[i].pool) : set_ft[i];
  121.     dat_em.method="PUT";
  122.     dat_em.path="/setup/"+setup+SETUPS[i].type;
  123.     https.get(dat_em, function(response) {
  124.         response.destroy();
  125.         console.log("%s: feature %s:%s (%s)", Date.now(), setup, done, response.statusCode);
  126.         if(!done) {
  127.             rotate_setups(i, true);
  128.             }
  129.         else {
  130.             set_ft[i]=setup;
  131.             if(++i < SETUPS.length) {
  132.                 rotate_setups(i, false);
  133.                 }
  134.             }
  135.         });
  136.     }
  137.  
  138. function init_jabber() {
  139.     discord_chat(random(JABBER));
  140.     }
  141.  
  142. function init_rotate() {
  143.     discord_chat(":recycle: Stickied setups have been rotated!");
  144.     rotate_setups(0, false);
  145.     }
  146.  
  147. function init_newday(init) {
  148.     var day=(new Date()).getDay();
  149.     dat_em.method="PUT";
  150.     dat_em.path="/lobby/5/announcement?announcement="+encodeURIComponent(
  151.         random(BIO_TAG)+BIO_BODY+random(BIO_LINK)
  152.         );
  153.     https.get(dat_em);
  154.     if(init) {
  155.         discord_chat(":fox: Sandbot is online");
  156.         }
  157.     else if(day===5) {
  158.         discord_chat(":pizza: Have a funky friday, nerds!");
  159.         }
  160.     else {
  161.         discord_chat(":sunflower: Good morning!");
  162.         }
  163.     if(day===5 || day===6) {
  164.         dat_em.method="PUT";
  165.         dat_em.path="/lobby/5/banner?banner="+encodeURIComponent(
  166.             random(BANNERS[day-5])
  167.             );
  168.         https.get(dat_em);
  169.         }
  170.     }
  171.  
  172. init_newday(true);
  173.  
  174. setTimeout(function() {
  175.     init_newday();
  176.     setInterval(init_jabber, 21600000);
  177.     setInterval(init_rotate, 43200000);
  178.     setInterval(init_newday, 86400000);
  179.     }, Date.now() % 86400000);
Advertisement
Add Comment
Please, Sign In to add comment