Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Slash Commands and Context Menu Commands #109

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions .eslintrc.json

This file was deleted.

4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ typings/
# Optional npm cache directory
.npm

# eslint
.eslintcache
.eslintrc.json

# Optional REPL history
.node_repl_history

Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"recommendations": [
"ms-azuretools.vscode-docker",
"dbaeumer.vscode-eslint",
"gamunu.vscode-yarn",
"biomejs.biome",
]
}
3 changes: 0 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"files.exclude": {
"node_modules": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"npm.packageManager": "yarn",
"files.eol": "\n",
"editor.insertSpaces": true,
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
HunteRoi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:lts-alpine AS BUILD
FROM node:lts-alpine AS build

WORKDIR /app

Expand All @@ -12,13 +12,13 @@ RUN yarn install --production
RUN zip -r app.zip ./node_modules ./build ./yarn.lock ./.env

# ------------------------------------------------------------
FROM node:lts-alpine AS APP
FROM node:lts-alpine AS app

WORKDIR /app

RUN apk --no-cache add unzip

COPY --from=BUILD /app/app.zip .
COPY --from=build /app/app.zip .
RUN unzip app.zip && rm app.zip && mv ./build/* . && rm -rf ./build

CMD ["sh", "-c", "sleep 2 && node ./index.js"]
24 changes: 24 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://biomejs.dev/schemas/1.6.4/schema.json",
"organizeImports": {
"enabled": true
},
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true,
"defaultBranch": "master"
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 4,
"lineEnding": "lf"
}
}
2 changes: 0 additions & 2 deletions config.development.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@
"roleid": "1028257512312557591",
"emote": "📢"
},
"ok_hand": "👌",
"warning": "⚠️",
"communicationServiceOptions": {
"mailData": {
"from": "[email protected]",
Expand Down
2 changes: 0 additions & 2 deletions config.production.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@
"roleid": "364008970966269952",
"emote": "📢"
},
"ok_hand": "👌",
"warning": "⚠️",
"communicationServiceOptions": {
"mailData": {
"from": "[email protected]",
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ x-restart-policy:
&restart-policy
restart: always

version: '3.8'
services:
database:
<<: [*env-file, *network, *restart-policy]
Expand Down
35 changes: 17 additions & 18 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import * as dotenv from 'dotenv';
import { GatewayIntentBits } from 'discord.js';
import { GatewayIntentBits } from "discord.js";
import * as dotenv from "dotenv";

import { DatadropClient } from './src/datadrop.js';
import { readConfig } from './src/config.js';
import { Configuration } from './src/models/Configuration.js';
import { readConfig } from "./src/config.js";
import { DatadropClient } from "./src/datadrop.js";
import type { Configuration } from "./src/models/Configuration.js";

dotenv.config({ debug: Boolean(process.env.DEBUG) });

let client: DatadropClient;
readConfig()
.then(
async (config: Configuration) => {
client = new DatadropClient({
.then(async (config: Configuration) => {
client = new DatadropClient(
{
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages
]
}, config);
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
],
},
config,
);

await client.start();
}
)
await client.start();
})
.catch(() => client?.stop());
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "datadrop",
"version": "1.11.1",
"version": "2.0.0",
"type": "module",
"main": "./build/index.js",
"scripts": {
"start": "docker-compose up --build",
"stop": "docker-compose down",
"deploy:commands": "tsc && node ./scripts/deploy-commands.cjs",
"build": "rm -rf build/ && tsc",
"lint": "eslint --fix --ext .ts .",
"lint": "biome check --write ./src index.ts",
"env-gen": "node ./scripts/envgen.cjs"
},
"repository": {
Expand All @@ -26,15 +27,14 @@
"@hunteroi/discord-temp-channels": "^3.3.0",
"@hunteroi/discord-verification": "^1.5.0",
"@sendgrid/mail": "8.1.3",
"discord-sync-commands": "^0.3.0",
"discord.js": "^14.16.2",
"dotenv": "^16.4.5",
"ts-postgres": "1.3.0"
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@types/node": "^20.12.7",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"eslint": "^9.0.0",
"typescript": "^5.4.4"
}
}
56 changes: 56 additions & 0 deletions scripts/deploy-commands.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const dotenv = require('dotenv');
dotenv.config({ debug: true });

const { Client, Collection, REST, Routes } = require('discord.js');
const path = require('node:path');
const os = require('node:os');
const fsp = require('node:fs/promises');
const synchronizeSlashCommands = require('discord-sync-commands');
const { guildId } = require('../config.development.json');

async function readFilesFrom(directory, callback) {
try {
const files = await fsp.readdir(directory);
for (const file of files) {
const filePath = path.join(directory, file);
const stats = await fsp.stat(filePath);
if (stats.isDirectory()) {
await readFilesFrom(filePath, callback);
continue;
}

if (stats.isFile() && !file.endsWith('.js')) continue;

const isWin = os.platform() === 'win32';
const props = await import(`${isWin ? 'file:///' : ''}${filePath}`);
callback(file.replace('.js', ''), props.default);
}
} catch (err) {
console.error(err);
}
}

/* DEPLOY COMMANDS */
const client = new Client({ intents: [] });
client.on('ready', () => console.log('Ready!'));
const commands = new Collection();

readFilesFrom(path.join(__dirname, '..', 'build', 'src', 'commands'), (commandName, command) => {
console.log(`Reading ${commandName}...`);
commands.set(commandName, command.data.toJSON());
}).then(() => {
const slashCommands = [...commands.values()];
console.log('Total expected slash commands : ', slashCommands.length);

synchronizeSlashCommands(client, slashCommands, {
debug: true,
//guildId // to deploy commands to a specific guild
});
client.login();
});

/* DELETE ALL DEPLOYED GLOBAL COMMANDS */
// const rest = new REST().setToken(process.env.DISCORD_TOKEN);
// rest.put(Routes.applicationCommands('703031563062870107'), { body: [] })
// .then(() => console.log('Successfully deleted all application commands.'))
// .catch(console.error);
HunteRoi marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 1 addition & 2 deletions scripts/envgen.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs/promises');
const fs = require('node:fs/promises');

const path = `${__dirname}/..`;

Expand Down
Loading
Loading