Updated ESlint Config and Housekeeping

This commit is contained in:
Ahmad 2024-11-16 19:05:52 -05:00
parent a65a38f00a
commit 5d5ca66e5d
No known key found for this signature in database
GPG key ID: 8FD8A93530D182BF
12 changed files with 512 additions and 107 deletions

17
src/commands/ping.ts Normal file
View file

@ -0,0 +1,17 @@
import { SlashCommandBuilder, CommandInteraction } from "discord.js";
interface Command {
data: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">;
execute: (interaction: CommandInteraction) => Promise<void>;
}
const command: Command = {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Check the latency from you to the bot"),
execute: async (interaction) => {
await interaction.reply(`Pong! Latency: ${Date.now() - interaction.createdTimestamp}ms`);
},
};
export default command;

111
src/commands/rules.ts Normal file
View file

@ -0,0 +1,111 @@
import {
SlashCommandBuilder,
CommandInteraction,
EmbedBuilder,
} from "discord.js";
interface Command {
data: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">;
execute: (interaction: CommandInteraction) => Promise<void>;
}
const rulesEmbed = new EmbedBuilder()
.setColor(0x0099ff)
.setTitle("Server Rules")
.setAuthor({
name: "Poixixel",
iconURL:
"https://cdn.discordapp.com/avatars/1052017329376071781/922947c726d7866d313744186c42ef49.webp",
})
.setDescription(
"These are the rules for the server. Please read and follow them carefully."
)
.addFields(
{
name: "**Rule #1: Be respectful**",
value:
"Treat everyone with kindness. No harassment, bullying, hate speech, or toxic behavior.",
},
{
name: "**Rule #2: Keep it Family-Friendly**",
value:
"No explicit content, including NSFW images, language, or discussions. This is a safe space for everyone.",
},
{
name: "**Rule #3: Use Common Sense**",
value:
"Think before you act or post. If something seems questionable, its probably best not to do it.",
},
{
name: "**Rule #4: No Spamming**",
value:
"Avoid excessive messages, emoji use, or CAPS LOCK. Keep the chat clean and readable.",
},
{
name: "**Rule #5: No Raiding**",
value:
"Do not disrupt the server or other servers with spam, unwanted content, or malicious behavior.",
},
{
name: "**Rule #6: No Self-Promotion**",
value:
"Do not advertise your own content or other servers without permission from staff.",
},
{
name: "**Rule #7: No Impersonation**",
value:
"Do not pretend to be someone else, including staff or other members.",
},
{
name: "**Rule #8: No Violence**",
value:
"Do not post or share content that is offensive, harmful, or contains violent or dangerous content.",
},
{
name: "**Rule #9: No Doxxing or Sharing Personal Information**",
value:
"Protect your privacy and the privacy of others. Do not share personal details.",
},
{
name: "**Rule #10: No Ping Abuse**",
value:
"Do not ping staff members unless it's absolutely necessary. Use pings responsibly for all members.",
},
{
name: "**Rule #11: Use Appropriate Channels**",
value:
"Post content in the right channels. Off-topic content may be moved or deleted.",
},
{
name: "**Rule #12: Follow Discord's ToS and Community Guidelines**",
value:
"All members must adhere to Discords Terms of Service and Community Guidelines.",
},
{
name: "**Rule #13: Moderator Discretion**",
value:
"Moderators reserve the right to moderate at their discretion. If you feel mistreated, please create a support ticket.",
},
{
name: "**Disclaimer:**",
value:
"**These rules may be updated at any time. It is your responsibility to review them regularly. Moderators and admins have the authority to enforce these rules and take appropriate action.**",
}
)
.setTimestamp()
.setFooter({
text: "Sent by the Poixpixel Bot",
iconURL:
"https://cdn.discordapp.com/avatars/1052017329376071781/922947c726d7866d313744186c42ef49.webp",
});
const command: Command = {
data: new SlashCommandBuilder()
.setName("rules")
.setDescription("Sends the server rules"),
execute: async (interaction) => {
await interaction.reply({ embeds: [rulesEmbed] });
},
};
export default command;

19
src/commands/server.ts Normal file
View file

@ -0,0 +1,19 @@
import { SlashCommandBuilder, CommandInteraction } from "discord.js";
interface Command {
data: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">;
execute: (interaction: CommandInteraction) => Promise<void>;
}
const command: Command = {
data: new SlashCommandBuilder()
.setName("server")
.setDescription("Provides information about the server."),
execute: async (interaction) => {
await interaction.reply(
`The server ${interaction?.guild?.name} has ${interaction?.guild?.memberCount} members and was created on ${interaction?.guild?.createdAt}. It is ${new Date().getFullYear() - interaction?.guild?.createdAt?.getFullYear()!} years old.`
);
},
};
export default command;

29
src/commands/user.ts Normal file
View file

@ -0,0 +1,29 @@
import {
SlashCommandBuilder,
CommandInteraction,
GuildMember,
} from "discord.js";
interface Command {
data: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">;
execute: (interaction: CommandInteraction) => Promise<void>;
}
const command: Command = {
data: new SlashCommandBuilder()
.setName("user")
.setDescription("Provides information about the user."),
execute: async (interaction) => {
if (interaction.member instanceof GuildMember) {
await interaction.reply(
`This command was run by ${interaction.user.username}, who joined this server on ${interaction.member.joinedAt}.`
);
} else {
await interaction.reply(
`This command was run by ${interaction.user.username}.`
);
}
},
};
export default command;

79
src/discord-bot.ts Normal file
View file

@ -0,0 +1,79 @@
import fs from "node:fs";
import path from "node:path";
import { Client, Collection, Events, GatewayIntentBits } from "discord.js";
import { deployCommands } from "./util/deployCommand.js";
const config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
const { token } = config;
const client: any = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
try {
const __dirname = path.resolve();
const commandsPath = path.join(__dirname, "/target/commands/");
const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const filePath = path.join("file://", commandsPath, file);
const commandModule = await import(filePath);
const command = commandModule.default;
if (
command instanceof Object &&
"data" in command &&
"execute" in command
) {
client.commands.set(command.data.name, command);
} else {
console.log(
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
);
}
}
} catch (error: any) {
console.log(`Error while getting commands up: ${error}`);
}
try {
await deployCommands();
} catch (error: any) {
console.log(`Error while registering commands: ${error}`);
}
client.once(Events.ClientReady, (c: any) => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
client.on(Events.InteractionCreate, async (interaction: any) => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({
content: "There was an error while executing this command!",
ephemeral: true,
});
} else {
await interaction.reply({
content: "There was an error while executing this command!",
ephemeral: true,
});
}
}
});
client.login(token);

52
src/util/deployCommand.ts Normal file
View file

@ -0,0 +1,52 @@
import { REST, Routes } from "discord.js";
import fs from "fs";
import path from "path";
const config = JSON.parse(fs.readFileSync("./config.json", "utf8"));
const { token, clientId, guildId } = config;
const __dirname = path.resolve();
const commandsPath = path.join(__dirname, "target", "commands");
const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".js"));
const rest = new REST({ version: "9" }).setToken(token);
export const deployCommands = async () => {
try {
console.log(
`Started refreshing ${commandFiles.length} application (/) commands.`
);
const commands = commandFiles.map(async (file) => {
const filePath = path.join("file://", commandsPath, file);
const commandModule = await import(filePath);
const command = commandModule.default;
if (command instanceof Object && "data" in command) {
return command.data.toJSON();
} else {
console.log(
`[WARNING] The command at ${filePath} is missing a required "data" property.`
);
return null;
}
});
const validCommands = await Promise.all(
commands.filter((command) => command !== null)
);
const data: any = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: validCommands }
);
console.log(
`Successfully reloaded ${data.length} application (/) commands.`
);
} catch (error) {
console.error(error);
}
};