updated package.json, moved stuff into src folder

This commit is contained in:
Aster Fialla
2026-02-14 21:11:15 -05:00
committed by pieartsy
parent 83a2497ff4
commit 7ef2adc689
4 changed files with 1 additions and 1 deletions

65
src/db.js Normal file
View File

@@ -0,0 +1,65 @@
import {DataTypes, Sequelize} from 'sequelize';
const password = process.env.POSTGRES_PASSWORD;
if (!password) {
console.error("Missing POSTGRES_PWD environment variable.");
process.exit(1);
}
const database = {};
const sequelize = new Sequelize('postgres', 'postgres', password, {
host: 'localhost',
dialect: 'postgres'
});
database.sequelize = sequelize;
database.Sequelize = Sequelize;
database.members = sequelize.define('Member', {
userid: {
type: DataTypes.STRING,
allowNull: false,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
displayname: {
type: DataTypes.STRING,
},
propic: {
type: DataTypes.STRING,
},
proxy: {
type: DataTypes.STRING,
}
});
/**
* Checks Sequelize database connection.
*/
database.check_connection = async function() {
await sequelize.authenticate().then(async (result) => {
console.log('Connection has been established successfully.');
await syncModels();
}).catch(err => {
console.error('Unable to connect to the database:', err);
process.exit(1);
});
}
/**
* Syncs Sequelize models.
*/
async function syncModels() {
await sequelize.sync().then(() => {
console.log('Models synced successfully.');
}).catch((err) => {
console.error('Syncing models did not work', err);
process.exit(1);
});
}
export const db = database;

37
src/enums.js Normal file
View File

@@ -0,0 +1,37 @@
const helperEnums = {};
helperEnums.err = {
NO_MEMBER: "No such member was found.",
NO_NAME_PROVIDED: "No member name was provided for",
NO_VALUE: "has not been set for this member. Please provide a value.",
ADD_ERROR: "Error adding member.",
MEMBER_EXISTS: "A member with that name already exists. Please pick a unique name.",
USER_NO_MEMBERS: "You have no members created.",
DISPLAY_NAME_TOO_LONG: "The display name is too long. Please limit it to 32 characters or less.",
PROXY_EXISTS: "A duplicate proxy already exists for one of your members. Please pick a new one, or change the old one first.",
NO_SUCH_COMMAND: "No such command exists.",
PROPIC_FAILS_REQUIREMENTS: "Profile picture must be in JPG or PNG format.",
PROPIC_CANNOT_LOAD: "Profile picture could not be loaded from URL.",
NO_WEBHOOKS_ALLOWED: "Channel does not support webhooks.",
NOT_IN_SERVER: "You can only proxy in a server.",
NO_MESSAGE_SENT_WITH_PROXY: 'Proxied message has no content.',
NO_TEXT_FOR_PROXY: "You need the word 'text' for the bot to detect proxy tags with.\nCorrect usage examples: `pf;member jane proxy J:text`, `pf;member jane [text]`",
NO_PROXY_WRAPPER: "You need at least one proxy tag surrounding 'text', either before or after.\nCorrect usage examples: `pf;member jane proxy J:text`, `pf;member jane [text]`",
NOT_JSON: "Please attach a valid JSON file."
}
helperEnums.help = {
SHORT_DESC_HELP: "Lists available commands.",
SHORT_DESC_MEMBER: "Commands and sub-commands related to proxy members.",
SHORT_DESC_PLURALFLUX: "PluralFlux is a proxybot akin to PluralKit and Tupperbot, but for Fluxer. All commands are prefixed by `pf;`. Type `pf;help` for info on the bot itself.",
PLURALFLUX: "PluralFlux is a proxybot akin to PluralKit and Tupperbot, but for Fluxer. All commands are prefixed by `pf;`. Add ` --help` to the end of a command to find out more about it, or just send it without arguments.",
MEMBER: "Accesses the sub-commands related to editing proxy members. The available subcommands are `listall`, `add`, `remove`, `displayname`, `proxy`, and `propic`. Add ` --help` to the end of a subcommand to find out more about it, or just send it without arguments.",
ADD: "Creates a new member to proxy with, for example: `pf;member jane`. The member name should ideally be short so you can write other commands with it easily. \n\nYou can optionally add a display name after the member name, for example: `pf;member new jane \"Jane Doe | ze/hir\"`. If it has spaces, put it in __double quotes__. The length limit is 32 characters.",
REMOVE: "Removes a member based on their name, for example: `pf;member remove jane`.",
NAME: "Updates the name for a specific member based on their current name, for ex: `pf;member jane name jane`. The member name should ideally be short so you can write other commands with it easily.",
DISPLAY_NAME: "Updates the display name for a specific member based on their name, for example: `pf;member jane \"Jane Doe | ze/hir\"`.This can be up to 32 characters long. If it has spaces, put it in __double quotes__.",
PROXY: "Updates the proxy tag for a specific member based on their name. The proxy must be formatted with the tags surrounding the word 'text', for example: `pf;member jane proxy Jane:text` or `pf;member amal proxy [text]` This is so the bot can detect what the proxy tags are.",
PROPIC: "Updates the profile picture for the member. Must be in JPG or PNG format. The two options are:\n1. Pass in a direct remote image URL, for example: `pf;member jane propic <https://cdn.pixabay.com/photo/2020/05/02/02/54/animal-5119676_1280.jpg>`. You can upload images on sites like <https://imgbb.com/>.\n2. Upload an attachment directly.\n\n**NOTE:** Fluxer does not save your attachments forever, so option #1 is recommended.",
}
export const enums = helperEnums;

29
src/import.js Normal file
View File

@@ -0,0 +1,29 @@
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} attachment - The attached JSON url.
* @returns {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(async(pkMember) => {
const proxy = `${pkMember.proxy_tags.prefix}text${pkMember.proxy_tags.suffix}`;
await memberHelper.addFullMember(authorId, pkMember.name, pkMember.display_name, proxy, avatar_url);
})
return "All members imported.";
}
catch {
throw new Error(enums.err.NOT_JSON);
}
}
export const importHelper = ih;