Refactor
This commit is contained in:
parent
ef0633d2e5
commit
8d863914c1
20
index.js
20
index.js
@ -13,15 +13,9 @@ let count = 0;
|
|||||||
const shapeGuild = config.shapeGuild;
|
const shapeGuild = config.shapeGuild;
|
||||||
const ALLOWED_CHANNEL_TYPES = ["DM", "GROUP_DM"];
|
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) {
|
function checkUser(id, list) {
|
||||||
const DISALLOWED_IDS = config.DISALLOWED_IDS;
|
if (list.find(string => string == id) || list.length) return true;
|
||||||
if (DISALLOWED_IDS.find(string => string == id) || !DISALLOWED_IDS.length) return true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,28 +60,28 @@ function filterPrompt(string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function sendToAI(message) {
|
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 ")) {
|
if (message.author.id == config.admin && message.content.startsWith("e ")) {
|
||||||
eval(message.content.substring(1));
|
eval(message.content.substring(1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.content.length >= 1800) return;
|
if (message.content.length >= 1800) return;
|
||||||
|
|
||||||
savedMessage = message;
|
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) {
|
async function processGuildTextMessage(message) {
|
||||||
if (message.guild.id != shapeGuild &&
|
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)))
|
|| (message.reference && message.channel.messages.cache.get(message.reference.messageId).author.id == client.user.id)))
|
||||||
sendToAI(message);
|
sendToAI(message);
|
||||||
else if (message.guild.id == shapeGuild && message.author.bot && savedMessage) {
|
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 => {});
|
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){
|
client.on("messageCreate", function(message){
|
||||||
|
Loading…
Reference in New Issue
Block a user