Fix and refactor

This commit is contained in:
pixtaded 2024-09-02 15:01:06 +03:00
parent 8d863914c1
commit f5385847a7

View File

@ -14,8 +14,8 @@ const shapeGuild = config.shapeGuild;
const ALLOWED_CHANNEL_TYPES = ["DM", "GROUP_DM"];
function checkUser(id, list) {
if (list.find(string => string == id) || list.length) return true;
function checkInList(element, list) {
if (list.find(string => string == element)) return true;
return false;
}
@ -60,14 +60,14 @@ function filterPrompt(string) {
}
async function sendToAI(message) {
if (message.author.id == client.user.id && checkUser(message.author.id, config.DISALLOWED_IDS)) return;
if (message.author.id == client.user.id || checkInList(message.author.id, config.DISALLOWED_IDS)) return;
if (message.author.id == config.admin && message.content.startsWith("e ")) {
eval(message.content.substring(1));
return;
}
if (message.content.length >= 1800) return;
if (message.content.length >= 2000) return;
savedMessage = message;
client.guilds.cache.get(shapeGuild).channels.cache.get(config.shapeChannel).send(await getMessageContent(message)).catch(error => console.error(error));
@ -75,19 +75,19 @@ async function sendToAI(message) {
async function processGuildTextMessage(message) {
if (message.guild.id != shapeGuild &&
(message.mentions.users.get(client.user.id) || checkUser(message.author.id, config.ALLOWED_IDS) || (!checkUser(message.author.id, config.ALLOWED_IDS) && count % 5 == 0)
((message.mentions.users.get(client.user.id)) || checkInList(message.author.id, config.ALLOWED_IDS) || (!checkInList(message.author.id, config.ALLOWED_IDS) && count % 5 == 0)
|| (message.reference && message.channel.messages.cache.get(message.reference.messageId).author.id == client.user.id)))
sendToAI(message);
else if (message.guild.id == shapeGuild && message.author.bot && savedMessage) {
Promise.all([savedMessage.channel.sendTyping(), savedMessage.channel.send("<@" + savedMessage.author.id + "> " + message.content)]).catch(error => {});
}
if (!checkUser(message.author.id, config.ALLOWED_IDS)) count++;
if (!checkInList(message.author.id, config.ALLOWED_IDS)) count++;
}
client.on("messageCreate", function(message){
try {
if (message.channel.type == "GUILD_TEXT") processGuildTextMessage(message);
else if (ALLOWED_CHANNEL_TYPES.find(type => type == message.channel.type)) sendToAI(message);
else if (checkInList(message.channel.type, ALLOWED_CHANNEL_TYPES)) sendToAI(message);
} catch(error) {
console.error(error);
}