Skip to content

Commit a49aae3

Browse files
committed
formatting
1 parent 8ec5bda commit a49aae3

File tree

24 files changed

+551
-210
lines changed

24 files changed

+551
-210
lines changed

.eslintrc.json

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
{
2-
"rules": {
3-
"semi": ["error", "always"],
4-
"quotes": ["error", "double"]
5-
}
6-
}
2+
"extends": [
3+
"eslint:recommended",
4+
"plugin:@typescript-eslint/eslint-recommended",
5+
"plugin:@typescript-eslint/recommended",
6+
"prettier"
7+
],
8+
"parser": "@typescript-eslint/parser",
9+
"plugins": ["@typescript-eslint", "prettier"],
10+
"root": true,
11+
"rules": {
12+
"no-console": 1, // Means warning
13+
"prettier/prettier": 2 // Means error
14+
}
15+
}

.prettierrc.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"trailingComma": "all",
3-
"tabWidth": 4,
4-
"semi": false,
2+
"trailingComma": "none",
3+
"tabWidth": 2,
4+
"semi": true,
55
"singleQuote": true
66
}

package.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,39 @@
88
"Ralph Schuler <[email protected]>"
99
],
1010
"scripts": {
11-
"clean": "yarn clean:bridge && yarn clean:cluster && yarn clean:bot && yarn clean:plugins",
11+
"clean": "yarn clean:bridge && yarn clean:cluster && yarn clean:bot && yarn clean:plugins && yarn clean:shared",
1212
"clean:bridge": "rimraf dist/bridge && mkdirp dist/bridge",
1313
"clean:cluster": "rimraf dist/cluster && mkdirp dist/cluster",
1414
"clean:bot": "rimraf dist/bot && mkdirp dist/bot",
1515
"clean:plugins": "rimraf dist/plugins && mkdirp dist/plugins",
16-
17-
"build": "yarn build:bridge && yarn build:cluster && yarn build:bot && yarn build:plugins",
16+
"clean:shared": "rimraf dist/shared && mkdirp dist/shared",
17+
"build": "yarn build:bridge && yarn build:cluster && yarn build:bot && yarn build:plugins && yarn build:shared",
1818
"build:bridge": "tsc -p tsconfig.bridge.json",
1919
"build:cluster": "tsc -p tsconfig.cluster.json",
2020
"build:bot": "tsc -p tsconfig.bot.json",
2121
"build:plugins": "tsc -p tsconfig.plugins.json",
22-
23-
"lint": "yarn lint:bridge && yarn lint:cluster && yarn lint:bot && yarn lint:plugins",
22+
"build:shared": "tsc -p tsconfig.shared.json",
23+
"lint": "yarn lint:bridge && yarn lint:cluster && yarn lint:bot && yarn lint:plugins && yarn lint:shared",
2424
"lint:bridge": "eslint --ext .ts src/bridge",
2525
"lint:cluster": "eslint --ext .ts src/cluster",
2626
"lint:bot": "eslint --ext .ts src/bot",
2727
"lint:plugins": "eslint --ext .ts src/plugins",
28-
29-
"start:bridge": "yarn clean:bridge && yarn build:bridge && node dist/bridge/index.js",
30-
"start:cluster": "yarn clean:cluster && yarn clean:bot && yarn build:cluster && yarn build:bot && node dist/cluster/index.js"
28+
"lint:shared": "eslint --ext .ts src/shared",
29+
"format": "yarn format:bridge && yarn format:cluster && yarn format:bot && yarn format:plugins && yarn format:shared",
30+
"format:bridge": "prettier --write src/bridge/**/*.ts",
31+
"format:cluster": "prettier --write src/cluster/**/*.ts",
32+
"format:bot": "prettier --write src/bot/**/*.ts",
33+
"format:plugins": "prettier --write src/plugins/**/*.ts",
34+
"format:shared": "prettier --write src/shared/**/*.ts"
3135
},
3236
"devDependencies": {
3337
"@types/mongodb": "^4.0.7",
3438
"@types/node": "^18.15.5",
39+
"@typescript-eslint/eslint-plugin": "^5.56.0",
40+
"@typescript-eslint/parser": "^5.56.0",
3541
"eslint": "^8.36.0",
42+
"eslint-config-prettier": "^8.8.0",
43+
"eslint-plugin-prettier": "^4.2.1",
3644
"mkdirp": "^2.1.6",
3745
"prettier": "^2.8.6",
3846
"rimraf": "^4.4.1",
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { IPlugin } from "@/src/shared/interfaces/IPlugin";
1+
import { IPlugin } from '@/src/shared/interfaces/IPlugin';
22

33
export interface IPluginWrapper {
44
name: string;
55
packageName: string;
66
isRelative?: boolean;
77
}
88

9-
export type PluginInstance = any extends IPlugin ? any : never
9+
export type PluginInstance = any extends IPlugin ? any : never;
1010

1111
export interface IInitializedPluginWrapper extends IPluginWrapper {
1212
instance: PluginInstance;
13-
}
13+
}

src/bot/pluginManager/PluginManager.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import { existsSync } from "fs";
2-
import { join } from "path";
3-
import { IPluginWrapper, IInitializedPluginWrapper, PluginInstance } from "./IPluginWrapper";
4-
import { IClient } from "@/src/shared/interfaces/IClient";
5-
import { createLogger } from "@/src/shared/logger";
6-
import Config from "../Config"
1+
import { existsSync } from 'fs';
2+
import { join } from 'path';
3+
import {
4+
IPluginWrapper,
5+
IInitializedPluginWrapper,
6+
PluginInstance
7+
} from './IPluginWrapper';
8+
import { IClient } from '@/src/shared/interfaces/IClient';
9+
import { createLogger } from '@/src/shared/logger';
10+
import Config from '../Config';
711

812
const logger = createLogger();
913

1014
export class PluginManager {
11-
1215
private client: IClient;
1316
private plugins: Map<string, IInitializedPluginWrapper> = new Map();
1417

@@ -36,24 +39,27 @@ export class PluginManager {
3639

3740
try {
3841
const pluginInstance = plugin.isRelative
39-
? this.requireModule(
40-
join(Config.pluginsPath, plugin.packageName)
41-
)
42+
? this.requireModule(join(Config.pluginsPath, plugin.packageName))
4243
: this.requireModule(
43-
join(process.cwd(), "node_modules", plugin.packageName)
44+
join(process.cwd(), 'node_modules', plugin.packageName)
4445
);
4546

4647
this.addPlugin(plugin, pluginInstance);
4748
} catch (error: any) {
48-
logger.error(`Plugin with name ${plugin.name} failed to load: ${error.message}`);
49+
logger.error(
50+
`Plugin with name ${plugin.name} failed to load: ${error.message}`
51+
);
4952
}
5053
}
5154

5255
private pluginExists(name: string): boolean {
5356
return this.plugins.has(name);
5457
}
5558

56-
private addPlugin(plugin: IPluginWrapper, pluginInstance: PluginInstance): void {
59+
private addPlugin(
60+
plugin: IPluginWrapper,
61+
pluginInstance: PluginInstance
62+
): void {
5763
this.plugins.set(plugin.name, { ...plugin, instance: pluginInstance });
5864
}
5965

@@ -68,8 +74,8 @@ export class PluginManager {
6874
logger: logger.child({ plugin: plugin.name }),
6975
client: this.client,
7076
registerCommand: this.client.registerCommand,
71-
registerCronjob: this.client.registerCronjob,
72-
}
77+
registerCronjob: this.client.registerCronjob
78+
};
7379
return new pluginInstance(protocol);
7480
}
7581
}

src/bot/pluginManager/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { IPluginWrapper } from "./IPluginWrapper";
2-
export { PluginManager } from "./PluginManager";
1+
export { IPluginWrapper } from './IPluginWrapper';
2+
export { PluginManager } from './PluginManager';

src/bridge/Config.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const {
77
BRIDGE_TOTAL_SHARDS,
88
BRIDGE_TOTAL_MACHINES,
99
BRIDGE_SHARDS_PER_CLUSTER,
10-
BRIDGE_TOKEN,
10+
BRIDGE_TOKEN
1111
} = process.env;
1212

1313
export interface IConfig {
@@ -19,13 +19,33 @@ export interface IConfig {
1919
token: string;
2020
}
2121

22-
const Config = new GenericConfig<IConfig>("bridge.json");
22+
const Config = new GenericConfig<IConfig>('bridge.json');
2323

2424
export default {
25-
port: assert<number>("Port is not defined", Config.get("port"), BRIDGE_PORT),
26-
authToken: assert<string>("Auth token is not defined", Config.get("authToken"), BRIDGE_AUTH_TOKEN),
27-
totalShards: assert<number>("Total shards is not defined", Config.get("totalShards"), BRIDGE_TOTAL_SHARDS),
28-
totalMachines: assert<number>("Total machines is not defined", Config.get("totalMachines"), BRIDGE_TOTAL_MACHINES),
29-
shardsPerCluster: assert<number>("Shards per cluster is not defined", Config.get("shardsPerCluster"), BRIDGE_SHARDS_PER_CLUSTER),
30-
token: assert<string>("Token is not defined", Config.get("token"), BRIDGE_TOKEN),
31-
} as IConfig;
25+
port: assert<number>('Port is not defined', Config.get('port'), BRIDGE_PORT),
26+
authToken: assert<string>(
27+
'Auth token is not defined',
28+
Config.get('authToken'),
29+
BRIDGE_AUTH_TOKEN
30+
),
31+
totalShards: assert<number>(
32+
'Total shards is not defined',
33+
Config.get('totalShards'),
34+
BRIDGE_TOTAL_SHARDS
35+
),
36+
totalMachines: assert<number>(
37+
'Total machines is not defined',
38+
Config.get('totalMachines'),
39+
BRIDGE_TOTAL_MACHINES
40+
),
41+
shardsPerCluster: assert<number>(
42+
'Shards per cluster is not defined',
43+
Config.get('shardsPerCluster'),
44+
BRIDGE_SHARDS_PER_CLUSTER
45+
),
46+
token: assert<string>(
47+
'Token is not defined',
48+
Config.get('token'),
49+
BRIDGE_TOKEN
50+
)
51+
} as IConfig;

src/bridge/index.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
import { Bridge } from 'discord-cross-hosting';
2-
import { RatelimitManager } from "discord-cross-ratelimit";
2+
import { RatelimitManager } from 'discord-cross-ratelimit';
33
import { createLogger } from '@/src/shared/utils/logger';
44

55
const logger = createLogger();
66

77
const server = new Bridge({
8-
port: 4444, // The Port of the Server | Proxy Connection (Replit) needs Port 443
9-
authToken: 'Your_auth_token_same_in_cluster.js',
10-
totalShards: 40, // The Total Shards of the Bot or 'auto'
11-
totalMachines: 2, // The Total Machines, where the Clusters will run
12-
shardsPerCluster: 10, // The amount of Internal Shards, which are in one Cluster
13-
token: 'Your_Bot_Token',
8+
port: 4444, // The Port of the Server | Proxy Connection (Replit) needs Port 443
9+
authToken: 'Your_auth_token_same_in_cluster.js',
10+
totalShards: 40, // The Total Shards of the Bot or 'auto'
11+
totalMachines: 2, // The Total Machines, where the Clusters will run
12+
shardsPerCluster: 10, // The amount of Internal Shards, which are in one Cluster
13+
token: 'Your_Bot_Token'
1414
});
1515
new RatelimitManager(server);
1616
server.on('debug', logger.debug);
1717
server.start();
18-
server.on('ready', url => {
19-
logger.info(`Bridge is ready at ${url}`);
20-
setInterval(() => {
21-
server.broadcastEval('this.guilds.cache.size').then(logger.info).catch(logger.error);
22-
}, 10000);
23-
});
18+
server.on('ready', (url) => {
19+
logger.info(`Bridge is ready at ${url}`);
20+
setInterval(() => {
21+
server
22+
.broadcastEval('this.guilds.cache.size')
23+
.then(logger.info)
24+
.catch(logger.error);
25+
}, 10000);
26+
});

src/cluster/Config.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const {
77
CLUSTER_PORT,
88
CLUSTER_HANDSHAKE,
99
CLUSTER_AUTH_TOKEN,
10-
CLUSTER_ROLLING_RESTARTS,
10+
CLUSTER_ROLLING_RESTARTS
1111
} = process.env;
1212

1313
export interface IConfig {
@@ -19,13 +19,29 @@ export interface IConfig {
1919
rollingRestarts: boolean;
2020
}
2121

22-
const Config = new GenericConfig<IConfig>("cluster.json");
22+
const Config = new GenericConfig<IConfig>('cluster.json');
2323

2424
export default {
25-
agent: assert<string>("Agent is not defined", Config.get("agent"), CLUSTER_AGENT),
26-
host: assert<string>("Host is not defined", Config.get("host"), CLUSTER_HOST),
27-
port: assert<number>("Port is not defined", Config.get("port"), CLUSTER_PORT),
28-
handshake: assert<boolean>("Handshake is not defined", Config.get("handshake"), CLUSTER_HANDSHAKE),
29-
authToken: assert<string>("Auth token is not defined", Config.get("authToken"), CLUSTER_AUTH_TOKEN),
30-
rollingRestarts: assert<boolean>("Rolling restarts is not defined", Config.get("rollingRestarts"), CLUSTER_ROLLING_RESTARTS),
31-
} as IConfig;
25+
agent: assert<string>(
26+
'Agent is not defined',
27+
Config.get('agent'),
28+
CLUSTER_AGENT
29+
),
30+
host: assert<string>('Host is not defined', Config.get('host'), CLUSTER_HOST),
31+
port: assert<number>('Port is not defined', Config.get('port'), CLUSTER_PORT),
32+
handshake: assert<boolean>(
33+
'Handshake is not defined',
34+
Config.get('handshake'),
35+
CLUSTER_HANDSHAKE
36+
),
37+
authToken: assert<string>(
38+
'Auth token is not defined',
39+
Config.get('authToken'),
40+
CLUSTER_AUTH_TOKEN
41+
),
42+
rollingRestarts: assert<boolean>(
43+
'Rolling restarts is not defined',
44+
Config.get('rollingRestarts'),
45+
CLUSTER_ROLLING_RESTARTS
46+
)
47+
} as IConfig;

src/cluster/index.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,35 @@ import { createLogger } from '@/src/shared/utils/logger';
55
const logger = createLogger();
66

77
const client = new Client({
8-
agent: 'bot',
9-
host: 'localhost', // Domain without https
10-
port: 4444, // Proxy Connection (Replit) needs Port 443
11-
// handshake: true, When Replit or any other Proxy is used
12-
authToken: 'theauthtoken',
13-
rollingRestarts: false, // Enable, when bot should respawn when cluster list changes.
8+
agent: 'bot',
9+
host: 'localhost', // Domain without https
10+
port: 4444, // Proxy Connection (Replit) needs Port 443
11+
// handshake: true, When Replit or any other Proxy is used
12+
authToken: 'theauthtoken',
13+
rollingRestarts: false // Enable, when bot should respawn when cluster list changes.
1414
});
1515
client.on('debug', logger.debug);
1616
client.connect();
1717

18-
const clusterManager = new ClusterManager(`${__dirname}/bot/index.js`, { totalShards: 1, totalClusters: 'auto' }); // Some dummy Data
19-
clusterManager.on('clusterCreate', cluster => logger.info(`Cluster ${cluster.id} created`));
18+
const clusterManager = new ClusterManager(`${__dirname}/bot/index.js`, {
19+
totalShards: 1,
20+
totalClusters: 'auto'
21+
}); // Some dummy Data
22+
clusterManager.on('clusterCreate', (cluster) =>
23+
logger.info(`Cluster ${cluster.id} created`)
24+
);
2025
clusterManager.on('debug', logger.debug);
2126

2227
client.listen(clusterManager);
2328
client
24-
.requestShardData()
25-
.then(e => {
26-
if (!e) return;
27-
if (!e.shardList) return;
28-
clusterManager.totalShards = e.totalShards;
29-
clusterManager.totalClusters = e.shardList.length;
30-
// clusterManager.shardList = e.shardList;
31-
clusterManager.clusterList = e.clusterList;
32-
clusterManager.spawn({ timeout: -1 });
33-
})
34-
.catch(logger.error);
29+
.requestShardData()
30+
.then((e) => {
31+
if (!e) return;
32+
if (!e.shardList) return;
33+
clusterManager.totalShards = e.totalShards;
34+
clusterManager.totalClusters = e.shardList.length;
35+
// clusterManager.shardList = e.shardList;
36+
clusterManager.clusterList = e.clusterList;
37+
clusterManager.spawn({ timeout: -1 });
38+
})
39+
.catch(logger.error);

0 commit comments

Comments
 (0)