Files
Yumi/src/utils/DiscordInteraction.ts
T

138 lines
5.0 KiB
TypeScript
Raw Normal View History

2021-09-16 23:54:32 -07:00
import Logger from "../libs/Logger";
import DiscordProvider from "../providers/Discord";
2021-09-17 11:13:58 -07:00
import { ApplicationCommand, Collection } from "discord.js"
import { SlashCommandBuilder } from "@discordjs/builders";
2021-09-16 23:54:32 -07:00
2021-09-17 11:13:58 -07:00
export const GLOBAL_COMMANDS: Object[] = [];
2021-09-16 23:54:32 -07:00
2021-09-17 11:13:58 -07:00
export const GUILD_COMMANDS: Object[] = [];
2021-09-16 23:54:32 -07:00
2021-09-18 06:28:41 -07:00
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('invite')
.setDescription('Invite me to your server!')
);
2021-09-17 11:13:58 -07:00
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)
)
);
2021-09-18 06:28:41 -07:00
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')
)
);
2021-09-17 11:13:58 -07:00
GUILD_COMMANDS.push(new SlashCommandBuilder()
.setName('membershipscreening')
.setDescription('Membership screening')
2021-09-18 06:28:41 -07:00
.addSubcommand(info => info
.setName('info')
.setDescription('Show more information for membership screening')
)
2021-09-17 11:13:58 -07:00
.addSubcommand(enable => enable
.setName('enable')
2021-09-18 06:28:41 -07:00
.setDescription('Enable membership screening')
2021-09-17 11:13:58 -07:00
)
.addSubcommand(enable => enable
.setName('disable')
2021-09-18 06:28:41 -07:00
.setDescription('Disable membership screening')
2021-09-17 11:13:58 -07:00
)
.addSubcommand(setrole => setrole
.setName('setrole')
2021-09-18 06:28:41 -07:00
.setDescription('Set a role that user will be granted when approved to join')
2021-09-17 11:13:58 -07:00
.addRoleOption(option => option
.setName('role')
2021-09-18 06:28:41 -07:00
.setDescription('Select a role that user will be granted when approved to join')
2021-09-17 11:13:58 -07:00
.setRequired(true)
)
)
.addSubcommand(setchannel => setchannel
.setName('setchannel')
2021-09-18 06:28:41 -07:00
.setDescription('Set channel where membership screening approval request will be sent')
2021-09-17 11:13:58 -07:00
.addChannelOption(option => option
.setName('channel')
2021-09-18 06:28:41 -07:00
.setDescription('Select a channel where approval request will be sent')
2021-09-17 11:13:58 -07:00
.setRequired(true)
)
)
.addSubcommand(createmessage => createmessage
.setName('createmessage')
2021-09-18 06:28:41 -07:00
.setDescription('Create greeting message for membership screening into the channel. A message for new commers to read')
2021-09-17 11:13:58 -07:00
)
);
2021-09-16 23:54:32 -07:00
export const registerAllGlobalCommands = async () => {
Logger.log('info', `Registering all global interaction commands`);
2021-09-17 11:13:58 -07:00
await DiscordProvider.client.application?.commands.set(JSON.parse(JSON.stringify(GLOBAL_COMMANDS)));
2021-09-16 23:54:32 -07:00
}
export const unregisterAllGlobalCommands = async () => {
2021-09-18 06:28:41 -07:00
//const commands = await DiscordProvider.client.application?.commands.fetch();
2021-09-16 23:54:32 -07:00
2021-09-18 06:28:41 -07:00
//if(typeof commands === 'undefined') return;
//if(commands.size === 0) return;
2021-09-16 23:54:32 -07:00
Logger.log('info', `Unregistering all global interaction commands`);
2021-09-18 06:28:41 -07:00
await DiscordProvider.client.application?.commands.set([]);
/*for(const command of commands) {
2021-09-16 23:54:32 -07:00
await DiscordProvider.client.application?.commands.delete(command[1]);
2021-09-18 06:28:41 -07:00
}*/
2021-09-16 23:54:32 -07:00
}
export const registerAllGuildsCommands = async () => {
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;
Logger.log('info', `Registering all interaction commands on guild ${guildObject.name} (${guildObject.id})`);
2021-09-17 11:13:58 -07:00
await DiscordProvider.client.guilds.cache.get(guildObject.id)?.commands.set(JSON.parse(JSON.stringify(GUILD_COMMANDS)));
2021-09-16 23:54:32 -07:00
}
}
export const unregisterAllGuildsCommands = async () => {
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;
Logger.log('info', `Unregistering all interaction commands on guild ${guildObject.name} (${guildObject.id})`);
2021-09-18 06:28:41 -07:00
await DiscordProvider.client.guilds.cache.get(guildObject.id)?.commands.set([]);
//const commands = await guildObject.commands.fetch();
//if(commands.size === 0) continue;
/*for(const command of commands) {
2021-09-16 23:54:32 -07:00
try {
await DiscordProvider.client.guilds.cache.get(guildObject.id)?.commands.delete(command[1]);
} catch(err) {
Logger.log('error', `Cannot unregister all interaction commands on guild ${guildObject.name} (${guildObject.id})`);
}
2021-09-18 06:28:41 -07:00
}*/
2021-09-16 23:54:32 -07:00
}
}