module.exports = {} const change = 62135659200; // Subtract a year, whoops module.exports.convertSLTimestamp = (timestamp) => { //change = 62167219200; // 1 year behind whoops ourTs = Number(BigInt(timestamp) / 10000000n); return new Date((ourTs - change) * 1000) } module.exports.toSLTimestamp = (timestamp) => { return String(((Number(timestamp) / 1000) + change) * 10000000) } module.exports.slToJSON = (slDataLine) => { raw = slDataLine.split(";"); data = { banned_username: raw[0], banned_id: raw[1], expires: module.exports.convertSLTimestamp(raw[2]), reason: raw[3], moderator: raw[4], banned_timestamp: module.exports.convertSLTimestamp(raw[5]) } return data; } module.exports.makeBansTable = (newContents) => { tmp = {} lines = newContents.split("\n"); lines.forEach(line => { if (line === "") return; data = module.exports.slToJSON(line) tmp[data.banned_id] = data }) return tmp } module.exports.diff = (oldData, newData) => { let added = {}; let removed = {}; // Find added keys (in newData but not in oldData) Object.keys(newData).forEach(key => { if (!oldData.hasOwnProperty(key)) { added[key] = newData[key]; } }); // Find removed keys (in oldData but not in newData) Object.keys(oldData).forEach(key => { if (!newData.hasOwnProperty(key)) { removed[key] = oldData[key]; } }); // Construct the result object with added and removed changes let result = { added: added, removed: removed }; return result; } return module.exports