Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 26 additions & 0 deletions apps/bot/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@apps/bot",
"version": "1.0.0",
"description": "Bot app",
"main": "dist/index.js",
"author": "Supabase Community",
"license": "MIT",
"private": true,
"scripts": {
"dev": "tsx watch ./src/index.ts",
"build": "del dist && tsc",
"start": "node dist/index.js",
"format": "prettier --write \"**/*.ts\""
},
"dependencies": {
"@packages/config": "workspace:*",
"discord.js": "^14.7.1"
},
"devDependencies": {
"@types/node": "^18.11.14",
"del-cli": "^5.0.0",
"prettier": "^2.8.1",
"tsx": "^3.12.1",
"typescript": "^4.9.4"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions src/commands/redirect.ts → apps/bot/src/commands/redirect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandInteraction, SlashCommandBuilder } from 'discord.js';

import { config } from '../config';
import { env, messages } from '@packages/config';

export const data = new SlashCommandBuilder()
.setName('redirect')
Expand All @@ -14,10 +14,10 @@ export const data = new SlashCommandBuilder()
export async function execute(interaction: CommandInteraction) {
const userId = interaction.options.getUser('user')?.id;

let msg = config.redirectReplyMessage.replace(
'{user}',
userId ? `<@${userId}>` : 'there'
);
const message = messages.redirectReplyMessage({
id_user: userId || 'there',
id_channel: env.HELP_CHANNEL_ID,
});

await interaction.reply(msg);
await interaction.reply(message);
}
2 changes: 1 addition & 1 deletion src/index.ts → apps/bot/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { env } from '@packages/config';
import { Client, GatewayIntentBits, REST, Routes } from 'discord.js';
import { commands } from './commands';
import { env } from './config';

const { CLIENT_ID, DISCORD_TOKEN } = env;

Expand Down
8 changes: 8 additions & 0 deletions apps/bot/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["./src/**/*"]
}
19 changes: 3 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,12 @@
"name": "supacommunitybot",
"version": "1.0.0",
"description": "A discord bot driven by the Supabase Community",
"main": "dist/index.js",
"author": "Supabase Community",
"license": "MIT",
"private": true,
"scripts": {
"dev": "tsx watch ./src/index.ts",
"build": "tsc",
"start": "node dist/index.js",
"format": "prettier --write \"**/*.ts\""
},
"dependencies": {
"discord.js": "^14.7.1",
"envsafe": "^2.0.3"
},
"devDependencies": {
"@types/node": "^18.11.14",
"dotenv": "^16.0.3",
"prettier": "^2.8.1",
"tsx": "^3.12.1",
"typescript": "^4.9.4"
"build": "pnpm -r build",
"build:packages": "pnpm -r --filter \"@packages/*\" --parallel build",
"dev": "pnpm build:packages && pnpm -r --parallel dev"
}
}
24 changes: 24 additions & 0 deletions packages/config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@packages/config",
"version": "1.0.0",
"description": "Configuration package for apps",
"author": "Supabase Community",
"license": "MIT",
"private": true,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "del dist && tsc",
"format": "prettier --write \"**/*.ts\""
},
"dependencies": {
"envsafe": "^2.0.3"
},
"devDependencies": {
"@types/node": "^18.11.14",
"del-cli": "^5.0.0",
"dotenv": "^16.0.3",
"prettier": "^2.8.1",
"typescript": "^4.9.4"
}
}
22 changes: 22 additions & 0 deletions packages/config/src/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { config } from 'dotenv';
import { envsafe, str } from 'envsafe';
import { existsSync } from 'node:fs';
import { resolve } from 'node:path';

const envPath = resolve(process.cwd(), '.env');

if (existsSync(envPath)) {
config({ path: envPath });
} else {
config({ path: resolve(process.cwd(), '../../.env') });
}

export const env = envsafe({
NODE_ENV: str({
devDefault: 'development',
choices: ['development', 'test', 'production'],
}),
DISCORD_TOKEN: str(),
CLIENT_ID: str(),
HELP_CHANNEL_ID: str(),
});
2 changes: 2 additions & 0 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './environment';
export * from './messages';
13 changes: 13 additions & 0 deletions packages/config/src/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type MessagesOptions = {
redirectReplyMessageOptions: {
id_user: string;
id_channel: string;
};
};

export const messages = {
redirectReplyMessage: (
options: MessagesOptions['redirectReplyMessageOptions']
) =>
`Hello <@${options.id_user}>! Please use the <#${options.id_channel}> channel for questions. You will find it easier to get answers there!`,
};
11 changes: 11 additions & 0 deletions packages/config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"declaration": true,
"sourceMap": true,
"declarationMap": true
},
"include": ["./src/**/*"]
}
Loading