feat!: templates for sern v2 (#19)

This commit is contained in:
Jacob Nguyen
2023-01-08 07:14:14 -06:00
committed by GitHub
parent 0ee7b2b872
commit 37207f8eec
9 changed files with 84 additions and 16 deletions

View File

@@ -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"

View File

@@ -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();

View File

@@ -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"

View File

@@ -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();

View File

@@ -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"
}
}

View File

@@ -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<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();