Skip to content
This repository was archived by the owner on Nov 24, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "Pokémon Showdown Bot",
"main": "app.js",
"dependencies": {
"moment": "^2.17.1",
"mysql": "^2.13.0",
"node-static": "^0.7.9",
"sqlite3": "^3.1.8",
Expand Down
3 changes: 1 addition & 2 deletions plugins/seen.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ if (!Config.mysql) {
});
}

const moment = require('moment');
const uuid = require('uuid/v4');

let lastUpdated = {};
Expand Down Expand Up @@ -125,7 +124,7 @@ exports.commands = {
} else {
lastSeen(targetid, data => {
if (!data) return this.sendReply(Tools.sanitize(target) + " has never been seen before.");
return this.sendReply(Tools.sanitize(data.name) + " was last seen " + data.action + (data.action !== "joining" && data.action !== "leaving" ? " in " : " ") + " **" + data.room + "** on **" + data.server + "** " + moment(data.date).fromNow());
return this.sendReply(Tools.sanitize(data.name) + " was last seen " + data.action + (data.action !== "joining" && data.action !== "leaving" ? " in " : " ") + " **" + data.room + "** on **" + data.server + "** " + Tools.toDurationString((Date.now() - data.date), {precision: true}) + " ago");
});
}
},
Expand Down
11 changes: 9 additions & 2 deletions tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ let regdateCache = {};
try {
regdateCache = JSON.parse(fs.readFileSync('config/regdate.json', 'utf8'));
} catch (e) {}

module.exports = {
sanitize: function (message) {
if (message.charAt(0) === '/') message = '/' + message;
Expand Down Expand Up @@ -73,13 +72,21 @@ module.exports = {
// https://github.com/tc39/ecma402/issues/47
const date = new Date(+number);
const parts = [date.getUTCFullYear() - 1970, date.getUTCMonth(), date.getUTCDate() - 1, date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds()];
const roundingBoundaries = [6, 15, 12, 30, 30];
const unitNames = ["second", "minute", "hour", "day", "month", "year"];
const positiveIndex = parts.findIndex(elem => elem > 0);
const precision = (options && options.precision ? options.precision : parts.length);
if (options && options.hhmmss) {
let string = parts.slice(positiveIndex).map(value => value < 10 ? "0" + value : "" + value).join(":");
return string.length === 2 ? "00:" + string : string;
}
return parts.slice(positiveIndex).reverse().map((value, index) => value ? value + " " + unitNames[index] + (value > 1 ? "s" : "") : "").reverse().join(" ").trim();
// round least significant displayed unit
if (positiveIndex + precision < parts.length && precision > 0 && positiveIndex >= 0) {
if (parts[positiveIndex + precision] >= roundingBoundaries[positiveIndex + precision - 1]) {
parts[positiveIndex + precision - 1]++;
}
}
return parts.slice(positiveIndex).reverse().map((value, index) => value ? value + " " + unitNames[index] + (value > 1 ? "s" : "") : "").reverse().slice(0, precision).join(" ").trim();
},
// uploadToHastebin function by TalkTakesTime (https://github.com/TalkTakesTime/Pokemon-Showdown-Bot)
uploadToHastebin: function (toUpload, callback) {
Expand Down