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,22 +50,7 @@ const registerSelfRoles = async (interaction) => {
return response;
};
const addSelfRoles = async (interaction) => {
const { options, channel } = interaction;
const id = options.getString('id');
let step = 'fetch';
try {
// Get message by id
const message = await channel.messages.fetch(id);
// Get user arguments
const role = options.getRole('role');
const emoji = options
.getString('emoji')
.replace(/:.*?:/, ':_:');
step = 'save data from';
const saveMessageData = async (id, role, emoji) => {
// Try finding existing entry
const rep = await RoleEmojiPair.findOne({
where: {
@ -84,6 +69,25 @@ const addSelfRoles = async (interaction) => {
// Create database entry for pair
await RoleEmojiPair.create({ message: id, role: role.id, emoji });
};
const addSelfRoles = async (interaction) => {
const { options, channel } = interaction;
const id = options.getString('id');
let step = 'fetch';
try {
// Get message by id
const message = await channel.messages.fetch(id);
// Get user arguments
const role = options.getRole('role');
const emoji = options
.getString('emoji')
.replace(/:.*?:/, ':_:');
step = 'save data from';
await saveMessageData(id, role, emoji);
step = 'react to';
// React with emoji to message