37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
|
const config = require("./config");
|
||
|
const https = require("https");
|
||
|
const fs = require("fs");
|
||
|
const path = require("path");
|
||
|
const util = require("util");
|
||
|
const modules = fs.readdirSync(config.modules);
|
||
|
var storage = {};
|
||
|
modules.forEach(function(module) {
|
||
|
storage[module] = {};
|
||
|
});
|
||
|
|
||
|
function setStatus(text) {
|
||
|
var data = JSON.stringify({ custom_status: { text } });
|
||
|
var Request = https.request("https://discord.com/api/v8/users/@me/settings");
|
||
|
Request.method = "PATCH";
|
||
|
Request.setHeader("authorization", config.token);
|
||
|
Request.setHeader("content-length", Buffer.from(data).length);
|
||
|
Request.setHeader("content-type", "application/json");
|
||
|
Request.setHeader("dnt", 1);
|
||
|
Request.setHeader("user-agent", config.useragent);
|
||
|
Request.write(data);
|
||
|
Request.end();
|
||
|
}
|
||
|
|
||
|
var counter = 0;
|
||
|
function update() {
|
||
|
if (counter >= modules.length) counter = 0;
|
||
|
const filename = modules[counter];
|
||
|
const basename = path.basename(filename, ".js");
|
||
|
require(path.join(config.modules, filename))(storage[filename], function(string) {
|
||
|
setStatus(util.format(config.format, basename, string));
|
||
|
console.log("[" + new Date().toLocaleString() + "] Switching to " + filename)
|
||
|
});
|
||
|
counter++;
|
||
|
}
|
||
|
setInterval(update, config.interval * 1000);
|
||
|
update();
|