mirror of
https://github.com/pieartsy/PluralFlux.git
synced 2026-04-16 17:45:28 +10:00
wip import
This commit is contained in:
29
import.js
Normal file
29
import.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import {db} from './sequelize.js'
|
||||||
|
import {enums} from "./enums.js";
|
||||||
|
import {memberHelper} from "./helpers/memberHelper.js";
|
||||||
|
|
||||||
|
const ih = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to import from Pluralkit.
|
||||||
|
*
|
||||||
|
* @param {string} authorId - The author of the message
|
||||||
|
* @param {string[]} args - The message arguments
|
||||||
|
* @returns {Promise<string>} A successful addition.
|
||||||
|
* @throws {Error} When the member exists, or creating a member doesn't work.
|
||||||
|
*/
|
||||||
|
ih.pluralKitImport = function (authorId, attachment) {
|
||||||
|
try {
|
||||||
|
const pkData = JSON.parse(attachment);
|
||||||
|
const pkMembers = pkData.members;
|
||||||
|
pkMembers.forEach((pkMember) => {
|
||||||
|
const proxy = `${pkMember.proxy_tags.prefix}text${pkMember.proxy_tags.suffix}`;
|
||||||
|
memberHelper.addFullMember(authorId, pkMember.name, pkMember.display_name, proxy, avatar_url);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
throw new Error(enums.err.NOT_JSON);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const importHelper = ih;
|
||||||
Reference in New Issue
Block a user