mirror of
https://github.com/pieartsy/PluralFlux.git
synced 2026-04-17 01:55:27 +10:00
hopefully added parsing for wrapping of proxies (at beginning, around, and end)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import {memberHelper} from "./memberHelper.js";
|
import {memberHelper} from "./memberHelper.js";
|
||||||
|
import {enums} from "../enums.js";
|
||||||
|
|
||||||
const msgh = {};
|
const msgh = {};
|
||||||
|
|
||||||
@@ -33,14 +34,18 @@ msgh.parseCommandArgs = function(content, commandName) {
|
|||||||
* Parses proxy tags and sees if they match the tags of any member belonging to an author.
|
* Parses proxy tags and sees if they match the tags of any member belonging to an author.
|
||||||
*
|
*
|
||||||
* @param {string} authorId - The author of the message.
|
* @param {string} authorId - The author of the message.
|
||||||
|
* @param {Object} attachment - An attachment for the message, if any exists.
|
||||||
* @param {string} content - The full message content.
|
* @param {string} content - The full message content.
|
||||||
* @returns {Object} The proxy message object.
|
* @returns {Object} The proxy message object.
|
||||||
*/
|
*/
|
||||||
msgh.parseProxyTags = async function (authorId, content){
|
msgh.parseProxyTags = async function (authorId, attachment, content){
|
||||||
const members = await memberHelper.getMembersByAuthor(authorId);
|
const members = await memberHelper.getMembersByAuthor(authorId);
|
||||||
|
|
||||||
const proxyMessage = {}
|
const proxyMessage = {}
|
||||||
members.forEach(member => {
|
members.forEach(member => {
|
||||||
if (content.startsWith(member.proxy) && content.length > member.proxy.length) {
|
if (content.length <= member.proxy.length && !attachment) throw new Error(enums.err.NO_MESSAGE_SENT_WITH_PROXY);
|
||||||
|
const splitProxy = member.proxy.split("text");
|
||||||
|
if(content.startsWith(splitProxy[0]) && content.endsWith(splitProxy[1])) {
|
||||||
proxyMessage.proxy = member.proxy;
|
proxyMessage.proxy = member.proxy;
|
||||||
proxyMessage.message = content.slice(member.proxy.length).trim();
|
proxyMessage.message = content.slice(member.proxy.length).trim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ function preventSameNameCollapse(channel, username) {
|
|||||||
*/
|
*/
|
||||||
wh.sendMessageAsMember = async function(client, message, content) {
|
wh.sendMessageAsMember = async function(client, message, content) {
|
||||||
|
|
||||||
const proxyMatch = await messageHelper.parseProxyTags(message.author.id, content);
|
const proxyMatch = await messageHelper.parseProxyTags(message.author.id, message.attachments[0] ?? null, content);
|
||||||
// If the message doesn't match a proxy, just return.
|
// If the message doesn't match a proxy, just return.
|
||||||
if (!proxyMatch.proxy) {
|
if (!proxyMatch.proxy) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user