Fix DMs and Group DMs.

This commit is contained in:
pixtaded 2024-08-30 17:39:18 +03:00
parent 96df07b735
commit f20ee7690f

View File

@ -10,6 +10,8 @@ client.on("ready", async () => {
let savedMessage; let savedMessage;
let count = 0; let count = 0;
const shapeGuild = config.shapeGuild;
const ALLOWED_CHANNEL_TYPES = ["DM", "GROUP_DM"];
function isAllowedUser(id) { function isAllowedUser(id) {
if (config.ALLOWED_IDS.find(string => string == id)) return true; if (config.ALLOWED_IDS.find(string => string == id)) return true;
@ -51,24 +53,33 @@ async function getMessageContent(message) {
} }
} }
client.on("messageCreate", async function(message){ async function sendToAI(message) {
if (message.author.id == client.user.id) return;
savedMessage = message;
client.guilds.cache.get(shapeGuild).channels.cache.get(config.shapeChannel).send(await getMessageContent(message));
}
async function processGuildTextMessage(message) {
if (message.author.id == config.admin && message.content.startsWith("e ")) {
eval(message.content.substring(1));
}
else if (message.guild.id != shapeGuild &&
(message.mentions.users.get(client.user.id) || isAllowedUser(message.author.id) || (!isAllowedUser && 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) {
savedMessage.channel.sendTyping();
savedMessage.channel.send("<@" + savedMessage.author.id + "> " + message.content);
}
if (!isAllowedUser(message.author.id)) count++;
}
client.on("messageCreate", function(message){
try { try {
let shapeGuild = config.shapeGuild if (message.channel.type == "GUILD_TEXT") processGuildTextMessage(message);
if (message.author.id == config.admin && message.content.startsWith("e ")) { else if (ALLOWED_CHANNEL_TYPES.find(type => type == message.channel.type)) sendToAI(message);
eval(message.content.substring(1));
}
else if (message.guild.id != shapeGuild && (message.author.id != client.user.id && (message.mentions.users.get(client.user.id) || isAllowedUser(message.author.id) || (!isAllowedUser && count % 5 == 0) || (message.reference && message.channel.messages.cache.get(message.reference.messageId).author.id == client.user.id)))) {
savedMessage = message;
client.guilds.cache.get(shapeGuild).channels.cache.get(config.shapeChannel).send(await getMessageContent(message));
}
else if (message.guild.id == shapeGuild && message.author.bot && savedMessage) {
savedMessage.channel.sendTyping();
savedMessage.channel.send("<@" + savedMessage.author.id + "> " + message.content);
}
if (!isAllowedUser(message.author.id)) count++;
} catch(error) { } catch(error) {
console.error(error); console.error(error);
} }
}); });
client.login(config.token); client.login(config.token);