diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..75e7c9d --- /dev/null +++ b/.prettierignore @@ -0,0 +1,13 @@ +# Prod +**/dist +**/node_modules +**/persist + +# Files +**/.env +**/.prettierrc +**/LICENSE +**/package-lock.json +**/package.json +**/README.md +**/tsconfig.json diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..694ed4c --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "trailingComma": "none", + "arrowParens": "avoid" +} diff --git a/package.json b/package.json index e79972e..92d2ae1 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "build": "rm -rf ./dist && tsc -p .", "start": "node ./dist/main.js", + "prettier": "if prettier -v >/dev/null 2>&1; then prettier . --write; else npx prettier . --write; fi", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "powermaker450", diff --git a/src/bot/client.ts b/src/bot/client.ts index d377bfb..e4d1b43 100644 --- a/src/bot/client.ts +++ b/src/bot/client.ts @@ -19,5 +19,5 @@ import { Client } from "discord.js"; export const BotClient = new Client({ - intents: ["Guilds", "GuildMessages", "DirectMessages"], + intents: ["Guilds", "GuildMessages", "DirectMessages"] }); diff --git a/src/bot/deploy-commands.ts b/src/bot/deploy-commands.ts index a075504..90a9ba8 100644 --- a/src/bot/deploy-commands.ts +++ b/src/bot/deploy-commands.ts @@ -24,8 +24,8 @@ import Logger from "../utils/Logger"; const logger = new Logger("Deployer"); -const commandsData = Object.values(commands).map((command) => - command.data.toJSON(), +const commandsData = Object.values(commands).map(command => + command.data.toJSON() ); const rest = new REST({ version: "9" }).setToken(BOT_TOKEN); @@ -35,7 +35,7 @@ export async function deployCommands({ guildId }: DeployCommandsProps) { logger.log("Started refreshing (/) commands."); await rest.put(Routes.applicationGuildCommands(BOT_ID, guildId), { - body: commandsData, + body: commandsData }); logger.log("Successfully reloaded (/) commands."); diff --git a/src/commands/confess.ts b/src/commands/confess.ts index 8be03c8..0f903a5 100644 --- a/src/commands/confess.ts +++ b/src/commands/confess.ts @@ -20,7 +20,7 @@ import { CommandInteraction, EmbedBuilder, SlashCommandBuilder, - TextChannel, + TextChannel } from "discord.js"; import { BotClient } from "../bot"; import { dt } from "../main"; @@ -33,11 +33,11 @@ const logger = new Logger("(/) confess"); export const data = new SlashCommandBuilder() .setName("confess") .setDescription("Send a confession") - .addStringOption((option) => + .addStringOption(option => option .setName("message") .setRequired(true) - .setDescription("What you want to confess"), + .setDescription("What you want to confess") ); export async function execute(interaction: CommandInteraction) { @@ -45,7 +45,7 @@ export async function execute(interaction: CommandInteraction) { if (dt.isBanned(interaction.guild?.id!, interaction.user.id)) { return interaction.reply({ content: "You are banned from confessions in this server!", - ephemeral: true, + ephemeral: true }); } @@ -53,7 +53,7 @@ export async function execute(interaction: CommandInteraction) { return interaction.reply({ content: "The bot hasn't been set up yet! Ask the server admins to set it up.", - ephemeral: true, + ephemeral: true }); } @@ -80,22 +80,22 @@ export async function execute(interaction: CommandInteraction) { .addFields( { name: "Author", - value: interaction.user.displayName, + value: interaction.user.displayName }, { name: "Author ID", - value: interaction.user.id, - }, + value: interaction.user.id + } ); const message = await ( BotClient.channels.cache.get(confessChannel!) as TextChannel ).send({ - embeds: [userConfessionEmbed], + embeds: [userConfessionEmbed] }); await (BotClient.channels.cache.get(adminChannel!) as TextChannel).send({ - embeds: [adminConfessionEmbed], + embeds: [adminConfessionEmbed] }); dt.addConfession( @@ -103,12 +103,12 @@ export async function execute(interaction: CommandInteraction) { messageId, interaction.user.displayName, interaction.user.id, - messageContent, + messageContent ); return interaction.reply({ content: "Confession sent!", - ephemeral: true, + ephemeral: true }); } catch (err) { logger.error("An error occured:", err); diff --git a/src/commands/confessban.ts b/src/commands/confessban.ts index af6bc1f..39e5d7e 100644 --- a/src/commands/confessban.ts +++ b/src/commands/confessban.ts @@ -19,7 +19,7 @@ import { CommandInteraction, PermissionFlagsBits, - SlashCommandBuilder, + SlashCommandBuilder } from "discord.js"; import { dt } from "../main"; import Logger from "../utils/Logger"; @@ -29,11 +29,11 @@ const logger = new Logger("(/) confessban"); export const data = new SlashCommandBuilder() .setName("confessban") .setDescription("Ban a user from submitting confessions.") - .addStringOption((option) => + .addStringOption(option => option .setName("id") .setDescription("The confession ID to ban") - .setRequired(true), + .setRequired(true) ) .setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers); @@ -41,18 +41,18 @@ export async function execute(interaction: CommandInteraction) { const result = dt.addBan( interaction.guild?.id!, // @ts-ignore - interaction.options.getString("id"), + interaction.options.getString("id") ); try { return result ? interaction.reply({ content: "User was banned.", - ephemeral: true, + ephemeral: true }) : interaction.reply({ content: "No confession with that ID was found.", - ephemeral: true, + ephemeral: true }); } catch (err) { logger.error("An error occured:", err); diff --git a/src/commands/confessdel.ts b/src/commands/confessdel.ts index 8359723..e334005 100644 --- a/src/commands/confessdel.ts +++ b/src/commands/confessdel.ts @@ -20,7 +20,7 @@ import { CommandInteraction, EmbedBuilder, SlashCommandBuilder, - TextChannel, + TextChannel } from "discord.js"; import { dt } from "../main"; import { BotClient } from "../bot"; @@ -32,8 +32,8 @@ const logger = new Logger("(/) confessdel"); export const data = new SlashCommandBuilder() .setName("confessdel") .setDescription("Deletes a confession") - .addStringOption((option) => - option.setName("id").setDescription("The confession id").setRequired(true), + .addStringOption(option => + option.setName("id").setDescription("The confession id").setRequired(true) ); export async function execute(interaction: CommandInteraction) { @@ -41,7 +41,7 @@ export async function execute(interaction: CommandInteraction) { return interaction.reply({ content: "The bot hasn't been set up yet! Ask the server admins to set it up.", - ephemeral: true, + ephemeral: true }); } @@ -53,7 +53,7 @@ export async function execute(interaction: CommandInteraction) { try { const confession = dt.getConfession( interaction.guild?.id!, - idVal, + idVal )?.messageId; const channelId = dt.getGuildInfo(interaction.guild?.id!)?.settings .confessChannel!; @@ -65,9 +65,9 @@ export async function execute(interaction: CommandInteraction) { await (BotClient.channels.cache.get(channelId) as TextChannel).messages .fetch(confession!) - .then((e) => { + .then(e => { e.edit({ - embeds: [emptyEmbed], + embeds: [emptyEmbed] }); }); @@ -75,7 +75,7 @@ export async function execute(interaction: CommandInteraction) { return interaction.reply({ content: "Confession removed.", - ephemeral: true, + ephemeral: true }); } catch (err) { logger.error("An error occured:", err); @@ -84,7 +84,7 @@ export async function execute(interaction: CommandInteraction) { return interaction.reply({ content: "Either the confession wasn't found or you may not be allowed to remove it.", - ephemeral: true, + ephemeral: true }); } } diff --git a/src/commands/confesspardon.ts b/src/commands/confesspardon.ts index 0c15f14..22e589f 100644 --- a/src/commands/confesspardon.ts +++ b/src/commands/confesspardon.ts @@ -19,7 +19,7 @@ import { CommandInteraction, PermissionFlagsBits, - SlashCommandBuilder, + SlashCommandBuilder } from "discord.js"; import { dt } from "../main"; import Logger from "../utils/Logger"; @@ -29,11 +29,11 @@ const logger = new Logger("(/) confesspardon"); export const data = new SlashCommandBuilder() .setName("confesspardon") .setDescription("Unbans a user from confessions") - .addStringOption((option) => + .addStringOption(option => option .setName("id") .setDescription("The confession ID to unban") - .setRequired(true), + .setRequired(true) ) .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages); @@ -41,18 +41,18 @@ export function execute(interaction: CommandInteraction) { const result = dt.removeBan( interaction.guild?.id!, // @ts-ignore - interaction.options.getString("id"), + interaction.options.getString("id") ); try { return result ? interaction.reply({ content: "User was unbanned.", - ephemeral: true, + ephemeral: true }) : interaction.reply({ content: "No confession with that ID was found.", - ephemeral: true, + ephemeral: true }); } catch (err) { logger.error("An error occured:", err); diff --git a/src/commands/index.ts b/src/commands/index.ts index b89843e..58af41e 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -29,5 +29,5 @@ export const commands = { confessban, confesspardon, ping, - setup, + setup }; diff --git a/src/commands/setup.ts b/src/commands/setup.ts index b7cf26c..7594fe6 100644 --- a/src/commands/setup.ts +++ b/src/commands/setup.ts @@ -23,7 +23,7 @@ import { CommandInteraction, ComponentType, PermissionFlagsBits, - SlashCommandBuilder, + SlashCommandBuilder } from "discord.js"; import { dt } from "../main"; import Logger from "../utils/Logger"; @@ -39,7 +39,7 @@ export async function execute(interaction: CommandInteraction) { if (dt.checkSetup(interaction.guild?.id!)) { return interaction.reply({ content: "This guild has already been set up!", - ephemeral: true, + ephemeral: true }); } @@ -58,20 +58,20 @@ export async function execute(interaction: CommandInteraction) { const response = await interaction.reply({ content: `# Let's get started, ${interaction.user.displayName}!\nFirst, let's choose a channel for your confessions.`, ephemeral: true, - components: [channelRow], + components: [channelRow] }); const collector = response.createMessageComponentCollector({ componentType: ComponentType.ChannelSelect, - time: 45_000, + time: 45_000 }); - collector.on("collect", async (i) => { + collector.on("collect", async i => { confessChannel = i.values[0]; await i.update({ content: "Awesome!", - components: [], + components: [] }); collector.stop(); @@ -83,55 +83,55 @@ export async function execute(interaction: CommandInteraction) { const logChannelRow = new ActionRowBuilder().addComponents( - logChannelList, + logChannelList ); const logResponse = await interaction.followUp({ content: "# Now, select a logging channel, for moderation purposes.", ephemeral: true, - components: [logChannelRow], + components: [logChannelRow] }); const logCollector = logResponse.createMessageComponentCollector({ componentType: ComponentType.ChannelSelect, - time: 45_000, + time: 45_000 }); - logCollector.on("collect", async (ij) => { + logCollector.on("collect", async ij => { logChannel = ij.values[0]; await ij.update({ content: "Setup Complete!", - components: [], + components: [] }); dt.setup(guildId!, { confessChannel: confessChannel, modChannel: logChannel, - bans: [], + bans: [] }); logCollector.stop(); }); - logCollector.on("end", (content) => { + logCollector.on("end", content => { // If there is no content, follow up with an error message. !content.size && interaction.followUp({ content: "No channel selected. Please try again.", ephemeral: true, - components: [], + components: [] }); }); }); - collector.on("end", (collected) => { + collector.on("end", collected => { // Same as above logCollector end !collected.size && interaction.followUp({ content: "No channel selected. Try again.", ephemeral: true, - components: [], + components: [] }); }); } catch (err) { diff --git a/src/main.ts b/src/main.ts index d5e867c..3f25589 100644 --- a/src/main.ts +++ b/src/main.ts @@ -24,20 +24,20 @@ import Logger from "./utils/Logger"; export const dt = new StoreMan(StoreMan.checkFile()); const logger = new Logger("Main"); -BotClient.once("ready", (client) => { +BotClient.once("ready", client => { logger.log(`We're ready! Logged in as ${client.user.tag}`); }); -BotClient.on("guildCreate", async (guild) => { +BotClient.on("guildCreate", async guild => { await deployCommands({ guildId: guild.id }); }); -BotClient.on("guildDelete", (guild) => { +BotClient.on("guildDelete", guild => { logger.log(`${guild.name} didn't want us anymore... :(`); dt.clearSettings(guild.id); }); -BotClient.on("interactionCreate", async (interaction) => { +BotClient.on("interactionCreate", async interaction => { if (!interaction.isCommand()) { return; } diff --git a/src/storeman/client.ts b/src/storeman/client.ts index 3bc7e29..eea6454 100644 --- a/src/storeman/client.ts +++ b/src/storeman/client.ts @@ -38,14 +38,14 @@ export class StoreMan { id: string, author: string, authorId: string, - content: string, + content: string ): Confession { return { id: id, messageId: message.id, author: author, authorId: authorId, - content: content, + content: content }; } @@ -72,7 +72,7 @@ export class StoreMan { fs.writeFileSync( StoreMan.fullPath, JSON.stringify(this.data, null, 2), - "utf8", + "utf8" ); } @@ -92,7 +92,7 @@ export class StoreMan { this.data.push({ id: id, confessions: [], - settings: opts, + settings: opts }); this.saveFile(); @@ -100,7 +100,7 @@ export class StoreMan { // Clear the settings for a given guild public clearSettings(id: string): void { - this.data = this.data.filter((guild) => { + this.data = this.data.filter(guild => { return guild.id !== id; }); this.saveFile(); @@ -122,7 +122,7 @@ export class StoreMan { id: string, author: string, authorId: string, - content: string, + content: string ): boolean { const guildId = message.guild?.id; @@ -134,7 +134,7 @@ export class StoreMan { } guild.confessions.push( - StoreMan.toConfession(message, id, author, authorId, content), + StoreMan.toConfession(message, id, author, authorId, content) ); this.saveFile(); return true; @@ -142,13 +142,13 @@ export class StoreMan { } throw new Error( - `No guild with id ${id} was found. Something's pretty wrong.`, + `No guild with id ${id} was found. Something's pretty wrong.` ); } public getConfession( guildId: string, - confessionId: string, + confessionId: string ): Confession | null { for (const guild of this.data) { if (guild.id === guildId) { @@ -166,7 +166,7 @@ export class StoreMan { // Attempts to delete a confession. If it is sucessfully deleted, returns true, else false. public delConfesssion( { guild, user }: CommandInteraction, - confessionId: string, + confessionId: string ): boolean { const guildId = guild?.id; const userId = user.id; @@ -175,7 +175,7 @@ export class StoreMan { if (guild.id === guildId) { for (const confession of guild.confessions) { if (confession.authorId === userId) { - guild.confessions = guild.confessions.filter((confession) => { + guild.confessions = guild.confessions.filter(confession => { return confession.id !== confessionId; }); @@ -239,7 +239,7 @@ export class StoreMan { for (const guild of this.data) { if (guild.id === guildId) { if (this.getConfession(guildId, confessionId)) { - guild.settings.bans = guild.settings.bans.filter((ban) => { + guild.settings.bans = guild.settings.bans.filter(ban => { return ban !== this.getConfession(guildId, confessionId)?.authorId!; }); diff --git a/src/utils/Logger.ts b/src/utils/Logger.ts index 06a8202..8b8589b 100644 --- a/src/utils/Logger.ts +++ b/src/utils/Logger.ts @@ -36,7 +36,7 @@ export default class Logger { public static readonly udln = chalk.underline; public static readonly anon = Logger.bold.gray( - `[ConfessBot] | ${Logger.emp("Anonymous ")}`, + `[ConfessBot] | ${Logger.emp("Anonymous ")}` ); constructor(origin?: string) {