added eslint typescript
This commit is contained in:
parent
d52431ffb5
commit
fbc9238e97
17
discordbot/.eslintrc.json
Normal file
17
discordbot/.eslintrc.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"root": true,
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2021,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"no-console": "off"
|
||||
}
|
||||
}
|
1793
discordbot/package-lock.json
generated
1793
discordbot/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,9 @@
|
||||
"scripts": {
|
||||
"dev": "tsx watch src/index.ts",
|
||||
"start": "node dist/index.js",
|
||||
"build": "tsup src/index.ts --minify"
|
||||
"build": "tsup src/index.ts --minify",
|
||||
"lint": "eslint \"**/*.{ts, tsx}\"",
|
||||
"eslint-fix": "eslint . --fix"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
@ -15,6 +17,9 @@
|
||||
"dotenv": "^16.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^5.60.1",
|
||||
"@typescript-eslint/parser": "^5.60.1",
|
||||
"eslint": "^8.43.0",
|
||||
"tsup": "^7.1.0",
|
||||
"tsx": "^3.12.7",
|
||||
"typescript": "^5.1.3"
|
||||
|
24
discordbot/src/commands/clear.ts
Normal file
24
discordbot/src/commands/clear.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { ChatInputCommandInteraction, SlashCommandBuilder, Client, PermissionFlagsBits } from "discord.js";
|
||||
import { basicEmbed } from '../createEmbed'
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName("clear")
|
||||
.setDescription("Clear 1-100 messages")
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
|
||||
.addNumberOption(option => option
|
||||
.setName('amount')
|
||||
.setDescription('The amount of messages to creat')
|
||||
.setRequired(true)
|
||||
)
|
||||
|
||||
export async function execute({ interaction }: { interaction: ChatInputCommandInteraction, client: Client }) {
|
||||
const amount = interaction.options.getNumber('amount');
|
||||
|
||||
if (!amount || !interaction.channel || amount < 1 || amount > 100) return await interaction.reply({ embeds: [basicEmbed('The amount must be between 1-100')] });
|
||||
|
||||
if (interaction.channel.isDMBased()) return await interaction.reply({ embeds: [basicEmbed('This command can only be executed inside a guild')], ephemeral: true })
|
||||
|
||||
interaction.channel.bulkDelete(amount)
|
||||
|
||||
await interaction.reply({ embeds: [basicEmbed(`Cleared **${amount}** messages`)], ephemeral: true })
|
||||
}
|
@ -1,10 +1,11 @@
|
||||
import { CommandInteraction, SlashCommandBuilder, Client } from "discord.js";
|
||||
import { ChatInputCommandInteraction, SlashCommandBuilder, Client } from "discord.js";
|
||||
import { basicEmbed } from '../createEmbed'
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName("ping")
|
||||
.setDescription("Replies with Pong!");
|
||||
|
||||
export async function execute({ interaction, client, createEmbed }: { interaction: CommandInteraction, client: Client, createEmbed: Function }) {
|
||||
const reply = await interaction.reply({ embeds: [createEmbed(`Websocket heartbeat: **${client.ws.ping}ms**\n Roundtrip latency: **Pinging...**`)], fetchReply: true, ephemeral: true });
|
||||
interaction.editReply({ embeds: [createEmbed(`Websocket heartbeat: **${client.ws.ping}ms**\n Roundtrip latency: **${reply.createdTimestamp - interaction.createdTimestamp}ms**`)] });
|
||||
export async function execute({ interaction, client }: { interaction: ChatInputCommandInteraction, client: Client }) {
|
||||
const reply = await interaction.reply({ embeds: [basicEmbed(`Websocket heartbeat: **${client.ws.ping}ms**\n Roundtrip latency: **Pinging...**`)], fetchReply: true, ephemeral: true });
|
||||
interaction.editReply({ embeds: [basicEmbed(`Websocket heartbeat: **${client.ws.ping}ms**\n Roundtrip latency: **${reply.createdTimestamp - interaction.createdTimestamp}ms**`)] });
|
||||
}
|
||||
|
8
discordbot/src/createEmbed.ts
Normal file
8
discordbot/src/createEmbed.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { EmbedBuilder } from 'discord.js'
|
||||
import { config } from './config'
|
||||
|
||||
export const basicEmbed = (description: string) => {
|
||||
return new EmbedBuilder()
|
||||
.setColor(config.EMBED_COLOR)
|
||||
.setDescription(description);
|
||||
};
|
@ -2,7 +2,7 @@ import { Events, Client, BaseInteraction } from 'discord.js'
|
||||
|
||||
export const name = Events.InteractionCreate
|
||||
|
||||
export const execute = async ({ client, createEmbed }: { client: Client, createEmbed: Function }, interaction: BaseInteraction) => {
|
||||
export const execute = async ({ client }: { client: Client }, interaction: BaseInteraction) => {
|
||||
if (interaction.isChatInputCommand()) {
|
||||
const command = interaction.client.commands.get(interaction.commandName);
|
||||
|
||||
@ -13,7 +13,7 @@ export const execute = async ({ client, createEmbed }: { client: Client, createE
|
||||
}
|
||||
|
||||
try {
|
||||
await command.execute({ interaction, client, createEmbed });
|
||||
await command.execute({ interaction, client });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
|
@ -6,6 +6,8 @@ export const name = Events.ClientReady
|
||||
export const once = true
|
||||
|
||||
export const execute = async ({ client }: { client: Client }) => {
|
||||
if (!client.user) throw Error('No client.user')
|
||||
|
||||
console.log(`Ready! Logged in as ${client.user.tag}`)
|
||||
|
||||
registerCommands()
|
||||
|
@ -1,45 +1,48 @@
|
||||
import { Client, GatewayIntentBits, Collection, EmbedBuilder } from 'discord.js'
|
||||
import { Client, GatewayIntentBits, Collection } from 'discord.js'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { config } from './config'
|
||||
|
||||
type Command = {
|
||||
data: any
|
||||
}
|
||||
|
||||
const client = new Client({
|
||||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
|
||||
})
|
||||
|
||||
const createEmbed = (description: string) => {
|
||||
return new EmbedBuilder()
|
||||
.setColor(config.EMBED_COLOR)
|
||||
.setDescription(description);
|
||||
};
|
||||
|
||||
client.commands = new Collection()
|
||||
|
||||
const commandsPath = path.join(__dirname, 'commands');
|
||||
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.ts'));
|
||||
|
||||
for (const file of commandFiles) {
|
||||
(async () => {
|
||||
for (const file of commandFiles) {
|
||||
const filePath = path.join(commandsPath, file);
|
||||
const command = require(filePath);
|
||||
const command = await import(filePath) as Command
|
||||
|
||||
if ('data' in command && 'execute' in command) {
|
||||
client.commands.set(command.data.name, command);
|
||||
} else {
|
||||
console.error(`The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const eventsPath = path.join(__dirname, 'events');
|
||||
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.ts'));
|
||||
|
||||
for (const file of eventFiles) {
|
||||
(async () => {
|
||||
for (const file of eventFiles) {
|
||||
const filePath = path.join(eventsPath, file);
|
||||
const event = require(filePath);
|
||||
const event = await import(filePath);
|
||||
if (event.once) {
|
||||
client.once(event.name, (...args) => event.execute({ client, createEmbed }, ...args));
|
||||
client.once(event.name, (...args) => event.execute({ client }, ...args));
|
||||
} else {
|
||||
client.on(event.name, (...args) => event.execute({ client, createEmbed }, ...args));
|
||||
client.on(event.name, (...args) => event.execute({ client }, ...args));
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
client.login(config.DISCORD_TOKEN);
|
||||
|
@ -10,6 +10,9 @@
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"strictNullChecks": true,
|
||||
"skipLibCheck": true
|
||||
"skipLibCheck": true,
|
||||
"compilerOptions": {
|
||||
"module": "commonjs"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
4
discordbot/types.d.ts
vendored
4
discordbot/types.d.ts
vendored
@ -5,3 +5,7 @@ declare module 'discord.js' {
|
||||
commands: Collection<unknown, any>
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
type CreateEmbed = (message: string) => void
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user