Refactor
This commit is contained in:
parent
ef0633d2e5
commit
8d863914c1
18
index.js
18
index.js
@ -13,15 +13,9 @@ let count = 0;
|
||||
const shapeGuild = config.shapeGuild;
|
||||
const ALLOWED_CHANNEL_TYPES = ["DM", "GROUP_DM"];
|
||||
|
||||
function isAllowedUser(id) {
|
||||
const ALLOWED_IDS = config.ALLOWED_IDS;
|
||||
if (ALLOWED_IDS.find(string => string == id) || !ALLOWED_IDS.length) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function isDisallowedUser(id) {
|
||||
const DISALLOWED_IDS = config.DISALLOWED_IDS;
|
||||
if (DISALLOWED_IDS.find(string => string == id) || !DISALLOWED_IDS.length) return true;
|
||||
function checkUser(id, list) {
|
||||
if (list.find(string => string == id) || list.length) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -66,7 +60,7 @@ function filterPrompt(string) {
|
||||
}
|
||||
|
||||
async function sendToAI(message) {
|
||||
if (message.author.id == client.user.id && isDisallowedUser(message.author.id)) return;
|
||||
if (message.author.id == client.user.id && checkUser(message.author.id, config.DISALLOWED_IDS)) return;
|
||||
|
||||
if (message.author.id == config.admin && message.content.startsWith("e ")) {
|
||||
eval(message.content.substring(1));
|
||||
@ -76,18 +70,18 @@ async function sendToAI(message) {
|
||||
if (message.content.length >= 1800) return;
|
||||
|
||||
savedMessage = message;
|
||||
client.guilds.cache.get(shapeGuild).channels.cache.get(config.shapeChannel).send(await getMessageContent(message));
|
||||
client.guilds.cache.get(shapeGuild).channels.cache.get(config.shapeChannel).send(await getMessageContent(message)).catch(error => console.error(error));
|
||||
}
|
||||
|
||||
async function processGuildTextMessage(message) {
|
||||
if (message.guild.id != shapeGuild &&
|
||||
(message.mentions.users.get(client.user.id) || isAllowedUser(message.author.id) || (!isAllowedUser && count % 5 == 0)
|
||||
(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.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 (!isAllowedUser(message.author.id)) count++;
|
||||
if (!checkUser(message.author.id, config.ALLOWED_IDS)) count++;
|
||||
}
|
||||
|
||||
client.on("messageCreate", function(message){
|
||||
|
Loading…
Reference in New Issue
Block a user