const express = require('express');
const app = express();
const { promisify } = require('util');
const osutilsWrapper = (func) => {
    return (callback) => {
        func((val) => {
            return callback(undefined, val);
        });
    };
};
const os = promisifyAll(require('os-utils'));
const port = os.platform() === 'win32' ? 42069 : 80; // Don't even ask.

module.exports = function (Bot) {
    app.listen(port, () => {
        Bot.log(`Web server listening on port ${port}.`);
    });

    app.use(express.static('./website'));

    app.get('/api/stats', async (req, res) => {
        res.send(JSON.stringify({
            guilds: Bot.client.guilds.size,
            channels: `${Bot.client.channels.filter(c => c.type === 'voice').size} voice, ${Bot.client.channels.filter(c => c.type === 'text').size} text (${Bot.client.channels.filter(c => c.type === 'text' || c.type === 'voice').size} total)`,
            users: `${Bot.client.users.size}`,
            ram: `${(process.memoryUsage().rss / 1048576).toFixed()}MB/${(os.totalmem() > 1000 ? `${(os.totalmem() / 1000).toFixed(1)}GB` : `${os.totalmem().toFixed()}MB`)}
            (${(process.memoryUsage().rss / (os.totalmem() * 1048576) * 100).toFixed(2)}%), ${(os.freemem() > 1024 ? `${(os.freemem() / 1024).toFixed(1)}GB` : `${os.freemem().toFixed()}MB`)} free on server`, // ewww
            cpu: `${(await os.cpuUsageAsync() * 100).toFixed(2)}%`}
        ));
    });

    app.get('/api/uptime', (req, res) => {
        res.send(process.uptime().toString());
    });
};

function promisifyAll (obj) {
    const ret = obj;
    for (const key in obj) {
        if (!obj.hasOwnProperty(key)) {
            continue;
        }
        const val = obj[key];
        if (typeof val === 'object' && !Array.isArray(val)) {
            ret[key] = promisifyAll(val);
        }
        if (typeof val !== 'function') {
            continue;
        }
        ret[`${key}Async`] = promisify(osutilsWrapper(val));
    }
    return ret;
}
@@ -95,161 +95,8 @@
 ');%0A
-const osutilsWrapper = (func) =%3E %7B%0A    return (callback) =%3E %7B%0A        func((val) =%3E %7B%0A            return callback(undefined, val);%0A        %7D);%0A    %7D;%0A%7D;%0A
 cons
@@ -137,16 +137,16 @@
 ils'));%0A
+
 const po
@@ -423,32 +423,165 @@
 (req, res) =%3E %7B%0A
+        const totalMem = os.totalmem();%0A        const processMem = process.memoryUsage().rss;%0A        const freeMem = os.freemem();%0A%0A
         res.send
@@ -642,16 +642,17 @@
 s.size,%0A
+%0A
         
@@ -888,16 +888,17 @@
 otal)%60,%0A
+%0A
         
@@ -936,16 +936,17 @@
 size%7D%60,%0A
+%0A
         
@@ -965,34 +965,19 @@
 (process
-.memoryUsage().rss
+Mem
  / 10485
@@ -993,32 +993,46 @@
 ed()%7DMB/
-$%7B(os.
+%60 +%0A                 (
 total
-m
+M
 em
-()
  %3E 1000 
@@ -1037,29 +1037,24 @@
 0 ? %60$%7B(
-os.
 total
-m
+M
 em
-()
  / 1000)
@@ -1074,29 +1074,24 @@
 B%60 : %60$%7B
-os.
 total
-m
+M
 em
-()
 .toFixed
@@ -1097,18 +1097,23 @@
 d()%7DMB%60)
-%7D%0A
+ +%0A    
         
@@ -1115,16 +1115,19 @@
         
+  %60
  ($%7B(pro
@@ -1134,43 +1134,23 @@
 cess
-.memoryUsage().rss
+Mem
  / (
-os.
 total
-m
+M
 em
-()
  * 1
@@ -1179,31 +1179,45 @@
 (2)%7D%25), 
-$%7B(os.
+%60 +%0A                 (
 free
-m
+M
 em
-()
  %3E 1024 
@@ -1222,28 +1222,23 @@
 4 ? %60$%7B(
-os.
 free
-m
+M
 em
-()
  / 1024)
@@ -1258,28 +1258,23 @@
 B%60 : %60$%7B
-os.
 free
-m
+M
 em
-()
 .toFixed
@@ -1280,17 +1280,20 @@
 d()%7DMB%60)
-%7D
+ + '
  free on
@@ -1303,18 +1303,11 @@
 rver
-%60, // ewww
+',%0A
 %0A   
@@ -1478,24 +1478,24 @@
 oString());%0A
-
     %7D);%0A%7D;%0A%0A
@@ -1494,16 +1494,168 @@
 %7D);%0A%7D;%0A%0A
+function osutilsWrapper (func) %7B%0A    return (callback) =%3E %7B%0A        func((val) =%3E %7B%0A            return callback(undefined, val);%0A        %7D);%0A    %7D;%0A%7D;%0A%0A
 function

Clean up the mess that was ram + move fn