clean up: refactor by splitting into functions

This commit is contained in:
Baipyrus 2024-02-05 03:10:21 +01:00
parent 42293efb68
commit 531b07e304

View File

@ -50,6 +50,27 @@ const registerSelfRoles = async (interaction) => {
return response; return response;
}; };
const saveMessageData = async (id, role, emoji) => {
// Try finding existing entry
const rep = await RoleEmojiPair.findOne({
where: {
[Op.or]: [
{
message: id,
role: role.id
}, {
message: id,
emoji
}
]
}
});
if (rep !== null) throw new Error(`Failed to fetch RoleEmojiPair entry with data {message:${id},role:${role.id},emoji:${emoji}}!`);
// Create database entry for pair
await RoleEmojiPair.create({ message: id, role: role.id, emoji });
};
const addSelfRoles = async (interaction) => { const addSelfRoles = async (interaction) => {
const { options, channel } = interaction; const { options, channel } = interaction;
const id = options.getString('id'); const id = options.getString('id');
@ -66,24 +87,7 @@ const addSelfRoles = async (interaction) => {
.replace(/:.*?:/, ':_:'); .replace(/:.*?:/, ':_:');
step = 'save data from'; step = 'save data from';
// Try finding existing entry await saveMessageData(id, role, emoji);
const rep = await RoleEmojiPair.findOne({
where: {
[Op.or]: [
{
message: id,
role: role.id
}, {
message: id,
emoji
}
]
}
});
if (rep !== null) throw new Error(`Failed to fetch RoleEmojiPair entry with data {message:${id},role:${role.id},emoji:${emoji}}!`);
// Create database entry for pair
await RoleEmojiPair.create({ message: id, role: role.id, emoji });
step = 'react to'; step = 'react to';
// React with emoji to message // React with emoji to message