Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
feat!: templates for sern v2 (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoobes authored Jan 8, 2023
1 parent 0ee7b2b commit 37207f8
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
run: npm i

- name: Run linters
run: npm run format
run: npm run format
2 changes: 1 addition & 1 deletion templates/javascript-esm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/node_modules
/node_modules
.env
4 changes: 2 additions & 2 deletions templates/javascript-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 21 additions & 2 deletions templates/javascript-esm/src/index.js
Original file line number Diff line number Diff line change
@@ -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: [
Expand All @@ -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();
2 changes: 1 addition & 1 deletion templates/javascript/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/node_modules
/node_modules
.env
4 changes: 2 additions & 2 deletions templates/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 21 additions & 2 deletions templates/javascript/src/index.js
Original file line number Diff line number Diff line change
@@ -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: [
Expand All @@ -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();
6 changes: 3 additions & 3 deletions templates/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
34 changes: 32 additions & 2 deletions templates/typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -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: [
Expand All @@ -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<Client>;
'@sern/logger': Singleton<DefaultLogging>;
}
/**
* 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<MyDependencies>({
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();

0 comments on commit 37207f8

Please sign in to comment.