Skip to content

Commit

Permalink
AWESOM-O's packing!
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon1320 committed Oct 13, 2018
1 parent b600ad8 commit 9eb20d8
Show file tree
Hide file tree
Showing 13 changed files with 473 additions and 435 deletions.
13 changes: 11 additions & 2 deletions src/bot/commands/levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ const trophies = [];

const getLevelData = xp => {

if (xp === 0) {

return {

level: 0,
progress: 0
};
}

const levels = [0, 1, 250, 400, 550, 700, 850, 1000, 1200, 1400, 1600, 1800, 2000, 2250, 2500, 2750, 3000, 3300, 3600, 4000, 4500];

let count = 0;
Expand Down Expand Up @@ -216,7 +225,7 @@ const levels = new Command({
let changed = false;
let modifiedAbout = users[0].bio;

const testHeight = getTextHeight(fontAbout, changed === true ? `${modifiedAbout}...` : modifiedAbout, 360);
//const testHeight = getTextHeight(fontAbout, changed === true ? `${modifiedAbout}...` : modifiedAbout, 360);

while (getTextHeight(fontAbout, changed === true ? `${modifiedAbout}...` : modifiedAbout, 360) > 150) {

Expand Down Expand Up @@ -280,7 +289,7 @@ const levels = new Command({
})
.catch(error => {

message.reply(`error fetching xp teehee: ${error}`);
message.reply(`error sending profile: ${error}`);
});
},

Expand Down
2 changes: 1 addition & 1 deletion src/bot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const schemas = require("../db");
const Sandbox = require("./sandbox");

const botLogger = new Logger();
const botSandbox = new Sandbox({}, 2000);
const botSandbox = new Sandbox({ Promise: null }, 2000);

const isFile = fp => fs.lstatSync(fp).isFile();
const getFilePathsInDir = fp => fs.readdirSync(fp).map(name => path.join(fp, name)).filter(isFile);
Expand Down
13 changes: 13 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,19 @@ Promise.all(promises).then(() => {

//

//
process.on('uncaughtException', function (exception) {
console.error(exception); // to see your exception details in the console
// if you are on production, maybe you can send the exception details to your
// email as well ?
});

process.on('unhandledRejection', (reason, p) => {
console.error("Unhandled Rejection at: Promise ", p, " reason: ", reason);
// application specific logging, throwing an error, or other logic here
});
//

// do stuff
try {

Expand Down
2 changes: 1 addition & 1 deletion src/web/routes/api/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ router.route("/:object_id").get(authUser, (req, res) => {
return res.json({ status: 404 });
}

if (doc.author_id !== eq.user.discord_id && req.user.admin === false) {
if (doc.author_id !== req.user.discord_id && req.user.admin === false) {

return res.json({ status: 403 });
}
Expand Down
90 changes: 88 additions & 2 deletions src/web/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ try {
}

const client = new discord.Client();
client.login(config.discord_token);
const hasLoggedIn = client.login(config.discord_token);

router.use("/api/v3", api);
router.get("/api/v3/uptime", (req, res) => {
Expand All @@ -60,6 +60,92 @@ router.get("/api/v3/uptime", (req, res) => {
});
});

const statsCacheTime = 30000;
const cachedStats = {

expire: Date.now(),
stats: null
};

router.get("/api/v3/stats", async (req, res) => {

// total servers
// total members + online members
// commands used
// marketplace commands
// latest tweet
// status + ping
// latest update

await hasLoggedIn;

if (cachedStats.expire < Date.now()) {

cachedStats.stats = {};

const promises = [];

// total servers
cachedStats.stats.servers = client.guilds.size;

// online + total members
cachedStats.stats.members = {};
cachedStats.stats.members.online = client.guilds.map(g => g.members.array()).reduce((a, c) => a = a.concat(c)).filter(m => m.presence.status === "online").length;
cachedStats.stats.members.total = client.guilds.map(g => g.memberCount).reduce((a, c) => a + c);

// script uses
promises.push(schemas.ScriptSchema.aggregate([{
$group: {
_id: {},
total: {
$sum: "$use_count"
}
}
}]).then(uses => {

cachedStats.stats.script_uses = uses[0].total;
}));

// total scripts
promises.push(schemas.ScriptSchema.count().then(count => cachedStats.stats.total_scripts = count));

// latest tweet
cachedStats.stats.latest_tweet = {};
cachedStats.stats.latest_tweet.text = "latest tweet text";
cachedStats.stats.latest_tweet.date = "latest tweet date";

// status + ping
promises.push(axios({
method: "post",
url: "https://api.uptimerobot.com/v2/getMonitors",
headers: {
"Content-Type": "application/json"
},
data: {
"api_key": config.uptime_key,
"all_time_uptime_ratio": "1",
"response_times": "1",
"response_times_limit": "1"
}
}).then(api_res => {

cachedStats.stats.status = {};
cachedStats.stats.status.status = api_res.data.monitors[0].status === 2 ? "OK" : "ERROR";
cachedStats.stats.status.ping = api_res.data.monitors[0].response_times[0].value;
cachedStats.stats.status.uptime = api_res.data.monitors[0].all_time_uptime_ratio;
}));

// latest update
cachedStats.stats.latest_update = "latest update text";

await Promise.all(promises);

cachedStats.expire = Date.now() + statsCacheTime;
}

return res.json({ stats: cachedStats.stats });
});

router.get("/api/v3/patrons", (req, res) => {

// username
Expand Down Expand Up @@ -136,7 +222,7 @@ router.get("/api/v3/sloc", (req, res) => {
router.get("/dashboard/profiles/:discord_id", authUser, async (req, res) => {

res.render("dashboard/profile")
});
});

router.get("/logout", async (req, res) => {

Expand Down
Binary file added src/web/static/img/logo_red_grey.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/web/static/img/mackey.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/web/static/img/servers_ico.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9eb20d8

Please sign in to comment.