Initial Emmelia merge

This commit is contained in:
Logan Cusano
2023-05-06 14:56:51 -04:00
parent 6e8af5dbcc
commit f3a4f25f85
44 changed files with 5530 additions and 1115 deletions

115
Server/modules/linkCop.js Normal file
View File

@@ -0,0 +1,115 @@
const { DebugBuilder } = require("../utilities/debugBuilder");
const log = new DebugBuilder("server", "linkCop");
const { linkCopInsults } = require('../extras/linkCopInsults');
const linkRegExp = /(?:http[s]?:\/\/)?(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)/g
// Langvars that can be used in the insults
// Mention the posting user
const mtnUsrRegExp = /\{\%mtn_user\%\}/g
// Reference the original message
const refOgMsgRegExp = /\{\%ref_og_msg\%\}/g
// Reference the channel the original message was posted in
const refOgChannelRegExp = /\{\%ref_og_channel\%\}/g
// Reference the links from the original message
const refLinksRegExp = /\{\%ref_links\%\}/g
const restrictedChannelIds = [
'757379843792044102',
'367396189529833474',
"918029426397184000"
]
const approvedLinksChannel = "767303243285790721";
async function replaceLangVars(messageContent, selectedInsult) {
selectedInsult = String(selectedInsult)
selectedInsult = selectedInsult.replace(mtnUsrRegExp, messageContent.author);
selectedInsult = selectedInsult.replace(refOgMsgRegExp, messageContent.content);
selectedInsult = selectedInsult.replace(refOgChannelRegExp, `<#${messageContent.channelId}>`);
selectedInsult = selectedInsult.replace(refLinksRegExp, Array(messageContent.links).join(", "));
return selectedInsult;
}
exports.linkCop = async (message) => {
if (!restrictedChannelIds.includes(message.channelId)) return;
const client = message.client;
log.DEBUG("Message Content: ", message.content);
log.VERBOSE("Interaction: ", message);
const urls = String(message.content).matchAll(linkRegExp);
if (!urls || urls.length === 0) return;
log.DEBUG("Found URLs: ", urls);
const messageContent = {
'author': message.author,
'content': String(message.content),
'channelId': message.channelId,
'links': urls
}
await message.delete();
var selectedInsult = linkCopInsults[Math.floor(Math.random()*linkCopInsults.length)];
const finalMessage = await replaceLangVars(messageContent, selectedInsult);
log.DEBUG("Final Message: ", finalMessage);
log.VERBOSE("Client: ", client.guilds);
client.channels.get(approvedLinksChannel).send(finalMessage);
}
/* TODO
- Get the message to send, getting an error because client.guilds and .channels doesn't have functions
- Make sure the links are added to the final message
*/
/*
Message {
channelId: '918029426397184000',
guildId: '367396189529833472',
id: '1101346007087845437',
createdTimestamp: 1682651750109,
type: 0,
system: false,
content: '<@943742040255115304> asd',
author: User {
id: '301507932678520833',
bot: false,
system: false,
flags: UserFlagsBitField { bitfield: 0 },
username: 'Logan',
discriminator: '3331',
avatar: null,
banner: undefined,
accentColor: undefined
},
pinned: false,
tts: false,
nonce: '1101346006672343040',
embeds: [],
components: [],
attachments: Collection(0) [Map] {},
stickers: Collection(0) [Map] {},
position: null,
editedTimestamp: null,
reactions: ReactionManager { message: [Circular *1] },
mentions: MessageMentions {
everyone: false,
users: Collection(1) [Map] { '943742040255115304' => [ClientUser] },
roles: Collection(0) [Map] {},
_members: null,
_channels: null,
_parsedUsers: null,
crosspostedChannels: Collection(0) [Map] {},
repliedUser: null
},
webhookId: null,
groupActivityApplication: null,
applicationId: null,
activity: null,
flags: MessageFlagsBitField { bitfield: 0 },
reference: null,
interaction: null
} */