mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 18:59:19 +00:00
Another code clean up
This commit is contained in:
+59
-48
@@ -33,6 +33,16 @@ interface EmbedData {
|
||||
setTimestamp: boolean;
|
||||
}
|
||||
|
||||
interface EmbedDataPresets {
|
||||
icon?: string;
|
||||
title: string;
|
||||
description?: any;
|
||||
color?: ColorResolvable;
|
||||
fields?: any;
|
||||
user?: User;
|
||||
setTimestamp?: boolean;
|
||||
}
|
||||
|
||||
export function makeEmbed(data: EmbedData) {
|
||||
const embed = new MessageEmbed();
|
||||
embed.setColor(data.color || '#FFFFFF');
|
||||
@@ -59,19 +69,19 @@ export function makeEmbed(data: EmbedData) {
|
||||
return embed;
|
||||
}
|
||||
|
||||
export function makeInfoEmbed(options: any) {
|
||||
export function makeInfoEmbed(data: EmbedDataPresets) {
|
||||
return makeEmbed({
|
||||
icon: !options.icon ? '🔮' : options.icon,
|
||||
title: options.title,
|
||||
description: options.description,
|
||||
icon: !data.icon ? '🔮' : data.icon,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
color: '#C7CEEA',
|
||||
fields: options.fields,
|
||||
user: options.user,
|
||||
setTimestamp: options.setTimestamp || true
|
||||
fields: data.fields,
|
||||
user: data.user,
|
||||
setTimestamp: data.setTimestamp || true
|
||||
});
|
||||
}
|
||||
|
||||
export function makeSuccessEmbed(options: any) {
|
||||
export function makeSuccessEmbed(options: EmbedDataPresets) {
|
||||
return makeEmbed({
|
||||
icon: !options.icon ? '✅' : options.icon,
|
||||
title: options.title,
|
||||
@@ -83,39 +93,39 @@ export function makeSuccessEmbed(options: any) {
|
||||
});
|
||||
}
|
||||
|
||||
export function makeWarningEmbed(options: any) {
|
||||
export function makeWarningEmbed(data: EmbedDataPresets) {
|
||||
return makeEmbed({
|
||||
icon: !options.icon ? '⚠️' : options.icon,
|
||||
title: options.title,
|
||||
description: options.description,
|
||||
icon: !data.icon ? '⚠️' : data.icon,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
color: '#FFEEAD',
|
||||
fields: options.fields,
|
||||
user: options.user,
|
||||
setTimestamp: options.setTimestamp || true
|
||||
fields: data.fields,
|
||||
user: data.user,
|
||||
setTimestamp: data.setTimestamp || true
|
||||
});
|
||||
}
|
||||
|
||||
export function makeErrorEmbed(options: any) {
|
||||
export function makeErrorEmbed(data: EmbedDataPresets) {
|
||||
return makeEmbed({
|
||||
icon: !options.icon ? '❌' : options.icon,
|
||||
title: options.title,
|
||||
description: options.description,
|
||||
icon: !data.icon ? '❌' : data.icon,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
color: '#FF9AA2',
|
||||
fields: options.fields,
|
||||
user: options.user,
|
||||
setTimestamp: options.setTimestamp || true
|
||||
fields: data.fields,
|
||||
user: data.user,
|
||||
setTimestamp: data.setTimestamp || true
|
||||
});
|
||||
}
|
||||
|
||||
export function makeProcessingEmbed(options: any) {
|
||||
export function makeProcessingEmbed(data: EmbedDataPresets) {
|
||||
return makeEmbed({
|
||||
icon: !options.icon ? getEmotes().yumiloading : options.icon,
|
||||
title: options.title,
|
||||
description: options.description,
|
||||
icon: !data.icon ? getEmotes().yumiloading : data.icon,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
color: '#E2F0CB',
|
||||
fields: options.fields,
|
||||
user: options.user,
|
||||
setTimestamp: options.setTimestamp || true
|
||||
fields: data.fields,
|
||||
user: data.user,
|
||||
setTimestamp: data.setTimestamp || true
|
||||
});
|
||||
}
|
||||
|
||||
@@ -147,25 +157,6 @@ export async function sendMessage(
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendReply(rMessage: Message, options: string | MessagePayload | MessageOptions) {
|
||||
let message;
|
||||
|
||||
try {
|
||||
message = await rMessage.reply(options);
|
||||
} catch (error) {
|
||||
try {
|
||||
message = await rMessage.author.send(options);
|
||||
} catch (errorDM) {
|
||||
Logger.error(
|
||||
`Cannot find available destinations to reply the message to. MID: ${rMessage.id} CID: ${rMessage.channel.id} UID: ${rMessage.author.id} C_ERR: ${error} DM_ERR: ${errorDM}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
} finally {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendHybridInteractionMessageResponse(
|
||||
data: HybridInteractionMessage,
|
||||
payload: MessageOptions | InteractionReplyOptions,
|
||||
@@ -216,3 +207,23 @@ export async function sendHybridInteractionMessageResponse(
|
||||
export function getEmotes() {
|
||||
return emotes;
|
||||
}
|
||||
|
||||
|
||||
async function sendReply(rMessage: Message, options: string | MessagePayload | MessageOptions) {
|
||||
let message;
|
||||
|
||||
try {
|
||||
message = await rMessage.reply(options);
|
||||
} catch (error) {
|
||||
try {
|
||||
message = await rMessage.author.send(options);
|
||||
} catch (errorDM) {
|
||||
Logger.error(
|
||||
`Cannot find available destinations to reply the message to. MID: ${rMessage.id} CID: ${rMessage.channel.id} UID: ${rMessage.author.id} C_ERR: ${error} DM_ERR: ${errorDM}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
} finally {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user