mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 18:59:19 +00:00
Formatted code and clean up
This commit is contained in:
+164
-160
@@ -1,180 +1,179 @@
|
||||
import Logger from "../libs/Logger";
|
||||
import DiscordProvider from "../providers/Discord";
|
||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
|
||||
import DiscordProvider from '../providers/Discord';
|
||||
import Logger from '../libs/Logger';
|
||||
|
||||
export const GLOBAL_COMMANDS: Object[] = [];
|
||||
|
||||
export const GUILD_COMMANDS: Object[] = [];
|
||||
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder()
|
||||
.setName('help')
|
||||
.setDescription('Show help menu')
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder().setName('help').setDescription('Show help menu'));
|
||||
GUILD_COMMANDS.push(
|
||||
new SlashCommandBuilder().setName('ping').setDescription('Measure network latency')
|
||||
);
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder()
|
||||
.setName('ping')
|
||||
.setDescription('Measure network latency')
|
||||
GUILD_COMMANDS.push(
|
||||
new SlashCommandBuilder().setName('invite').setDescription('Invite me to your server!')
|
||||
);
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder()
|
||||
.setName('invite')
|
||||
.setDescription('Invite me to your server!')
|
||||
GUILD_COMMANDS.push(
|
||||
new SlashCommandBuilder()
|
||||
.setName('say')
|
||||
.setDescription('Make me say something')
|
||||
.addStringOption((option) =>
|
||||
option.setName('message').setDescription('Message you want me to say').setRequired(true)
|
||||
)
|
||||
);
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder()
|
||||
.setName('say')
|
||||
.setDescription('Make me say something')
|
||||
.addStringOption(option => option
|
||||
.setName('message')
|
||||
.setDescription('Message you want me to say')
|
||||
.setRequired(true)
|
||||
)
|
||||
GUILD_COMMANDS.push(
|
||||
new SlashCommandBuilder()
|
||||
.setName('interaction')
|
||||
.setDescription('[Developer Only] Manage interaction')
|
||||
.addSubcommand((info) =>
|
||||
info.setName('info').setDescription('[Developer Only] Interaction modules information')
|
||||
)
|
||||
.addSubcommand((reloadAll) =>
|
||||
reloadAll
|
||||
.setName('reloadall')
|
||||
.setDescription('[Developer Only] Reload interaction for global and all guilds')
|
||||
)
|
||||
);
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder()
|
||||
.setName('interaction')
|
||||
.setDescription('[Developer Only] Manage interaction')
|
||||
.addSubcommand(info => info
|
||||
.setName('info')
|
||||
.setDescription('[Developer Only] Interaction modules information')
|
||||
)
|
||||
.addSubcommand(reloadAll => reloadAll
|
||||
.setName('reloadall')
|
||||
.setDescription('[Developer Only] Reload interaction for global and all guilds')
|
||||
)
|
||||
GUILD_COMMANDS.push(
|
||||
new SlashCommandBuilder()
|
||||
.setName('settings')
|
||||
.setDescription('Change settings')
|
||||
.addSubcommand((info) =>
|
||||
info
|
||||
.setName('setprefix')
|
||||
.setDescription('Change what prefix to use on this guild')
|
||||
.addStringOption((prefix) =>
|
||||
prefix.setName('prefix').setDescription('New prefix to use').setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((info) =>
|
||||
info
|
||||
.setName('setenableserviceannouncement')
|
||||
.setDescription('Enable or disable service announcement feature')
|
||||
.addStringOption((prefix) =>
|
||||
prefix.setName('status').setDescription('New status').setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((info) =>
|
||||
info
|
||||
.setName('setserviceannouncementchannel')
|
||||
.setDescription('Set channel where service announcement will be sent')
|
||||
.addChannelOption((prefix) =>
|
||||
prefix.setName('channel').setDescription('New status').setRequired(true)
|
||||
)
|
||||
)
|
||||
);
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder()
|
||||
.setName('settings')
|
||||
.setDescription('Change settings')
|
||||
.addSubcommand(info => info
|
||||
.setName('setprefix')
|
||||
.setDescription('Change what prefix to use on this guild')
|
||||
.addStringOption(prefix => prefix
|
||||
.setName('prefix')
|
||||
.setDescription('New prefix to use')
|
||||
.setRequired(true)
|
||||
GUILD_COMMANDS.push(
|
||||
new SlashCommandBuilder()
|
||||
.setName('membershipscreening')
|
||||
.setDescription('Membership screening')
|
||||
.addSubcommand((info) =>
|
||||
info.setName('info').setDescription('Show more information for membership screening')
|
||||
)
|
||||
)
|
||||
.addSubcommand(info => info
|
||||
.setName('setenableserviceannouncement')
|
||||
.setDescription('Enable or disable service announcement feature')
|
||||
.addStringOption(prefix => prefix
|
||||
.setName('status')
|
||||
.setDescription('New status')
|
||||
.setRequired(true)
|
||||
.addSubcommand((enable) =>
|
||||
enable.setName('enable').setDescription('Enable membership screening')
|
||||
)
|
||||
)
|
||||
.addSubcommand(info => info
|
||||
.setName('setserviceannouncementchannel')
|
||||
.setDescription('Set channel where service announcement will be sent')
|
||||
.addChannelOption(prefix => prefix
|
||||
.setName('channel')
|
||||
.setDescription('New status')
|
||||
.setRequired(true)
|
||||
.addSubcommand((enable) =>
|
||||
enable.setName('disable').setDescription('Disable membership screening')
|
||||
)
|
||||
.addSubcommand((setrole) =>
|
||||
setrole
|
||||
.setName('setrole')
|
||||
.setDescription('Set a role that user will be granted when approved to join')
|
||||
.addRoleOption((option) =>
|
||||
option
|
||||
.setName('role')
|
||||
.setDescription(
|
||||
'Select a role that user will be granted when approved to join'
|
||||
)
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((setchannel) =>
|
||||
setchannel
|
||||
.setName('setchannel')
|
||||
.setDescription(
|
||||
'Set channel where membership screening approval request will be sent'
|
||||
)
|
||||
.addChannelOption((option) =>
|
||||
option
|
||||
.setName('channel')
|
||||
.setDescription('Select a channel where approval request will be sent')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((createmessage) =>
|
||||
createmessage
|
||||
.setName('createmessage')
|
||||
.setDescription(
|
||||
'Create greeting message for membership screening into the channel. A message for new commers to read'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder()
|
||||
.setName('membershipscreening')
|
||||
.setDescription('Membership screening')
|
||||
.addSubcommand(info => info
|
||||
.setName('info')
|
||||
.setDescription('Show more information for membership screening')
|
||||
)
|
||||
.addSubcommand(enable => enable
|
||||
.setName('enable')
|
||||
.setDescription('Enable membership screening')
|
||||
)
|
||||
.addSubcommand(enable => enable
|
||||
.setName('disable')
|
||||
.setDescription('Disable membership screening')
|
||||
)
|
||||
.addSubcommand(setrole => setrole
|
||||
.setName('setrole')
|
||||
.setDescription('Set a role that user will be granted when approved to join')
|
||||
.addRoleOption(option => option
|
||||
.setName('role')
|
||||
.setDescription('Select a role that user will be granted when approved to join')
|
||||
.setRequired(true)
|
||||
GUILD_COMMANDS.push(
|
||||
new SlashCommandBuilder()
|
||||
.setName('osu')
|
||||
.setDescription('Interact with the game osu!')
|
||||
.addSubcommand((user) =>
|
||||
user
|
||||
.setName('user')
|
||||
.setDescription('Get user information on osu!')
|
||||
.addStringOption((user) =>
|
||||
user.setName('user').setDescription('Username or User id').setRequired(true)
|
||||
)
|
||||
)
|
||||
)
|
||||
.addSubcommand(setchannel => setchannel
|
||||
.setName('setchannel')
|
||||
.setDescription('Set channel where membership screening approval request will be sent')
|
||||
.addChannelOption(option => option
|
||||
.setName('channel')
|
||||
.setDescription('Select a channel where approval request will be sent')
|
||||
.setRequired(true)
|
||||
.addSubcommand((beatmap) =>
|
||||
beatmap
|
||||
.setName('beatmap')
|
||||
.setDescription('Get beatmap information on osu!')
|
||||
.addStringOption((user) =>
|
||||
user.setName('beatmap').setDescription('Beatmap id').setRequired(true)
|
||||
)
|
||||
)
|
||||
)
|
||||
.addSubcommand(createmessage => createmessage
|
||||
.setName('createmessage')
|
||||
.setDescription('Create greeting message for membership screening into the channel. A message for new commers to read')
|
||||
)
|
||||
);
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder()
|
||||
.setName('osu')
|
||||
.setDescription('Interact with the game osu!')
|
||||
.addSubcommand(user => user
|
||||
.setName('user')
|
||||
.setDescription('Get user information on osu!')
|
||||
.addStringOption(user => user
|
||||
.setName('user')
|
||||
.setDescription('Username or User id')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand(beatmap => beatmap
|
||||
.setName('beatmap')
|
||||
.setDescription('Get beatmap information on osu!')
|
||||
.addStringOption(user => user
|
||||
.setName('beatmap')
|
||||
.setDescription('Beatmap id')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder()
|
||||
.setName('userinfo')
|
||||
.setDescription('Lookup discord user information')
|
||||
.addSubcommand(user => user
|
||||
.setName('user')
|
||||
GUILD_COMMANDS.push(
|
||||
new SlashCommandBuilder()
|
||||
.setName('userinfo')
|
||||
.setDescription('Lookup discord user information')
|
||||
.addUserOption(user => user
|
||||
.setName('user')
|
||||
.setDescription('Discord user to lookup')
|
||||
.setRequired(true)
|
||||
.addSubcommand((user) =>
|
||||
user
|
||||
.setName('user')
|
||||
.setDescription('Lookup discord user information')
|
||||
.addUserOption((user) =>
|
||||
user.setName('user').setDescription('Discord user to lookup').setRequired(true)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder()
|
||||
.setName('stats')
|
||||
.setDescription('Show the bot stats')
|
||||
GUILD_COMMANDS.push(
|
||||
new SlashCommandBuilder().setName('stats').setDescription('Show the bot stats')
|
||||
);
|
||||
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder()
|
||||
.setName('skip')
|
||||
.setDescription('Skip the current song')
|
||||
GUILD_COMMANDS.push(
|
||||
new SlashCommandBuilder().setName('skip').setDescription('Skip the current song')
|
||||
);
|
||||
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder()
|
||||
.setName('nowplaying')
|
||||
.setDescription('Show the current song information')
|
||||
GUILD_COMMANDS.push(
|
||||
new SlashCommandBuilder()
|
||||
.setName('nowplaying')
|
||||
.setDescription('Show the current song information')
|
||||
);
|
||||
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder()
|
||||
.setName('join')
|
||||
.setDescription('Join the voice channel')
|
||||
GUILD_COMMANDS.push(
|
||||
new SlashCommandBuilder().setName('join').setDescription('Join the voice channel')
|
||||
);
|
||||
|
||||
GUILD_COMMANDS.push(new SlashCommandBuilder()
|
||||
.setName('leave')
|
||||
.setDescription('Leave the voice channel')
|
||||
GUILD_COMMANDS.push(
|
||||
new SlashCommandBuilder().setName('leave').setDescription('Leave the voice channel')
|
||||
);
|
||||
|
||||
|
||||
export const registerAllGlobalCommands = async () => {
|
||||
Logger.log('info', `Registering all global interaction commands`);
|
||||
await DiscordProvider.client.application?.commands.set(JSON.parse(JSON.stringify(GLOBAL_COMMANDS)));
|
||||
}
|
||||
await DiscordProvider.client.application?.commands.set(
|
||||
JSON.parse(JSON.stringify(GLOBAL_COMMANDS))
|
||||
);
|
||||
};
|
||||
|
||||
export const unregisterAllGlobalCommands = async () => {
|
||||
//const commands = await DiscordProvider.client.application?.commands.fetch();
|
||||
@@ -187,32 +186,38 @@ export const unregisterAllGlobalCommands = async () => {
|
||||
/*for(const command of commands) {
|
||||
await DiscordProvider.client.application?.commands.delete(command[1]);
|
||||
}*/
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
export const registerAllGuildsCommands = async () => {
|
||||
const guilds = DiscordProvider.client.guilds.cache.map(guild => guild.id);
|
||||
const guilds = DiscordProvider.client.guilds.cache.map((guild) => guild.id);
|
||||
|
||||
for(const guild of guilds) {
|
||||
for (const guild of guilds) {
|
||||
const guildObject = DiscordProvider.client.guilds.cache.get(guild);
|
||||
|
||||
if(!guildObject) continue;
|
||||
|
||||
Logger.log('info', `Registering all interaction commands on guild ${guildObject.name} (${guildObject.id})`);
|
||||
await DiscordProvider.client.guilds.cache.get(guildObject.id)?.commands.set(JSON.parse(JSON.stringify(GUILD_COMMANDS)));
|
||||
if (!guildObject) continue;
|
||||
|
||||
Logger.log(
|
||||
'info',
|
||||
`Registering all interaction commands on guild ${guildObject.name} (${guildObject.id})`
|
||||
);
|
||||
await DiscordProvider.client.guilds.cache
|
||||
.get(guildObject.id)
|
||||
?.commands.set(JSON.parse(JSON.stringify(GUILD_COMMANDS)));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const unregisterAllGuildsCommands = async () => {
|
||||
const guilds = DiscordProvider.client.guilds.cache.map(guild => guild.id);
|
||||
|
||||
for(const guild of guilds) {
|
||||
const guilds = DiscordProvider.client.guilds.cache.map((guild) => guild.id);
|
||||
|
||||
for (const guild of guilds) {
|
||||
const guildObject = DiscordProvider.client.guilds.cache.get(guild);
|
||||
|
||||
if(!guildObject) continue;
|
||||
if (!guildObject) continue;
|
||||
|
||||
Logger.log('info', `Unregistering all interaction commands on guild ${guildObject.name} (${guildObject.id})`);
|
||||
Logger.log(
|
||||
'info',
|
||||
`Unregistering all interaction commands on guild ${guildObject.name} (${guildObject.id})`
|
||||
);
|
||||
await DiscordProvider.client.guilds.cache.get(guildObject.id)?.commands.set([]);
|
||||
|
||||
//const commands = await guildObject.commands.fetch();
|
||||
@@ -225,6 +230,5 @@ export const unregisterAllGuildsCommands = async () => {
|
||||
Logger.log('error', `Cannot unregister all interaction commands on guild ${guildObject.name} (${guildObject.id})`);
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+180
-92
@@ -1,186 +1,274 @@
|
||||
import { MessageEmbed, User, MessagePayload, MessageOptions, GuildTextBasedChannel, TextChannel, DMChannel, PartialDMChannel, BaseGuildTextChannel, Message, ColorResolvable, Interaction, InteractionReplyOptions, CommandInteraction } from "discord.js";
|
||||
import App from "..";
|
||||
import Logger from "../libs/Logger";
|
||||
import { HybridInteractionMessage } from "./DiscordModule";
|
||||
import {
|
||||
MessageEmbed,
|
||||
User,
|
||||
MessagePayload,
|
||||
MessageOptions,
|
||||
GuildTextBasedChannel,
|
||||
TextChannel,
|
||||
DMChannel,
|
||||
PartialDMChannel,
|
||||
BaseGuildTextChannel,
|
||||
Message,
|
||||
ColorResolvable,
|
||||
Interaction,
|
||||
InteractionReplyOptions,
|
||||
CommandInteraction
|
||||
} from 'discord.js';
|
||||
|
||||
import App from '..';
|
||||
import { HybridInteractionMessage } from './DiscordModule';
|
||||
import Logger from '../libs/Logger';
|
||||
|
||||
const emotes = {
|
||||
"yumiloading": "<a:yumiloading:983269480085983262>"
|
||||
yumiloading: '<a:yumiloading:983269480085983262>'
|
||||
};
|
||||
|
||||
export function makeEmbed(icon: string | undefined, title: string, description: any, color: ColorResolvable, fields: any, user: User, setTimestamp: boolean) {
|
||||
|
||||
export function makeEmbed(
|
||||
icon: string | undefined,
|
||||
title: string,
|
||||
description: any,
|
||||
color: ColorResolvable,
|
||||
fields: any,
|
||||
user: User,
|
||||
setTimestamp: boolean
|
||||
) {
|
||||
const embed = new MessageEmbed();
|
||||
embed.setColor(color || '#FFFFFF');
|
||||
|
||||
if(typeof icon === 'undefined')
|
||||
embed.setTitle(title);
|
||||
else
|
||||
embed.setTitle(`${icon} ${title}`);
|
||||
if (typeof icon === 'undefined') embed.setTitle(title);
|
||||
else embed.setTitle(`${icon} ${title}`);
|
||||
|
||||
if (typeof description !== 'undefined')
|
||||
embed.setDescription(description)
|
||||
if (typeof description !== 'undefined') embed.setDescription(description);
|
||||
|
||||
if(setTimestamp)
|
||||
embed.setTimestamp();
|
||||
if (setTimestamp) embed.setTimestamp();
|
||||
|
||||
if(typeof user !== 'undefined')
|
||||
if (typeof user !== 'undefined')
|
||||
embed.footer = {
|
||||
text: `${user.username} | v${App.version}`,
|
||||
iconURL: `${user.displayAvatarURL()}?size=4096`
|
||||
}
|
||||
};
|
||||
else
|
||||
embed.footer = {
|
||||
text: `v${App.version}`
|
||||
}
|
||||
|
||||
if (typeof fields !== 'undefined')
|
||||
embed.addFields(fields);
|
||||
|
||||
return embed;
|
||||
};
|
||||
|
||||
if (typeof fields !== 'undefined') embed.addFields(fields);
|
||||
|
||||
return embed;
|
||||
}
|
||||
|
||||
export function makeSuccessEmbed(options: any) {
|
||||
return makeEmbed(typeof options.icon === 'undefined' ? "✅" : options.icon, options.title, options.description, '#B5EAD7', options.fields, options.user, options.setTimestamp || true);
|
||||
return makeEmbed(
|
||||
typeof options.icon === 'undefined' ? '✅' : options.icon,
|
||||
options.title,
|
||||
options.description,
|
||||
'#B5EAD7',
|
||||
options.fields,
|
||||
options.user,
|
||||
options.setTimestamp || true
|
||||
);
|
||||
}
|
||||
|
||||
export function makeWarningEmbed(options: any) {
|
||||
return makeEmbed(typeof options.icon === 'undefined' ? "⚠️" : options.icon, options.title, options.description, '#FFEEAD', options.fields, options.user, options.setTimestamp || true);
|
||||
return makeEmbed(
|
||||
typeof options.icon === 'undefined' ? '⚠️' : options.icon,
|
||||
options.title,
|
||||
options.description,
|
||||
'#FFEEAD',
|
||||
options.fields,
|
||||
options.user,
|
||||
options.setTimestamp || true
|
||||
);
|
||||
}
|
||||
|
||||
export function makeErrorEmbed(options: any) {
|
||||
return makeEmbed(typeof options.icon === 'undefined' ? "❌" : options.icon, options.title, options.description, '#FF9AA2', options.fields, options.user, options.setTimestamp || true);
|
||||
return makeEmbed(
|
||||
typeof options.icon === 'undefined' ? '❌' : options.icon,
|
||||
options.title,
|
||||
options.description,
|
||||
'#FF9AA2',
|
||||
options.fields,
|
||||
options.user,
|
||||
options.setTimestamp || true
|
||||
);
|
||||
}
|
||||
|
||||
export function makeProcessingEmbed(options: any) {
|
||||
return makeEmbed(typeof options.icon === 'undefined' ? getEmotes().yumiloading : options.icon, options.title, options.description, '#E2F0CB', options.fields, options.user, options.setTimestamp || true);
|
||||
return makeEmbed(
|
||||
typeof options.icon === 'undefined' ? getEmotes().yumiloading : options.icon,
|
||||
options.title,
|
||||
options.description,
|
||||
'#E2F0CB',
|
||||
options.fields,
|
||||
options.user,
|
||||
options.setTimestamp || true
|
||||
);
|
||||
}
|
||||
|
||||
export function makeInfoEmbed(options: any) {
|
||||
return makeEmbed(typeof options.icon === 'undefined' ? "🔮" : options.icon, options.title, options.description, '#C7CEEA', options.fields, options.user, options.setTimestamp || true);
|
||||
return makeEmbed(
|
||||
typeof options.icon === 'undefined' ? '🔮' : options.icon,
|
||||
options.title,
|
||||
options.description,
|
||||
'#C7CEEA',
|
||||
options.fields,
|
||||
options.user,
|
||||
options.setTimestamp || true
|
||||
);
|
||||
}
|
||||
|
||||
export async function sendMessage(channel: TextChannel | DMChannel | BaseGuildTextChannel | GuildTextBasedChannel | PartialDMChannel , user: User | undefined, options: string | MessagePayload | MessageOptions) {
|
||||
|
||||
export async function sendMessage(
|
||||
channel:
|
||||
| TextChannel
|
||||
| DMChannel
|
||||
| BaseGuildTextChannel
|
||||
| GuildTextBasedChannel
|
||||
| PartialDMChannel,
|
||||
user: User | undefined,
|
||||
options: string | MessagePayload | MessageOptions
|
||||
) {
|
||||
let message;
|
||||
|
||||
try { message = await channel.send(options); }
|
||||
catch(error) {
|
||||
if(typeof user === 'undefined') {
|
||||
return Logger.error(`Cannot find available destinations to send the message CID: ${channel.id} C_ERR: ${error}`);
|
||||
try {
|
||||
message = await channel.send(options);
|
||||
} catch (error) {
|
||||
if (typeof user === 'undefined') {
|
||||
return Logger.error(
|
||||
`Cannot find available destinations to send the message CID: ${channel.id} C_ERR: ${error}`
|
||||
);
|
||||
}
|
||||
try { message = await user.send(options); }
|
||||
catch(errorDM) {
|
||||
Logger.error(`Cannot find available destinations to send the message CID: ${channel.id} UID: ${user.id} C_ERR: ${error} DM_ERR: ${errorDM}`);
|
||||
try {
|
||||
message = await user.send(options);
|
||||
} catch (errorDM) {
|
||||
Logger.error(
|
||||
`Cannot find available destinations to send the message CID: ${channel.id} UID: ${user.id} C_ERR: ${error} DM_ERR: ${errorDM}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
} finally {
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export async function sendReply(rMessage: Message, options: string | MessagePayload | MessageOptions) {
|
||||
|
||||
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}`);
|
||||
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 sendMessageOrInteractionResponse(data: Message | Interaction, payload: MessageOptions | InteractionReplyOptions, replace = false) {
|
||||
export async function sendMessageOrInteractionResponse(
|
||||
data: Message | Interaction,
|
||||
payload: MessageOptions | InteractionReplyOptions,
|
||||
replace = false
|
||||
) {
|
||||
const isSlashCommand = data instanceof CommandInteraction && data.isCommand();
|
||||
const isMessage = data instanceof Message;
|
||||
|
||||
if(isSlashCommand || (data instanceof Interaction && ( data.isSelectMenu() || data.isButton()))) {
|
||||
if(!data.replied) {
|
||||
if (
|
||||
isSlashCommand ||
|
||||
(data instanceof Interaction && (data.isSelectMenu() || data.isButton()))
|
||||
) {
|
||||
if (!data.replied) {
|
||||
let message;
|
||||
try {
|
||||
if(!data.deferred)
|
||||
return await data.reply(payload as InteractionReplyOptions);
|
||||
else
|
||||
return await data.editReply(payload);
|
||||
}
|
||||
catch(errorDM) {
|
||||
Logger.error(`Cannot find available destinations to send the message CID: ${data.channel!.id} UID: ${data.user.id} DM_ERR: ${errorDM}`);
|
||||
if (!data.deferred) return await data.reply(payload as InteractionReplyOptions);
|
||||
else return await data.editReply(payload);
|
||||
} catch (errorDM) {
|
||||
Logger.error(
|
||||
`Cannot find available destinations to send the message CID: ${
|
||||
data.channel!.id
|
||||
} UID: ${data.user.id} DM_ERR: ${errorDM}`
|
||||
);
|
||||
return;
|
||||
} finally {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
let message;
|
||||
try {
|
||||
if(replace)
|
||||
return await data.editReply(payload);
|
||||
else
|
||||
return await data.followUp(payload as InteractionReplyOptions);
|
||||
}
|
||||
catch(errorDM) {
|
||||
Logger.error(`Cannot find available destinations to send the message CID: ${data.channel!.id} UID: ${data.user.id} DM_ERR: ${errorDM}`);
|
||||
try {
|
||||
if (replace) return await data.editReply(payload);
|
||||
else return await data.followUp(payload as InteractionReplyOptions);
|
||||
} catch (errorDM) {
|
||||
Logger.error(
|
||||
`Cannot find available destinations to send the message CID: ${
|
||||
data.channel!.id
|
||||
} UID: ${data.user.id} DM_ERR: ${errorDM}`
|
||||
);
|
||||
return;
|
||||
} finally {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(isMessage) return await sendReply(data, payload as MessageOptions);
|
||||
} else if (isMessage) return await sendReply(data, payload as MessageOptions);
|
||||
}
|
||||
|
||||
export async function sendHybridInteractionMessageResponse(data: HybridInteractionMessage, payload: MessageOptions | InteractionReplyOptions, replace = false): (Promise<Message | Interaction | undefined>) {
|
||||
|
||||
if(data.isSlashCommand() || data.isButton() || data.isSelectMenu()) {
|
||||
|
||||
export async function sendHybridInteractionMessageResponse(
|
||||
data: HybridInteractionMessage,
|
||||
payload: MessageOptions | InteractionReplyOptions,
|
||||
replace = false
|
||||
): Promise<Message | Interaction | undefined> {
|
||||
if (data.isSlashCommand() || data.isButton() || data.isSelectMenu()) {
|
||||
const messageComponent = data.getMessageComponentInteraction();
|
||||
|
||||
if(!messageComponent.replied) {
|
||||
if (!messageComponent.replied) {
|
||||
let message;
|
||||
try {
|
||||
if(!messageComponent.deferred) {
|
||||
if (!messageComponent.deferred) {
|
||||
await messageComponent.reply(payload as InteractionReplyOptions);
|
||||
return messageComponent;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
await messageComponent.editReply(payload);
|
||||
return messageComponent;
|
||||
}
|
||||
}
|
||||
catch(errorDM) {
|
||||
Logger.error(`Cannot find available destinations to send the message CID: ${messageComponent.channel!.id} UID: ${messageComponent.user.id} DM_ERR: ${errorDM}`);
|
||||
} catch (errorDM) {
|
||||
Logger.error(
|
||||
`Cannot find available destinations to send the message CID: ${
|
||||
messageComponent.channel!.id
|
||||
} UID: ${messageComponent.user.id} DM_ERR: ${errorDM}`
|
||||
);
|
||||
return;
|
||||
} finally {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
let message;
|
||||
try {
|
||||
if(replace)
|
||||
return (await messageComponent.editReply(payload) as Message);
|
||||
try {
|
||||
if (replace) return (await messageComponent.editReply(payload)) as Message;
|
||||
else
|
||||
return (await messageComponent.followUp(payload as InteractionReplyOptions) as Message);
|
||||
}
|
||||
catch(errorDM) {
|
||||
Logger.error(`Cannot find available destinations to send the message CID: ${messageComponent.channel!.id} UID: ${messageComponent.user.id} DM_ERR: ${errorDM}`);
|
||||
return (await messageComponent.followUp(
|
||||
payload as InteractionReplyOptions
|
||||
)) as Message;
|
||||
} catch (errorDM) {
|
||||
Logger.error(
|
||||
`Cannot find available destinations to send the message CID: ${
|
||||
messageComponent.channel!.id
|
||||
} UID: ${messageComponent.user.id} DM_ERR: ${errorDM}`
|
||||
);
|
||||
return;
|
||||
} finally {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(data.isMessage()) return await sendReply(data.getMessage(), payload as MessageOptions);
|
||||
} else if (data.isMessage())
|
||||
return await sendReply(data.getMessage(), payload as MessageOptions);
|
||||
}
|
||||
|
||||
export function getEmotes() {
|
||||
return emotes;
|
||||
}
|
||||
}
|
||||
|
||||
+60
-44
@@ -1,45 +1,63 @@
|
||||
import { Guild, Interaction, Message, GuildMember, CommandInteraction, ButtonInteraction, TextBasedChannel, MessageComponentInteraction, User, SelectMenuInteraction } from "discord.js";
|
||||
import {
|
||||
Guild,
|
||||
Interaction,
|
||||
Message,
|
||||
GuildMember,
|
||||
CommandInteraction,
|
||||
ButtonInteraction,
|
||||
TextBasedChannel,
|
||||
MessageComponentInteraction,
|
||||
User,
|
||||
SelectMenuInteraction
|
||||
} from 'discord.js';
|
||||
|
||||
export default class DiscordModule {
|
||||
|
||||
public id?: string;
|
||||
public commands?: (string[] | null) = null;
|
||||
public commandInteractionName?: (string | null) = null;
|
||||
public commands?: string[] | null = null;
|
||||
public commandInteractionName?: string | null = null;
|
||||
|
||||
constructor({ id, command, commandInteractionName }: {
|
||||
id?: string,
|
||||
command?: (string[] | null),
|
||||
commandInteractionName?: (string | null)
|
||||
constructor({
|
||||
id,
|
||||
command,
|
||||
commandInteractionName
|
||||
}: {
|
||||
id?: string;
|
||||
command?: string[] | null;
|
||||
commandInteractionName?: string | null;
|
||||
} = {}) {
|
||||
this.id = id;
|
||||
this.commands = command;
|
||||
this.commandInteractionName = commandInteractionName;
|
||||
this.id = id;
|
||||
this.commands = command;
|
||||
this.commandInteractionName = commandInteractionName;
|
||||
}
|
||||
|
||||
Init(): (void | Promise<void | any>) {}
|
||||
Ready(): (void | Promise<void | any>) {}
|
||||
Init(): void | Promise<void | any> {}
|
||||
Ready(): void | Promise<void | any> {}
|
||||
|
||||
GuildOnCommand(command: string, args: any, message: Message): (void | Promise<void | any>) {}
|
||||
GuildOnModuleCommand(args: any, message: Message): (void | Promise<void | any>) {}
|
||||
GuildOnCommand(command: string, args: any, message: Message): void | Promise<void | any> {}
|
||||
GuildOnModuleCommand(args: any, message: Message): void | Promise<void | any> {}
|
||||
|
||||
GuildInteractionCreate(interaction: Interaction): (void | Promise<void | any>) {}
|
||||
GuildModuleInteractionCreate(interaction: Interaction): (void | Promise<void | any>) {}
|
||||
GuildInteractionCreate(interaction: Interaction): void | Promise<void | any> {}
|
||||
GuildModuleInteractionCreate(interaction: Interaction): void | Promise<void | any> {}
|
||||
|
||||
GuildCommandInteractionCreate(interaction: CommandInteraction): (void | Promise<void | any>) {}
|
||||
GuildModuleCommandInteractionCreate(interaction: CommandInteraction): (void | Promise<void | any>) {}
|
||||
GuildCommandInteractionCreate(interaction: CommandInteraction): void | Promise<void | any> {}
|
||||
GuildModuleCommandInteractionCreate(
|
||||
interaction: CommandInteraction
|
||||
): void | Promise<void | any> {}
|
||||
|
||||
GuildSelectMenuInteractionCreate(interaction: SelectMenuInteraction): (void | Promise<void | any>) {}
|
||||
GuildSelectMenuInteractionCreate(
|
||||
interaction: SelectMenuInteraction
|
||||
): void | Promise<void | any> {}
|
||||
|
||||
GuildButtonInteractionCreate(interaction: ButtonInteraction): (void | Promise<void | any>) {}
|
||||
GuildButtonInteractionCreate(interaction: ButtonInteraction): void | Promise<void | any> {}
|
||||
|
||||
GuildCreate(guild: Guild): (void | Promise<void | any>) {}
|
||||
GuildMemberAdd(member: GuildMember): (void | Promise<void | any>) {}
|
||||
GuildMessageCreate(message: Message): (void | Promise<void | any>) {}
|
||||
GuildCreate(guild: Guild): void | Promise<void | any> {}
|
||||
GuildMemberAdd(member: GuildMember): void | Promise<void | any> {}
|
||||
GuildMessageCreate(message: Message): void | Promise<void | any> {}
|
||||
}
|
||||
|
||||
export class HybridInteractionMessage {
|
||||
public data: Interaction | Message;
|
||||
constructor (data: Interaction | Message) {
|
||||
constructor(data: Interaction | Message) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@@ -54,7 +72,7 @@ export class HybridInteractionMessage {
|
||||
public isButton(): boolean {
|
||||
return this.data instanceof ButtonInteraction && this.data.isButton();
|
||||
}
|
||||
|
||||
|
||||
public isSelectMenu(): boolean {
|
||||
return this.data instanceof SelectMenuInteraction && this.data.isSelectMenu();
|
||||
}
|
||||
@@ -63,58 +81,56 @@ export class HybridInteractionMessage {
|
||||
return this.data instanceof Message;
|
||||
}
|
||||
|
||||
public getChannel(): (TextBasedChannel | null) {
|
||||
public getChannel(): TextBasedChannel | null {
|
||||
return this.data.channel;
|
||||
}
|
||||
|
||||
public getGuild(): (Guild | null) {
|
||||
public getGuild(): Guild | null {
|
||||
return this.data.guild;
|
||||
}
|
||||
|
||||
public getUser(): (User | null) {
|
||||
return (this.isInteraction()) ? this.getInteraction().user : this.getMessage().author
|
||||
public getUser(): User | null {
|
||||
return this.isInteraction() ? this.getInteraction().user : this.getMessage().author;
|
||||
}
|
||||
|
||||
public getMember(): (GuildMember | null) {
|
||||
return (this.data.member as GuildMember);
|
||||
public getMember(): GuildMember | null {
|
||||
return this.data.member as GuildMember;
|
||||
}
|
||||
|
||||
public getInteraction(): Interaction {
|
||||
if(this.isMessage())
|
||||
throw new Error("Unable to cast interaction to message");
|
||||
if (this.isMessage()) throw new Error('Unable to cast interaction to message');
|
||||
|
||||
return this.data as Interaction;
|
||||
}
|
||||
|
||||
public getSlashCommand(): CommandInteraction {
|
||||
if(this.isInteraction() && !(this.data as CommandInteraction))
|
||||
throw new Error("Unable to cast to MessageComponentInteraction");
|
||||
if (this.isInteraction() && !(this.data as CommandInteraction))
|
||||
throw new Error('Unable to cast to MessageComponentInteraction');
|
||||
|
||||
return this.data as CommandInteraction;
|
||||
}
|
||||
|
||||
public getSelectMenu(): SelectMenuInteraction {
|
||||
if(this.isInteraction() && !(this.data as SelectMenuInteraction))
|
||||
throw new Error("Unable to cast to SelectMenuInteraction");
|
||||
if (this.isInteraction() && !(this.data as SelectMenuInteraction))
|
||||
throw new Error('Unable to cast to SelectMenuInteraction');
|
||||
|
||||
return this.data as SelectMenuInteraction;
|
||||
}
|
||||
|
||||
public getMessageComponentInteraction(): MessageComponentInteraction {
|
||||
if(this.isInteraction() && !(this.data as MessageComponentInteraction))
|
||||
throw new Error("Unable to cast to MessageComponentInteraction");
|
||||
if (this.isInteraction() && !(this.data as MessageComponentInteraction))
|
||||
throw new Error('Unable to cast to MessageComponentInteraction');
|
||||
|
||||
return this.data as MessageComponentInteraction;
|
||||
}
|
||||
|
||||
public getMessage(): Message {
|
||||
if(this.isInteraction())
|
||||
throw new Error("Unable to cast message to interaction");
|
||||
if (this.isInteraction()) throw new Error('Unable to cast message to interaction');
|
||||
|
||||
return this.data as Message;
|
||||
}
|
||||
|
||||
public getRaw(): (Interaction | Message) {
|
||||
public getRaw(): Interaction | Message {
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user