Skip to content

Commit

Permalink
Replace OLL with switch-case
Browse files Browse the repository at this point in the history
  • Loading branch information
TAEMBO committed Sep 18, 2024
1 parent a61e8cd commit 7f67ca2
Show file tree
Hide file tree
Showing 14 changed files with 556 additions and 397 deletions.
57 changes: 44 additions & 13 deletions src/commands/chatInput/case.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ApplicationCommandOptionType, EmbedBuilder, PermissionFlagsBits } from "discord.js";
import { Command } from "#structures";
import { formatString, formatTime, formatUser, lookup } from "#util";
import { formatString, formatTime, formatUser } from "#util";

export default new Command<"chatInput">({
async run(interaction) {
const caseid = interaction.options.getInteger("id");

await lookup({
async view() {
switch (interaction.options.getSubcommand()) {
case "view": {
const punishment = await interaction.client.punishments.data.findById(caseid);

if (!punishment) return await interaction.reply("A case with that ID wasn't found!");
Expand All @@ -24,13 +24,34 @@ export default new Command<"chatInput">({
.setColor(interaction.client.config.EMBED_COLOR)
.setTimestamp(punishment.time);

if (punishment.duration) embed.addFields({ name: "🔹 Duration", value: formatTime(punishment.duration, 100), inline: true }, { name: "\u200b", value: "\u200b", inline: true });
if (punishment.expired) embed.addFields({ name: "🔹 Expired", value: `This case has been overwritten by Case #${cancelledBy?.id} for reason \`${cancelledBy?.reason}\`` });
if (punishment.cancels) embed.addFields({ name: "🔹 Overwrites", value: `This case overwrites Case #${cancels?.id} \`${cancels?.reason}\`` });
if (punishment.duration) embed.addFields(
{
name: "🔹 Duration",
value: formatTime(punishment.duration, 100),
inline: true
},
{
name: "\u200b",
value: "\u200b",
inline: true
}
);

if (punishment.expired) embed.addFields({
name: "🔹 Expired",
value: `This case has been overwritten by Case #${cancelledBy?.id} for reason \`${cancelledBy?.reason}\``
});

if (punishment.cancels) embed.addFields({
name: "🔹 Overwrites",
value: `This case overwrites Case #${cancels?.id} \`${cancels?.reason}\``
});

await interaction.reply({ embeds: [embed] });
},
async member() {

break;
};
case "member": {
const user = interaction.options.getUser("user", true);
const pageNumber = interaction.options.getInteger("page") ?? 1;
const punishments = await interaction.client.punishments.data.find();
Expand All @@ -50,18 +71,28 @@ export default new Command<"chatInput">({
await interaction.reply({ embeds: [new EmbedBuilder()
.setTitle(`Punishments for ${user.tag}`)
.setDescription(formatUser(user))
.setFooter({ text: `${userPunishments.length} total punishments. Viewing page ${pageNumber} out of ${Math.ceil(userPunishments.length / 25)}.` })
.setFooter({
text: `${userPunishments.length} total punishments. Viewing page ${pageNumber} out of ${Math.ceil(userPunishments.length / 25)}.`
})
.setColor(interaction.client.config.EMBED_COLOR)
.addFields(userPunishments.slice((pageNumber - 1) * 25, pageNumber * 25))
] });
},
async update() {

break;
};
case "update": {
const reason = interaction.options.getString("reason", true);

await interaction.client.punishments.data.findByIdAndUpdate(caseid, { reason });
await interaction.reply({ embeds: [new EmbedBuilder().setColor(interaction.client.config.EMBED_COLOR).setTitle(`Case #${caseid} updated`).setDescription(`**New reason:** ${reason}`)] });

await interaction.reply({ embeds: [new EmbedBuilder()
.setColor(interaction.client.config.EMBED_COLOR)
.setTitle(`Case #${caseid} updated`)
.setDescription(`**New reason:** ${reason}`)
] });
break;
}
}, interaction.options.getSubcommand());
}
},
data: {
name: "case",
Expand Down
29 changes: 20 additions & 9 deletions src/commands/chatInput/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import * as utilities from "#util";

export default new structures.Command<"chatInput">({
async run(interaction) {
if (!interaction.client.config.devWhitelist.includes(interaction.user.id)) return await interaction.reply("You're not allowed to use dev commands.");
if (!interaction.client.config.devWhitelist.includes(interaction.user.id)) {
return await interaction.reply("You're not allowed to use dev commands.");
}

await utilities.lookup({
async eval() {
sleep; fs; Discord; // Imports possibly used in eval
switch (interaction.options.getSubcommand()) {
case "eval": {
sleep; fs; Discord; utilities; // Imports possibly used in eval
const { client } = interaction;
const code = interaction.options.getString("code", true);
const depth = interaction.options.getInteger("depth") ?? 1;
Expand All @@ -47,7 +49,9 @@ export default new structures.Command<"chatInput">({

const msgPayload = {
embeds: [embed],
components: [new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setCustomId("stack").setStyle(ButtonStyle.Primary).setLabel("Stack"))],
components: [new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder().setCustomId("stack").setStyle(ButtonStyle.Primary).setLabel("Stack")
)],
fetchReply: true as const
};

Expand Down Expand Up @@ -82,20 +86,27 @@ export default new structures.Command<"chatInput">({
...fsPub.map(x => x[1].ftp.password)
]) output = output.replace(credential, "CREDENTIAL_LEAK");

embed.addFields({ name: `Output • ${(performance.now() - now).toFixed(5)}ms`, value: `\`\`\`${output.slice(0, 1016)}\n\`\`\`` });
embed.addFields({
name: `Output • ${(performance.now() - now).toFixed(5)}ms`,
value: `\`\`\`${output.slice(0, 1016)}\n\`\`\``
});

await interaction.reply({ embeds: [embed] }).catch(() => interaction.channel!.send({ embeds: [embed] }));
},
async restart() {

break;
};
case "restart": {
await interaction.reply("Compiling...");

exec("tsc", async (error, stdout) => {
if (error) return await interaction.editReply(codeBlock(stdout.slice(0, 1950)));

await interaction.editReply("Restarting...").then(() => process.exit(-1));
});

break;
}
}, interaction.options.getSubcommand());
}
},
data: {
name: "dev",
Expand Down
146 changes: 80 additions & 66 deletions src/commands/chatInput/faq.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,90 @@
import { ActionRowBuilder, ApplicationCommandOptionType, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
import { Command } from "#structures";
import { fsServers, lookup } from "#util";
import { fsServers } from "#util";

export default new Command<"chatInput">({
async run(interaction) {
const isFromTicket = interaction.channel!.parentId === interaction.client.config.mainServer.categories.activeTickets;
const content = interaction.options.getUser("user", false)?.toString() || "";

await lookup({
staff: () => interaction.reply({ content, components: [
new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setStyle(ButtonStyle.Link).setURL(interaction.client.config.resources.faqStaffButtonRedirect).setLabel("Apply for MP Staff"))
] }),
troll: () => interaction.reply({ content, embeds: [new EmbedBuilder()
.setTitle("Reporting trolls")
.setColor(interaction.client.config.EMBED_COLOR)
.setImage(interaction.client.config.resources.faqTrollEmbedImage)
.setDescription([
`If a player is causing problems on a server, ${isFromTicket ? "let us know" : `don"t hesitate to send a report to ${fsServers.getPublicAll().map(([_, x]) => `<#${x.channelId}>`).join(" or ")}`} with:`,
"",
[
"- The name of the player",
"- What they are doing",
"- A picture or video as proof if possible",
isFromTicket ? "" : `- The <@&${interaction.client.config.mainServer.roles.mpStaff}> tag to notify staff`
].join("\n"),
"",
`Please do not ping or DM individual staff members${isFromTicket ? "" : `, use the <@&${interaction.client.config.mainServer.roles.mpStaff}> tag as mentioned above`}.`,
`Check <#${interaction.client.config.mainServer.channels.mpRulesAndInfo}> to see what a good reason could be for a player report.`
].join("\n"))
] }),
appeal: () => interaction.reply([
`${content} `,
"\n",
"If you would like to appeal your ban on our MP servers, ",
`head to <#${interaction.client.config.mainServer.channels.support}> and open an [MP Support](${interaction.client.config.resources.faqAppealSupportMsg}) ticket to privately discuss it with MP Staff.`
].join("")),
todo: () => interaction.reply({ content, embeds: [new EmbedBuilder()
.setTitle("To-do")
.setColor(interaction.client.config.EMBED_COLOR)
.setFooter({ text: "Note that not every task listed might be available to do at the time, so do your due dilligence to see what needs doing in the moment." })
.setFields(...fsServers.getPublicAll().map(([_, x]) => ({ name: x.fullName, value: "- " + x.todo.join("\n- ") })))
] }),
filters: () => interaction.reply({ content, embeds: [new EmbedBuilder()
.setColor(interaction.client.config.EMBED_COLOR)
.setTitle("Please note that servers may \"ghost\" and not show up until you've refreshed your MP menu several times.")
.setImage(interaction.client.config.resources.faqFiltersEmbedImage)
] }),
equipment: () => interaction.reply([
content,
"Purchasing new equipment can cause large impacts, including:",
"- Increased slot amounts",
"- Increased file sizes, causing larger amounts of lag",
"Therefore, we try to refrain from purchasing any new equipment."
].join("\n")),
passwords: () => interaction.reply([
content,
"\n",
"We run multiple farms for each of our public servers to aid managing them. ",
"Players who join our servers will only ever need to join the green farm, labeled with our Discord invite link, which should never have a password set on it. ",
"All other farms contain \"Staff\" in their name, indicating that no one except staff should ever need to access them. ",
"If one of our public servers are locked, the password to them can be found in their respective channel's pinned messages. Note that we may not use that password at all times."
].join("")),
terrain: () => interaction.reply([
content,
"\n",
"When you join one of our servers, you may encounter terrain with jagged edges or extreme deformations into the ground. ",
"This however is not the actual terrain formation on the server, and thus has no affect on where you can drive around. ",
"These are simply visual glitches that are only seen on your end, so don't fret that the server was possibly griefed!"
].join(""))
}, interaction.options.getString("questions", true));
switch (interaction.options.getString("question", true)) {
case "staff": {
await interaction.reply({ content, components: [
new ActionRowBuilder<ButtonBuilder>().setComponents(
new ButtonBuilder()
.setStyle(ButtonStyle.Link)
.setURL(interaction.client.config.resources.faqStaffButtonRedirect)
.setLabel("Apply for MP Staff")
)
] });

break;
};
case "troll": {
await interaction.reply({ content, embeds: [new EmbedBuilder()
.setTitle("Reporting trolls")
.setColor(interaction.client.config.EMBED_COLOR)
.setImage(interaction.client.config.resources.faqTrollEmbedImage)
.setDescription([
`If a player is causing problems on a server, ${isFromTicket ? "let us know" : `don"t hesitate to send a report to ${fsServers.getPublicAll().map(([_, x]) => `<#${x.channelId}>`).join(" or ")}`} with:`,
"",
[
"- The name of the player",
"- What they are doing",
"- A picture or video as proof if possible",
isFromTicket ? "" : `- The <@&${interaction.client.config.mainServer.roles.mpStaff}> tag to notify staff`
].join("\n"),
"",
`Please do not ping or DM individual staff members${isFromTicket ? "" : `, use the <@&${interaction.client.config.mainServer.roles.mpStaff}> tag as mentioned above`}.`,
`Check <#${interaction.client.config.mainServer.channels.mpRulesAndInfo}> to see what a good reason could be for a player report.`
].join("\n"))
] });

break;
};
case "appeal": {
await interaction.reply([
`${content} `,
"\n",
"If you would like to appeal your ban on our MP servers, ",
`head to <#${interaction.client.config.mainServer.channels.support}> and open an [MP Support](${interaction.client.config.resources.faqAppealSupportMsg}) ticket to privately discuss it with MP Staff.`
].join(""));

break;
};
case "todo": {
await interaction.reply({ content, embeds: [new EmbedBuilder()
.setTitle("To-do")
.setColor(interaction.client.config.EMBED_COLOR)
.setFooter({
text: "Note that not every task listed might be available to do at the time, so do your due dilligence to see what needs doing in the moment."
})
.setFields(...fsServers.getPublicAll().map(([_, x]) => ({ name: x.fullName, value: "- " + x.todo.join("\n- ") })))
] });

break;
};
case "filters": {
await interaction.reply({ content, embeds: [new EmbedBuilder()
.setColor(interaction.client.config.EMBED_COLOR)
.setTitle("Please note that servers may \"ghost\" and not show up until you've refreshed your MP menu several times.")
.setImage(interaction.client.config.resources.faqFiltersEmbedImage)
] });

break;
};
case "equipment": {
await interaction.reply([
content,
"Purchasing new equipment can cause large impacts, including:",
"- Increased slot amounts",
"- Increased file sizes, causing larger amounts of lag",
"Therefore, we try to refrain from purchasing any new equipment."
].join("\n"));

break;
};
}
},
data: {
name: "faq",
Expand All @@ -84,9 +100,7 @@ export default new Command<"chatInput">({
{ name: "Appeal an MP ban", value: "appeal" },
{ name: "What to do on MP servers", value: "todo" },
{ name: "MP filters to join", value: "filters" },
{ name: "Buying equipment", value: "equipment" },
{ name: "Getting passwords", value: "passwords" },
{ name: "Terrain glitches", value: "terrain" }
{ name: "Buying equipment", value: "equipment" }
],
required: true
},
Expand Down
Loading

0 comments on commit 7f67ca2

Please sign in to comment.