generated from Baipyrus/DiscordJS-Template
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;
|
return response;
|
||||||
};
|
};
|
||||||
|
|
||||||
const addSelfRoles = async (interaction) => {
|
const saveMessageData = async (id, role, emoji) => {
|
||||||
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';
|
|
||||||
// Try finding existing entry
|
// Try finding existing entry
|
||||||
const rep = await RoleEmojiPair.findOne({
|
const rep = await RoleEmojiPair.findOne({
|
||||||
where: {
|
where: {
|
||||||
@ -84,6 +69,25 @@ const addSelfRoles = async (interaction) => {
|
|||||||
|
|
||||||
// Create database entry for pair
|
// Create database entry for pair
|
||||||
await RoleEmojiPair.create({ message: id, role: role.id, emoji });
|
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';
|
step = 'react to';
|
||||||
// React with emoji to message
|
// React with emoji to message
|
||||||
|
Loading…
Reference in New Issue
Block a user