mirror of
https://github.com/pieartsy/PluralFlux.git
synced 2026-04-14 20:15:28 +10:00
adjusted webhook helper to not query twice for member.
adjusted proxy message to just reply to message w/ attachments with "Attachment sent by" instead of sending error message
This commit is contained in:
@@ -55,15 +55,14 @@ msgh.parseProxyTags = async function (authorId, content, attachmentUrl= null){
|
|||||||
members.filter(member => member.proxy).forEach(member => {
|
members.filter(member => member.proxy).forEach(member => {
|
||||||
const splitProxy = member.proxy.split("text");
|
const splitProxy = member.proxy.split("text");
|
||||||
if(content.startsWith(splitProxy[0]) && content.endsWith(splitProxy[1])) {
|
if(content.startsWith(splitProxy[0]) && content.endsWith(splitProxy[1])) {
|
||||||
if (attachmentUrl) throw new Error(enums.err.ATTACHMENTS_NOT_ALLOWED);
|
proxyMessage.member = member;
|
||||||
proxyMessage.proxy = member.proxy;
|
if (attachmentUrl) return proxyMessage.message = enums.misc.ATTACHMENT_SENT_BY;
|
||||||
|
|
||||||
let escapedPrefix = splitProxy[0].replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
let escapedPrefix = splitProxy[0].replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
let escapedSuffix = splitProxy[1].replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
let escapedSuffix = splitProxy[1].replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
console.log(escapedPrefix, escapedSuffix);
|
|
||||||
escapedPrefix = new RegExp("^" + escapedPrefix);
|
escapedPrefix = new RegExp("^" + escapedPrefix);
|
||||||
escapedSuffix = new RegExp(escapedSuffix + "$")
|
escapedSuffix = new RegExp(escapedSuffix + "$")
|
||||||
proxyMessage.message = content.replace(escapedPrefix, "").replace(escapedSuffix, "");
|
proxyMessage.message = content.replace(escapedPrefix, "").replace(escapedSuffix, "");
|
||||||
console.log(proxyMessage.message);
|
|
||||||
if (proxyMessage.message.length === 0) throw new Error(enums.err.NO_MESSAGE_SENT_WITH_PROXY);
|
if (proxyMessage.message.length === 0) throw new Error(enums.err.NO_MESSAGE_SENT_WITH_PROXY);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -17,17 +17,18 @@ wh.sendMessageAsMember = async function(client, message) {
|
|||||||
const attachmentUrl = message.attachments.size > 0 ? message.attachments.first().url : null;
|
const attachmentUrl = message.attachments.size > 0 ? message.attachments.first().url : null;
|
||||||
const proxyMatch = await messageHelper.parseProxyTags(message.author.id, message.content, attachmentUrl).catch(e =>{throw e});
|
const proxyMatch = await messageHelper.parseProxyTags(message.author.id, message.content, attachmentUrl).catch(e =>{throw e});
|
||||||
// If the message doesn't match a proxy, just return.
|
// If the message doesn't match a proxy, just return.
|
||||||
if (!proxyMatch || !proxyMatch.proxy) {
|
if (!proxyMatch || !proxyMatch.member.proxy) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If the message does match a proxy but is in a guild server
|
// If the message does match a proxy but is not in a guild server (ex: in the Bot's DMs
|
||||||
if (!message.guildId) {
|
if (!message.guildId) {
|
||||||
throw new Error(enums.err.NOT_IN_SERVER);
|
throw new Error(enums.err.NOT_IN_SERVER);
|
||||||
}
|
}
|
||||||
const member = await memberHelper.getMemberByProxy(message.author.id, proxyMatch.proxy);
|
|
||||||
if (member) {
|
if (proxyMatch.message === enums.misc.ATTACHMENT_SENT_BY) {
|
||||||
await replaceMessage(client, message, proxyMatch.message, member).catch(e =>{throw e});
|
return await message.reply(`${enums.misc.ATTACHMENT_SENT_BY} ${proxyMatch.member.displayname}`)
|
||||||
}
|
}
|
||||||
|
await replaceMessage(client, message, proxyMatch.message, proxyMatch.member).catch(e =>{throw e});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user