diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 5171c54..0000000 --- a/.dockerignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -npm-debug.log \ No newline at end of file diff --git a/.env_example b/.env_example index ad0e951..e8c8531 100644 --- a/.env_example +++ b/.env_example @@ -1,13 +1,11 @@ # Compatiplural -url_override="https://api.apparyllis.com" +url_override="https://v2.apparyllis.com" api_version="v1" -socket="wss://api.apparyllis.com/v1/socket" +socket="wss://v2.apparyllis.com/v1/socket" pk_url="https://api.pluralkit.me/v2" token="SIMPLYPLURAL_TOKEN" userId="abcd1234" pk_token= "PLURALKIT_TOKEN" heartbeat=4500000 max_workers=1 -silence_connections=true -full_swap=false -primary_tag="primary " +silence_connections=true \ No newline at end of file diff --git a/.gitignore b/.gitignore index 33014e4..0befe13 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,3 @@ config.json package-lock.json .env .vercel -docker_build.bat -docker_run.bat diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 1ece624..0000000 --- a/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -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/README.md b/README.md index 9a8cd91..d52522d 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ This project already has a Procfile set up, so it's super easy to get started. O These can be set either in the .env file, in terminal, or in the config vars section of Heroku. | Setting | Default | Description | | ---------| ------- | ------------------ | -| url_override | https://api.apparyllis.com | The base URL for all SimplyPlural API requests. Unless you are running your own fork of Simply Plural, you shouldn't change this. | +| url_override | https://v2.apparyllis.com | The base URL for all SimplyPlural API requests. Unless you are running your own fork of Simply Plural, you shouldn't change this. | | api_version | v1 | The target SimplyPlural API version. Unless you are running your own fork of Simply Plural, you shouldn't change this. | -| socket | wss://api.apparyllis.com/v1/socket | The socket URL for SimplyPlural. Unless you are running your own fork of Simply Plural, you shouldn't change this. | +| socket | wss://v2.apparyllis.com/v1/socket | The socket URL for SimplyPlural. Unless you are running your own fork of Simply Plural, you shouldn't change this. | | pk_url | https://api.pluralkit.me/v2 | The base URL for all PluralKit API requests. Unless you are running your own fork of PluralKit, you shouldn't change this. | | token | token_here | Your SimplyPlural account token. As of now, the only permission necessary is the Read permission. | | userId | user_id | Your SimplyPlural account/system ID. You can find it in account info near the bottom. | @@ -19,4 +19,3 @@ These can be set either in the .env file, in terminal, or in the config vars sec | heartbeat | 4500000 | The time in miliseconds before the websocket client reconnects to the websocket server. | | max_workers | 1 | Max number of workers for processing enqueued tasks. This probably shouldn't be changed. | | silence_connections | true | Whether or not to silence the websocket connection and authentication messages. | -| full_swap | false | Determines whether to completely overwrite PluralKit's front with SimplyPlural's. No individual changes. | diff --git a/dataManager.js b/dataManager.js index 64f13c4..5e844b5 100644 --- a/dataManager.js +++ b/dataManager.js @@ -50,9 +50,9 @@ async function findPrimary() { return new Promise(async (resolve) => { await Util.asyncForEach(fronters, async (fronter) => { if (fronter.content.customStatus) { - if (fronter.content.customStatus.toLowerCase().includes(Config.primary_tag)) { + if (fronter.content.customStatus.toLowerCase().includes("primary")) { let member = await system.getMemberById(fronter.content.member) - resolve({ name: member.content.name, pkId: member.content.pkId }) + resolve(member.content.pkId) found = true } } @@ -106,82 +106,6 @@ async function determineAction(eventData, frontData = []) { return action } -async function swapFront() { - let system = new System(Config) - let front = await system.getFronters() - - // start forming new front list - let newFront = [] - let frontNames = [] - for (member of front) { - let m = await system.getMemberById(member.content.member) - - if (m.content && m.content.pkId) { - // fronting member pkID has been found - newFront.push(m.content.pkId) - frontNames.push(m.content.name) - } - else { - console.warn('::SimplyWS:: System member not found, this may be a custom front which is unsupported.') - } - } - - // shift primary fronter to first in list - let primary = await findPrimary() - 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) - } - } - - // post the new switch - let url = `${pkUrl}/systems/@me/switches` - await axios.post(url, JSON.stringify({ "members": newFront }), { - headers: pkHeader - }) - .then(async (res) => { - // check if current front equals the new front - let front = await getPKFronters() - var equal = (front.length == newFront.length) && front.every(function(element, index) { - return element === newFront[index]; - }) - if (!equal) { - console.log('::SimplyWS:: Failed to swap front: ' + newFront) - await swapFront() - return - } else { - let formattedNames = frontNames.toString().replace(',',', ') - console.log(`::SimplyWS:: SimplyPlural -> PluralKit: ${formattedNames}`) - } - }) - .catch(async err => { - let status = err.status || err.toJSON().status - if (status == 400) { - // if the fronter is already in the front, do nothing - return - } - else if (status == 404) { - return - } - else if (status == 429) { - // Too many requests - console.warn("::SimplyWS:: Too many requests, waiting to try again.") - setTimeout(async function () { - await swapFront() - }, 1000) - return - } - }) -} - async function insertFront(member) { // get current fronters and add new fronter let fronters = await getPKFronters() @@ -193,7 +117,7 @@ async function insertFront(member) { } // find the "primary" fronter to move to the first element in the list - let primary = await findPrimary().pkId + let primary = await findPrimary() if (primary) { if (fronters.indexOf(primary) > 0) { fronters.splice(fronters.indexOf(primary), 1) @@ -254,11 +178,11 @@ async function removeFront(member) { } // find the "primary" fronter to move to the first element in the list - let primary = await findPrimary().pkId - if (primary) { - if (fronters.indexOf(primary) > 0) { - fronters.splice(fronters.indexOf(primary), 1) - fronters.unshift(primary) + let p = await findPrimary() + if (p) { + if (fronters.indexOf(p) > 0) { + fronters.splice(fronters.indexOf(p), 1) + fronters.unshift(p) } } @@ -298,7 +222,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().pkId + let primary = await findPrimary() if (primary && fronters.length > 1 && (member.content.pkId == primary)) { if (fronters.indexOf(primary) >= 0) { fronters.splice(fronters.indexOf(primary), 1) @@ -351,9 +275,8 @@ module.exports = { getPKFronters, findPrimary, determineAction, - swapFront, insertFront, removeFront, updateCustomStatus, calculateDiff -} +} \ No newline at end of file diff --git a/index.js b/index.js index 9c82e08..ea23807 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ dotenv.config() const { Config, System } = require('simplyapi') const { Util } = require('simplyapi') -const { initializeCache, determineAction, swapFront, insertFront, removeFront, updateCustomStatus } = require('./dataManager') +const { initializeCache, determineAction, insertFront, removeFront, updateCustomStatus } = require('./dataManager') const { isMainThread, @@ -95,12 +95,8 @@ update = async (data) => { await Util.asyncForEach(data.results, async (o) => { let system = new System(Config) let member = await system.getMemberById(o.content.member) - let swap = Config.full_swap // insert - if (swap) { - swapFront() - } - else if (o.operationType == "insert") { + if (o.operationType == "insert") { insertFront(member) } else {