Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/danclay/eris-fleet
Browse files Browse the repository at this point in the history
  • Loading branch information
danclay committed Mar 12, 2022
2 parents 24d99e6 + 185574a commit ad1e9a0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ To get started, you will need at least 2 files:
1. Your file which will create the fleet. This will be called "index.js" for now.
2. Your file containing your bot code. This will be called "bot.js" for now. This file will extend `BaseClusterWorker`

In the example below, the variable `options` is passed to the admiral. [Read the docs](https://danclay.github.io/eris-fleet/interfaces/options.html) for what options you can pass.
In the example below, the variable `options` is passed to the admiral. [Read the docs](https://danclay.github.io/eris-fleet/interfaces/Options.html) for what options you can pass.

Here is an example of `index.js`:
```js
Expand Down Expand Up @@ -220,11 +220,11 @@ Below is more in-depth documentation.

### Admiral options

Visit [the docs](https://danclay.github.io/eris-fleet/interfaces/options.html) for a complete list of options.
Visit [the docs](https://danclay.github.io/eris-fleet/interfaces/Options.html) for a complete list of options.

### Admiral events

Visit [the docs](https://danclay.github.io/eris-fleet/classes/fleet.html) for a complete list of events.
Visit [the docs](https://danclay.github.io/eris-fleet/classes/Fleet.html) for a complete list of events.

### Central Request Handler

Expand All @@ -236,15 +236,15 @@ If you are using a "very large bot," Discord's special gateway settings apply. E

### Concurrency

Eris-fleet supports concurrency by starting clusters at the same time based on your bot's `max_concurrency` value. The clusters are started together in groups. The `max_concurrency` value can be overridden with [options.maxConcurrencyOverride](https://danclay.github.io/eris-fleet/interfaces/options.html#maxconcurrencyoverride)
Eris-fleet supports concurrency by starting clusters at the same time based on your bot's `max_concurrency` value. The clusters are started together in groups. The `max_concurrency` value can be overridden with [options.maxConcurrencyOverride](https://danclay.github.io/eris-fleet/interfaces/Options.html#maxConcurrencyOverride)

### Formats

Visit [the docs](https://danclay.github.io/eris-fleet/modules.html) to view the Typescript interfaces.

### Choose what to log

You can choose what to log by using the `whatToLog` property in the options object. You can choose either a whitelist or a blacklist of what to log. You can select what to log by using an array. To possible array elements are shown [on the docs](https://danclay.github.io/eris-fleet/modules.html#loggingoptions). Here is an example of choosing what to log:
You can choose what to log by using the `whatToLog` property in the options object. You can choose either a whitelist or a blacklist of what to log. You can select what to log by using an array. To possible array elements are shown [on the docs](https://danclay.github.io/eris-fleet/modules.html#LoggingOptions). Here is an example of choosing what to log:
```js
const options = {
// Your other options
Expand All @@ -258,15 +258,15 @@ Change `whitelist` to `blacklist` if you want to use a blacklist. Change the arr

## IPC

Clusters and services can use IPC to interact with other clusters, the Admiral, and services. Visit [the IPC docs](https://danclay.github.io/eris-fleet/classes/ipc.html) to view available methods.
Clusters and services can use IPC to interact with other clusters, the Admiral, and services. Visit [the IPC docs](https://danclay.github.io/eris-fleet/classes/IPC.html) to view available methods.

## Stats

Stats are given in [this](https://danclay.github.io/eris-fleet/interfaces/stats.html) format.
Stats are given in [this](https://danclay.github.io/eris-fleet/interfaces/Stats.html) format.

## Using a specific version of Eris or a modified version of Eris

You can use an extended Eris client by passing it to the Options. (see the [options.customClient](https://danclay.github.io/eris-fleet/interfaces/options.html#customclient) section).
You can use an extended Eris client by passing it to the Options. (see the [options.customClient](https://danclay.github.io/eris-fleet/interfaces/Options.html#customclient) section).

Eris-fleet is able to use packages such as eris-additions if you desire. To do so, modify your bot file to match the following template:
```js
Expand Down
1 change: 1 addition & 0 deletions src/clusters/Cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class Cluster {

if (input.overrideConsole) {
console.log = (str: unknown) => {this.ipc.log(str);};
console.info = (str: unknown) => {this.ipc.info(str);};
console.debug = (str: unknown) => {this.ipc.debug(str);};
console.error = (str: unknown) => {this.ipc.error(str);};
console.warn = (str: unknown) => {this.ipc.warn(str);};
Expand Down
1 change: 1 addition & 0 deletions src/services/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class Service {

if (input.overrideConsole) {
console.log = (str: unknown) => {this.ipc.log(str);};
console.info = (str: unknown) => {this.ipc.info(str);};
console.debug = (str: unknown) => {this.ipc.debug(str);};
console.error = (str: unknown) => {this.ipc.error(str);};
console.warn = (str: unknown) => {this.ipc.warn(str);};
Expand Down
15 changes: 12 additions & 3 deletions src/sharding/Admiral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ export class Admiral extends EventEmitter {
}
}
this.emit(message.type, shardEmit);
if (this.broadcastAdmiralEvents) this.broadcast(message.type, shardEmit);
break;
}
default: {
Expand Down Expand Up @@ -990,7 +991,7 @@ export class Admiral extends EventEmitter {
}

private ipcMessageHandler(worker: FakeWorker, message: any) {
const logSourced = (type: "log" | "warn" | "error" | "debug", msg: string) => {
const logSourced = (type: "log" | "info" | "warn" | "error" | "debug", msg: string) => {
let source = `Worker ${worker.id}`;
if (worker.id === "master") {
source = "Admiral";
Expand All @@ -1009,6 +1010,10 @@ export class Admiral extends EventEmitter {
this.ipcLog("log", message, worker);
break;
}
case "info": {
this.ipcLog("info", message, worker);
break;
}
case "debug": {
this.ipcLog("debug", message, worker);
break;
Expand Down Expand Up @@ -2592,7 +2597,7 @@ export class Admiral extends EventEmitter {
}
}

private ipcLog(type: "log" | "error" | "warn" | "debug", message: unknown, worker: FakeWorker) {
private ipcLog(type: "log" | "info" | "error" | "warn" | "debug", message: unknown, worker: FakeWorker) {
// convert log if convered
let messageToLog = message;
let source;
Expand Down Expand Up @@ -2651,7 +2656,7 @@ export class Admiral extends EventEmitter {
this.emitLog(type, messageToLog, source);
}

private emitLog(type: "log" | "error" | "warn" | "debug", message: unknown, source?: string) {
private emitLog(type: "log" | "info" | "error" | "warn" | "debug", message: unknown, source?: string) {
let log = message;
if (this.objectLogging) {
log = {
Expand Down Expand Up @@ -2679,6 +2684,10 @@ export class Admiral extends EventEmitter {
this.emitLog("log", message, source);
}

public info(message: unknown, source?: string): void {
this.emitLog("info", message, source);
}

public warn(message: unknown, source?: string): void {
this.emitLog("warn", message, source);
}
Expand Down
19 changes: 16 additions & 3 deletions src/util/IPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Collection } from "../util/Collection";
import { isMaster } from "cluster";

export interface IpcHandledLog {
op: "log" | "error" | "warn" | "debug",
op: "log" | "info" | "error" | "warn" | "debug",
ipcLogObject: boolean,
msg: unknown,
source?: string,
Expand Down Expand Up @@ -187,7 +187,7 @@ export class IPC extends EventEmitter {
}
}

private sendLog(type: "log" | "error" | "warn" | "debug", value: unknown, source?: string) {
private sendLog(type: "log" | "info" | "error" | "warn" | "debug", value: unknown, source?: string) {
let valueToSend = value;
let valueTranslatedFrom: string | undefined = undefined;

Expand Down Expand Up @@ -219,6 +219,19 @@ export class IPC extends EventEmitter {
this.sendLog("log", message, source);
}

/**
* Sends an info log to the Admiral
* @param message Item to log
* @param source Custom error source
* @example
* ```js
* this.ipc.info("You might want to take a look at this");
* ```
*/
public info(message: unknown, source?: string): void {
this.sendLog("info", message, source);
}

/**
* Sends an error log to the Admiral
* @param message Item to log
Expand Down Expand Up @@ -259,7 +272,7 @@ export class IPC extends EventEmitter {
}

/**
* Register for an event. This will receive broadcasts and messages sent to this cluster.
* Register for an event. This will receive broadcasts and messages sent to this cluster. This will also receive Admiral events if broadcastAdmiralEvents is enabled in options.
* Events can be sent using {@link sendTo} and {@link broadcast}
* @param event Name of the event
* @param callback Function run when event is received
Expand Down

0 comments on commit ad1e9a0

Please sign in to comment.