From 5e0fe8aa0ce6b91fad31fe3eff41b66314041892 Mon Sep 17 00:00:00 2001 From: bee! Date: Sun, 22 Oct 2023 16:31:10 -0700 Subject: [PATCH] docker: add dockerfile, format log --- .dockerignore | 2 ++ Dockerfile | 16 ++++++++++++++++ dataManager.js | 36 +++++++++++++++++++++++------------- 3 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5171c54 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1ece624 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM node:18 + +WORKDIR /usr/src/app + +COPY package*.json ./ +RUN npm install + +# If you are building your code for production +# RUN npm ci --omit=dev + +# Bundle app source +COPY . . + +#EXPOSE 8080 + +CMD [ "node", "index.js" ] \ No newline at end of file diff --git a/dataManager.js b/dataManager.js index 209cd5e..ec1cc5f 100644 --- a/dataManager.js +++ b/dataManager.js @@ -52,7 +52,7 @@ async function findPrimary() { if (fronter.content.customStatus) { if (fronter.content.customStatus.toLowerCase().includes("primary")) { let member = await system.getMemberById(fronter.content.member) - resolve(member.content.pkId) + resolve({ name: member.content.name, pkId: member.content.pkId }) found = true } } @@ -112,21 +112,30 @@ async function swapFront() { // start forming new front list let newFront = [] + let frontNames = [] for (member of front) { let m = await system.getMemberById(member.content.member) if (m.content.pkId) { // fronting member pkID has been found newFront.push(m.content.pkId) + frontNames.push(m.content.name) } } // shift primary fronter to first in list let primary = await findPrimary() - if (primary) { - if (newFront.indexOf(primary) > 0) { - newFront.splice(newFront.indexOf(primary), 1) - newFront.unshift(primary) + let primaryPK = primary.pkId + let primaryName = primary.name + if (primaryPK) { + if (newFront.indexOf(primaryPK) > 0) { + newFront.splice(newFront.indexOf(primaryPK), 1) + newFront.unshift(primaryPK) + } + + if (frontNames.indexOf(primaryName) > 0) { + frontNames.splice(frontNames.indexOf(primaryName), 1) + frontNames.unshift(primaryName) } } @@ -146,7 +155,8 @@ async function swapFront() { await swapFront() return } else { - console.log('::SimplyWS:: SP\'s front has been published to PK.') + let formattedNames = frontNames.toString().replace(',',', ') + console.log(`::SimplyWS:: SimplyPlural -> PluralKit: ${formattedNames}`) } }) .catch(async err => { @@ -180,7 +190,7 @@ async function insertFront(member) { } // find the "primary" fronter to move to the first element in the list - let primary = await findPrimary() + let primary = await findPrimary().pkId if (primary) { if (fronters.indexOf(primary) > 0) { fronters.splice(fronters.indexOf(primary), 1) @@ -241,11 +251,11 @@ async function removeFront(member) { } // find the "primary" fronter to move to the first element in the list - let p = await findPrimary() - if (p) { - if (fronters.indexOf(p) > 0) { - fronters.splice(fronters.indexOf(p), 1) - fronters.unshift(p) + let primary = await findPrimary().pkId + if (primary) { + if (fronters.indexOf(primary) > 0) { + fronters.splice(fronters.indexOf(primary), 1) + fronters.unshift(primary) } } @@ -285,7 +295,7 @@ async function removeFront(member) { async function updateCustomStatus(member) { // find the "primary" fronter to move to the first element in the list let fronters = await getPKFronters() - let primary = await findPrimary() + let primary = await findPrimary().pkId if (primary && fronters.length > 1 && (member.content.pkId == primary)) { if (fronters.indexOf(primary) >= 0) { fronters.splice(fronters.indexOf(primary), 1)