some API typings

pull/17/head
TheCodedProf 3 years ago
parent 2ec2ba615c
commit 5129610998

@ -1,14 +1,17 @@
import type { Client } from 'discord.js';
import type { NucleusClient } from '../utils/client.js';
//@ts-expect-error
import express from "express";
//@ts-expect-error
import bodyParser from "body-parser";
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
//@ts-expect-error
import structuredClone from "@ungap/structured-clone";
const jsonParser = bodyParser.json();
const app = express();
const port = 10000;
const runServer = (client: Client) => {
const runServer = (client: NucleusClient) => {
app.get("/", (req, res) => {
res.status(200).send(client.ws.ping);
});
@ -17,20 +20,20 @@ const runServer = (client: Client) => {
const code = req.params.code;
const secret = req.body.secret;
if (secret === client.config.verifySecret) {
const guild = await client.guilds.fetch(client.verify[code].gID);
const guild = await client.guilds.fetch(client.verify[code]!.gID);
if (!guild) {
return res.status(404);
}
const member = await guild.members.fetch(client.verify[code].uID);
const member = await guild.members.fetch(client.verify[code]!.uID);
if (!member) {
return res.status(404);
}
if (member.roles.cache.has(client.verify[code].rID)) {
if (member.roles.cache.has(client.verify[code]!.rID)) {
return res.status(200);
}
await member.roles.add(client.verify[code].rID);
await member.roles.add(client.verify[code]!.rID);
const interaction = client.verify[code].interaction;
const interaction = client.verify[code]!.interaction;
if (interaction) {
interaction.editReply({
embeds: [
@ -57,7 +60,7 @@ const runServer = (client: Client) => {
},
list: {
memberId: entry(member.id, `\`${member.id}\``),
member: entry(member.id, renderUser(member))
member: entry(member.id, renderUser(member.user))
},
hidden: {
guild: guild.id
@ -77,7 +80,7 @@ const runServer = (client: Client) => {
const code = req.params.code;
if (client.verify[code]) {
try {
const interaction = client.verify[code].interaction;
const interaction = client.verify[code]!.interaction;
if (interaction) {
interaction.editReply({
embeds: [
@ -105,11 +108,11 @@ const runServer = (client: Client) => {
const code = req.params.code;
const secret = req.body.secret;
if (secret === client.config.verifySecret) {
const guild = await client.guilds.fetch(client.roleMenu[code].guild);
const guild = await client.guilds.fetch(client.roleMenu[code]!.guild);
if (!guild) {
return res.status(404);
}
const member = await guild.members.fetch(client.roleMenu[code].user);
const member = await guild.members.fetch(client.roleMenu[code]!.user);
if (!member) {
return res.status(404);
}
@ -123,7 +126,7 @@ const runServer = (client: Client) => {
const code = req.params.code;
if (client.roleMenu[code] !== undefined) {
try {
const interaction = client.roleMenu[code].interaction;
const interaction = client.roleMenu[code]!.interaction;
if (interaction) {
interaction.editReply({
embeds: [

@ -22,13 +22,7 @@ const command = (builder: SlashCommandSubcommandBuilder) =>
.addUserOption((option) => option.setName("member").setDescription("The member to view as").setRequired(true));
const callback = async (interaction: CommandInteraction): Promise<void> => {
/*
* {
categoryObject: channel[],
categoryObject: channel[],
"null": channel[]
}
*/
const m = await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true})
let channels: Record<string, GuildBasedChannel[]> = {"": []};
@ -105,7 +99,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
threads = channel.threads.cache.toJSON().map((t) => t as Discord.ThreadChannel);
}
const nsfw = ("nsfw" in channel ? channel.nsfw : false) && NSFWAvailable.includes(channelType)
const emojiName = channelTypeEmoji[channelType] + (nsfw ? "_NSFW" : "");
const emojiName = channelTypeEmoji[channelType.valueOf()] + (nsfw ? "_NSFW" : "");
const emoji = getEmojiByName("ICONS.CHANNEL." + (threads.length ? "THREAD_CHANNEL" : emojiName));
let current = `${emoji} ${channel.name}`;
if (threads.length) {

@ -8,7 +8,9 @@ import Discord, {
MessageComponentInteraction,
Role,
ButtonStyle,
AutocompleteInteraction
AutocompleteInteraction,
GuildChannel,
EmbedBuilder
} from "discord.js";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
@ -50,17 +52,17 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
});
let m: Message;
if (
interaction.options.getRole("role") ||
interaction.options.getChannel("channel") ||
interaction.options.getString("message")
interaction.options.get("role")?.role ||
interaction.options.get("channel")?.channel ||
interaction.options.get("message")?.value as string
) {
let role: Role | null;
let ping: Role | null;
let channel: Channel | null;
const message: string | null = interaction.options.getString("message");
const message: string | null = interaction.options.get("message")?.value as string | null;
try {
role = interaction.options.getRole("role") as Role | null;
ping = interaction.options.getRole("ping") as Role | null;
role = interaction.options.get("role")?.role as Role | null;
ping = interaction.options.get("ping")?.role as Role | null;
} catch {
return await interaction.editReply({
embeds: [
@ -73,7 +75,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
});
}
try {
channel = interaction.options.getChannel("channel") as Channel | null;
channel = interaction.options.get("channel")?.channel as Channel | null;
} catch {
return await interaction.editReply({
embeds: [
@ -94,13 +96,14 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
if (role) options.role = renderRole(role);
if (ping) options.ping = renderRole(ping);
if (channel) options.channel = renderChannel(channel);
if (channel) options.channel = renderChannel(channel as GuildChannel);
if (message) options.message = "\n> " + message;
const confirmation = await new confirmationMessage(interaction)
.setEmoji("GUILD.ROLES.EDIT", "GUILD.ROLES.DELETE")
.setEmoji("GUILD.ROLES.EDIT")
.setTitle("Welcome Events")
.setDescription(generateKeyValueList(options))
.setColor("Warning")
.setFailedMessage("Cancelled", "Warning", "GUILD.ROLES.DELETE") //TODO: Actual Message Needed
.setInverted(true)
.send(true);
if (confirmation.cancelled) return;
@ -130,7 +133,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
};
if (role) list.role = entry(role.id, renderRole(role));
if (ping) list.ping = entry(ping.id, renderRole(ping));
if (channel) list.channel = entry(channel.id, renderChannel(channel.id));
if (channel) list.channel = entry(channel.id, renderChannel(channel as GuildChannel));
if (message) list.message = entry(message, `\`${message}\``);
const data = {
meta: {
@ -185,19 +188,19 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
`**Message:** ${config.welcome.message ? `\n> ${config.welcome.message}` : "*None set*"}\n` +
`**Role:** ${
config.welcome.role
? renderRole(await interaction.guild!.roles.fetch(config.welcome.role))
? renderRole((await interaction.guild!.roles.fetch(config.welcome.role))!)
: "*None set*"
}\n` +
`**Ping:** ${
config.welcome.ping
? renderRole(await interaction.guild!.roles.fetch(config.welcome.ping))
? renderRole((await interaction.guild!.roles.fetch(config.welcome.ping))!)
: "*None set*"
}\n` +
`**Channel:** ${
config.welcome.channel
? config.welcome.channel == "dm"
? "DM"
: renderChannel(await interaction.guild!.channels.fetch(config.welcome.channel))
: renderChannel((await interaction.guild!.channels.fetch(config.welcome.channel))!)
: "*None set*"
}`
)
@ -293,7 +296,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}
} while (!timedOut);
await interaction.editReply({
embeds: [m.embeds[0]!.setFooter({ text: "Message timed out" })],
embeds: [new EmbedBuilder(m.embeds[0]!.data).setFooter({ text: "Message timed out" })],
components: []
});
};

Loading…
Cancel
Save