Skip to content

Commit 2a39fe5

Browse files
committed
Create available-single-letters.ts
1 parent 55686be commit 2a39fe5

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import Command from "../../classes/Command";
2+
import ExtendedClient from "../../classes/ExtendedClient";
3+
import { ChatInputCommandInteraction, ColorResolvable } from "discord.js";
4+
5+
import axios from "axios";
6+
import { emojis as emoji } from "../../../config.json";
7+
8+
const command: Command = {
9+
name: "available-single-letters",
10+
description: "Check if there are any available single letter subdomains.",
11+
options: [],
12+
botPermissions: [],
13+
requiredRoles: [],
14+
cooldown: 5,
15+
enabled: true,
16+
deferReply: true,
17+
ephemeral: false,
18+
async execute(
19+
interaction: ChatInputCommandInteraction,
20+
client: ExtendedClient,
21+
Discord: typeof import("discord.js")
22+
) {
23+
try {
24+
const subdomains = "abcdefghijklmnopqrstuvwxyz0123456789".split("");
25+
26+
const res = (await axios.get("https://raw.is-a.dev/v2.json")).data;
27+
28+
const taken = res.map((entry: any) => entry.subdomain);
29+
const available = subdomains.filter((subdomain) => !taken.includes(subdomain));
30+
31+
if (!available.length) {
32+
const noAvailable = new Discord.EmbedBuilder()
33+
.setColor(client.config.embeds.error as ColorResolvable)
34+
.setDescription(`${emoji.cross} No single letter subdomains are available.`);
35+
36+
await interaction.editReply({ embeds: [noAvailable] });
37+
return;
38+
}
39+
40+
const availableList = available.map((subdomain) => `- \`${subdomain}.is-a.dev\``).join("\n");
41+
42+
const availableEmbed = new Discord.EmbedBuilder()
43+
.setColor(client.config.embeds.default as ColorResolvable)
44+
.setTitle("Available Single Letter Subdomains")
45+
.setDescription(availableList)
46+
.setTimestamp()
47+
48+
await interaction.editReply({ embeds: [availableEmbed] });
49+
} catch (err) {
50+
client.logCommandError(err, interaction, Discord);
51+
}
52+
}
53+
};
54+
55+
export = command;

0 commit comments

Comments
 (0)