clean up: refactor by splitting into functions
This commit is contained in:
parent
42293efb68
commit
531b07e304
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user