diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 79cac1b..55344d1 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -29,4 +29,4 @@ jobs: run: npm i - name: Run linters - run: npm run format \ No newline at end of file + run: npm run format diff --git a/templates/javascript-esm/.gitignore b/templates/javascript-esm/.gitignore index caa2994..7af7f04 100644 --- a/templates/javascript-esm/.gitignore +++ b/templates/javascript-esm/.gitignore @@ -1,2 +1,2 @@ -/node_modules +/node_modules .env \ No newline at end of file diff --git a/templates/javascript-esm/package.json b/templates/javascript-esm/package.json index 439d2d0..7121a7b 100644 --- a/templates/javascript-esm/package.json +++ b/templates/javascript-esm/package.json @@ -13,8 +13,8 @@ ], "license": "UNLICENSED", "dependencies": { - "@sern/handler": "^1.0.0", - "discord.js": "^14.2.0" + "@sern/handler": "^2.0.0", + "discord.js": "^14.7.1" }, "devDependencies": { "@types/node": "^17.0.25" diff --git a/templates/javascript-esm/src/index.js b/templates/javascript-esm/src/index.js index e61e213..d3c8514 100644 --- a/templates/javascript-esm/src/index.js +++ b/templates/javascript-esm/src/index.js @@ -1,5 +1,5 @@ import { Client, GatewayIntentBits } from 'discord.js'; -import { Sern } from '@sern/handler'; +import { Sern, single, DefaultLogging } from '@sern/handler'; const client = new Client({ intents: [ @@ -9,12 +9,31 @@ const client = new Client({ GatewayIntentBits.MessageContent, // Make sure this is enabled for text commands! ], }); + +/** + * Where all of your dependencies are composed. + * '@sern/client' is usually your Discord Client. + * View documentation for pluggable dependencies + * Configure your dependency root to your liking. + * It follows the npm package iti https://itijs.org/. + * Use this function to access all of your dependencies. + * This is used for external event modules as well + */ +export const useContainer = Sern.makeDependencies({ + build: (root) => + root + .add({ '@sern/client': single(client) }) + .add({ '@sern/logger': single(new DefaultLogging()) }), +}); + //View docs for all options Sern.init({ - client, defaultPrefix: '!', // removing defaultPrefix will shut down text commands commands: 'src/commands', // events: 'src/events' (optional), + containerConfig: { + get: useContainer, + }, }); client.login(); diff --git a/templates/javascript/.gitignore b/templates/javascript/.gitignore index caa2994..7af7f04 100644 --- a/templates/javascript/.gitignore +++ b/templates/javascript/.gitignore @@ -1,2 +1,2 @@ -/node_modules +/node_modules .env \ No newline at end of file diff --git a/templates/javascript/package.json b/templates/javascript/package.json index 81713b3..6d21482 100644 --- a/templates/javascript/package.json +++ b/templates/javascript/package.json @@ -13,8 +13,8 @@ ], "license": "UNLICENSED", "dependencies": { - "@sern/handler": "^1.0.0", - "discord.js": "^14.2.0" + "@sern/handler": "^2.0.0", + "discord.js": "^14.7.1" }, "devDependencies": { "@types/node": "^17.0.25" diff --git a/templates/javascript/src/index.js b/templates/javascript/src/index.js index c14636c..8fad758 100644 --- a/templates/javascript/src/index.js +++ b/templates/javascript/src/index.js @@ -1,5 +1,5 @@ const { Client, GatewayIntentBits } = require('discord.js'); -const { Sern } = require('@sern/handler'); +const { Sern, single, DefaultLogging } = require('@sern/handler'); const client = new Client({ intents: [ @@ -9,12 +9,31 @@ const client = new Client({ GatewayIntentBits.MessageContent, // Make sure this is enabled for text commands! ], }); + +/** + * Where all of your dependencies are composed. + * '@sern/client' is usually your Discord Client. + * View documentation for pluggable dependencies + * Configure your dependency root to your liking. + * It follows the npm package iti https://itijs.org/. + * Use this function to access all of your dependencies. + * This is used for external event modules as well + */ +export const useContainer = Sern.makeDependencies({ + build: (root) => + root + .add({ '@sern/client': single(client) }) + .add({ '@sern/logger': single(new DefaultLogging()) }), +}); + //View docs for all options Sern.init({ - client, defaultPrefix: '!', // removing defaultPrefix will shut down text commands commands: 'src/commands', // events: 'src/events' (optional), + containerConfig: { + get: useContainer, + }, }); client.login(); diff --git a/templates/typescript/package.json b/templates/typescript/package.json index da56314..02ee897 100644 --- a/templates/typescript/package.json +++ b/templates/typescript/package.json @@ -15,11 +15,11 @@ ], "license": "UNLICENSED", "dependencies": { - "@sern/handler": "^1.0.0", - "discord.js": "^14.2.0" + "@sern/handler": "^2.0.0", + "discord.js": "^14.7.1" }, "devDependencies": { "@types/node": "^17.0.25", - "typescript": "^4.6.3" + "typescript": "^4.9" } } diff --git a/templates/typescript/src/index.ts b/templates/typescript/src/index.ts index fc2a2fe..71ba32d 100644 --- a/templates/typescript/src/index.ts +++ b/templates/typescript/src/index.ts @@ -1,5 +1,11 @@ import { Client, GatewayIntentBits } from 'discord.js'; -import { Sern } from '@sern/handler'; +import { + Dependencies, + Sern, + single, + Singleton, + DefaultLogging, +} from '@sern/handler'; const client = new Client({ intents: [ @@ -9,12 +15,36 @@ const client = new Client({ GatewayIntentBits.MessageContent, //Make sure this is enabled for text commands! ], }); + +//With typescript, you can customize / augment your typings. +interface MyDependencies extends Dependencies { + '@sern/client': Singleton; + '@sern/logger': Singleton; +} +/** + * Where all of your dependencies are composed. + * '@sern/client' is usually your Discord Client. + * View documentation for pluggable dependencies + * Configure your dependency root to your liking. + * It follows the npm package iti https://itijs.org/. + * Use this function to access all of your dependencies. + * This is used for external event modules as well + */ +export const useContainer = Sern.makeDependencies({ + build: (root) => + root + .add({ '@sern/client': single(client) }) + .add({ '@sern/logger': single(new DefaultLogging()) }), +}); + //View docs for all options Sern.init({ - client, defaultPrefix: '!', // removing defaultPrefix will shut down text commands commands: 'dist/commands', // events: 'dist/events' (optional), + containerConfig: { + get: useContainer, + }, }); client.login();