generated from nhcarrigan/template
feat: set up Discord bot scaffolding
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 48s
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 48s
- Add Rondelle interface with discord client and database - Add logger utility using @nhcarrigan/logger - Add database utility for Prisma client instantiation - Update index.ts with bot startup logic - Update .gitignore to exclude prod/ build output
This commit is contained in:
+2
-133
@@ -1,133 +1,2 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
.temp
|
||||
.cache
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# pnpm
|
||||
pnpm-lock.yaml
|
||||
node_modules
|
||||
prod
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@nhcarrigan/eslint-config": "5.2.0",
|
||||
"@nhcarrigan/typescript-config": "1.0.0",
|
||||
"@nhcarrigan/typescript-config": "4.0.0",
|
||||
"@types/node": "22.10.6",
|
||||
"prisma": "6.8.2",
|
||||
"typescript": "5.7.3"
|
||||
|
||||
Generated
+4397
File diff suppressed because it is too large
Load Diff
+24
-7
@@ -3,15 +3,32 @@
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import { Client, GatewayIntentBits } from "discord.js";
|
||||
import { instantiatePrisma } from "./utils/database.js";
|
||||
import { logger } from "./utils/logger.js";
|
||||
import type { Rondelle } from "./interfaces/rondelle.js";
|
||||
|
||||
/**
|
||||
* Adds two numbers together.
|
||||
* @param a - The first number.
|
||||
* @param b - The second number.
|
||||
* @returns The sum of the two numbers.
|
||||
* Starts the Discord bot and connects to the database.
|
||||
*/
|
||||
const calculateSum = (a: number, b: number): number => {
|
||||
return a + b;
|
||||
const startBot = async(): Promise<void> => {
|
||||
const rondelle: Rondelle = {
|
||||
database: await instantiatePrisma(),
|
||||
discord: new Client({
|
||||
intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates ],
|
||||
}),
|
||||
};
|
||||
|
||||
rondelle.discord.once("ready", () => {
|
||||
void logger.log("info", `Logged in as ${rondelle.discord.user?.tag ?? "unknown"}`);
|
||||
});
|
||||
|
||||
await rondelle.discord.login(process.env.DISCORD_TOKEN);
|
||||
};
|
||||
|
||||
export { calculateSum };
|
||||
await startBot().catch(async(error: unknown) => {
|
||||
const actualError = error instanceof Error
|
||||
? error
|
||||
: new Error(String(error));
|
||||
await logger.error("startBot", actualError);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @copyright 2026
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import type { PrismaClient } from "@prisma/client";
|
||||
import type { Client } from "discord.js";
|
||||
|
||||
interface Rondelle {
|
||||
database: PrismaClient;
|
||||
discord: Client;
|
||||
}
|
||||
|
||||
export type { Rondelle };
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @copyright 2026
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { logger } from "./logger.js";
|
||||
|
||||
/**
|
||||
* Creates and connects a Prisma client instance.
|
||||
* @returns The connected Prisma client.
|
||||
*/
|
||||
const instantiatePrisma = async(): Promise<PrismaClient> => {
|
||||
const client = new PrismaClient();
|
||||
await client.$connect();
|
||||
await logger.log("info", "Connected to database.");
|
||||
return client;
|
||||
};
|
||||
|
||||
export { instantiatePrisma };
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @copyright 2026
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import { Logger } from "@nhcarrigan/logger";
|
||||
|
||||
const logger = new Logger(
|
||||
"rondelle",
|
||||
process.env.LOG_TOKEN ?? "",
|
||||
);
|
||||
|
||||
export { logger };
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
"extends": "@nhcarrigan/typescript-config",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./prod"
|
||||
"outDir": "./prod",
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user