Skip to content

Commit 390e3e1

Browse files
committed
📝 docs: standardize presence listener pattern across languages
1 parent 47a02eb commit 390e3e1

6 files changed

Lines changed: 207 additions & 78 deletions

File tree

en/presence/presence-overview.mdx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ The presence system integrates with the sharding system. When your bot runs acro
2020
The simplest use case is setting a fixed activity that stays until you change it. Call *PresenceManager.setActivity* with a name and a type. The name is the text that appears in the member list, and the type determines the prefix Discord adds (Playing, Watching, Listening, Streaming, or Competing).
2121

2222
```typescript filename="src/listeners/ready.listener.ts"
23-
import { Listener, On } from '@spraxium/core';
23+
import { Events, Listener, Once } from '@spraxium/common';
2424
import { PresenceManager } from '@spraxium/core';
2525

26-
@Listener()
26+
@Listener(Events.ClientReady)
2727
export class ReadyListener {
28-
@On('clientReady')
29-
onReady() {
28+
@Once()
29+
onReady(): void {
3030
PresenceManager.setActivity({
31-
name: 'your commands', type: 'Listening', });
31+
name: 'your commands',
32+
type: 'Listening',
33+
});
3234
}
3335
}
3436
```
@@ -37,7 +39,9 @@ The *setActivity* method only changes the activity. It does not touch the status
3739

3840
```typescript filename="src/listeners/ready.listener.ts"
3941
PresenceManager.setPresence({
40-
status: 'dnd', activities: [{ name: 'maintenance mode', type: 'Playing' }], });
42+
status: 'dnd',
43+
activities: [{ name: 'maintenance mode', type: 'Playing' }],
44+
});
4145
```
4246

4347
## Changing only the status
@@ -89,7 +93,9 @@ Placeholders work everywhere activities are used: in *setActivity*, *setPresence
8993

9094
```typescript filename="src/listeners/ready.listener.ts"
9195
PresenceManager.setActivity({
92-
name: '{{totalServers}} servers · {{ping}}ms', type: 'Watching', });
96+
name: '{{totalServers}} servers · {{ping}}ms',
97+
type: 'Watching',
98+
});
9399
```
94100

95101
## Boot configuration
@@ -102,8 +108,9 @@ Instead of calling *PresenceManager* methods in a listener, you can declare the
102108
import type { PresenceOptions } from '@spraxium/core';
103109

104110
export const presenceConfig: PresenceOptions = {
105-
status: 'online', activities: [
106-
{ name: '{{totalServers}} servers', type: 'Watching' }, ], };
111+
status: 'online',
112+
activities: [{ name: '{{totalServers}} servers', type: 'Watching' }],
113+
};
107114
```
108115
</Tab>
109116
<Tab label="src/main.ts">
@@ -113,7 +120,9 @@ import { presenceConfig } from '../config/presence.config';
113120
import { AppModule } from './app.module';
114121

115122
async function main() {
116-
const app = await SpraxiumFactory.create({ token: process.env.DISCORD_TOKEN });
123+
const app = await SpraxiumFactory.create({
124+
token: process.env.DISCORD_TOKEN,
125+
});
117126
app.useModule(AppModule);
118127
app.initPresence(presenceConfig);
119128
await app.listen();

en/presence/presence-rotation-shards.mdx

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@ category: Presence
1212
When your bot has multiple things to say, you can cycle through activities on a fixed interval. The *startRotation* method accepts an array of activities and a millisecond interval. It sets the first activity immediately, then advances to the next one every time the interval fires. The rotation wraps around when it reaches the end of the array.
1313

1414
```typescript filename="src/listeners/ready.listener.ts"
15-
import { Listener, On } from '@spraxium/core';
15+
import { Events, Listener, Once } from '@spraxium/common';
1616
import { PresenceManager } from '@spraxium/core';
1717

18-
@Listener()
18+
@Listener(Events.ClientReady)
1919
export class ReadyListener {
20-
@On('clientReady')
21-
onReady() {
22-
PresenceManager.startRotation([
23-
{ name: '{{totalServers}} servers', type: 'Watching' }, { name: '/help for commands', type: 'Playing' }, { name: 'feedback from users', type: 'Listening' }, ], 30_000);
20+
@Once()
21+
onReady(): void {
22+
PresenceManager.startRotation(
23+
[
24+
{ name: '{{totalServers}} servers', type: 'Watching' },
25+
{ name: '/help for commands', type: 'Playing' },
26+
{ name: 'feedback from users', type: 'Listening' },
27+
],
28+
30_000,
29+
);
2430
}
2531
}
2632
```
@@ -35,8 +41,14 @@ You can also configure rotation at boot time by setting *rotateInterval* in your
3541
import type { PresenceOptions } from '@spraxium/core';
3642

3743
export const presenceConfig: PresenceOptions = {
38-
status: 'online', activities: [
39-
{ name: '{{totalServers}} servers', type: 'Watching' }, { name: '/help', type: 'Playing' }, { name: '{{ping}}ms latency', type: 'Competing' }, ], rotateInterval: 20_000, };
44+
status: 'online',
45+
activities: [
46+
{ name: '{{totalServers}} servers', type: 'Watching' },
47+
{ name: '/help', type: 'Playing' },
48+
{ name: '{{ping}}ms latency', type: 'Competing' },
49+
],
50+
rotateInterval: 20_000,
51+
};
4052
```
4153
</Tab>
4254
<Tab label="src/main.ts">
@@ -46,7 +58,9 @@ import { presenceConfig } from '../config/presence.config';
4658
import { AppModule } from './app.module';
4759

4860
async function main() {
49-
const app = await SpraxiumFactory.create({ token: process.env.DISCORD_TOKEN });
61+
const app = await SpraxiumFactory.create({
62+
token: process.env.DISCORD_TOKEN,
63+
});
5064
app.useModule(AppModule);
5165
app.initPresence(presenceConfig);
5266
await app.listen();
@@ -65,7 +79,10 @@ The *stopRotation* method clears the interval timer. The last active activity re
6579
import { PresenceManager } from '@spraxium/core';
6680

6781
PresenceManager.stopRotation();
68-
PresenceManager.setActivity({ name: 'maintenance in progress', type: 'Playing' });
82+
PresenceManager.setActivity({
83+
name: 'maintenance in progress',
84+
type: 'Playing',
85+
});
6986
```
7087

7188
## Per-shard presence at boot
@@ -80,10 +97,19 @@ For deeper customization, the *PresenceOptions* object supports a *perShard* rec
8097
import type { PresenceOptions } from '@spraxium/core';
8198

8299
export const presenceConfig: PresenceOptions = {
83-
status: 'online', activities: [
84-
{ name: 'Shard {{shardNumber}}/{{totalShards}}', type: 'Playing' }, ], perShard: {
100+
status: 'online',
101+
activities: [
102+
{ name: 'Shard {{shardNumber}}/{{totalShards}}', type: 'Playing' },
103+
],
104+
perShard: {
85105
0: {
86-
status: 'dnd', activities: [{ name: 'Primary shard · {{totalServers}} guilds', type: 'Watching' }], }, }, };
106+
status: 'dnd',
107+
activities: [
108+
{ name: 'Primary shard · {{totalServers}} guilds', type: 'Watching' },
109+
],
110+
},
111+
},
112+
};
87113
```
88114
</Tab>
89115
<Tab label="src/main.ts">
@@ -93,7 +119,9 @@ import { presenceConfig } from '../config/presence.config';
93119
import { AppModule } from './app.module';
94120

95121
async function main() {
96-
const app = await SpraxiumFactory.create({ token: process.env.DISCORD_TOKEN });
122+
const app = await SpraxiumFactory.create({
123+
token: process.env.DISCORD_TOKEN,
124+
});
97125
app.useModule(AppModule);
98126
app.initPresence(presenceConfig);
99127
await app.listen();
@@ -117,8 +145,14 @@ import { PresenceManager } from '@spraxium/core';
117145
@Injectable()
118146
export class ShardStatusService {
119147
updateShardActivity(shardId: number, version: string) {
120-
PresenceManager.setShardActivity(shardId, {
121-
name: 'v{{version}} · {{totalServers}} guilds on shard {{shardNumber}}', type: 'Playing', }, { version });
148+
PresenceManager.setShardActivity(
149+
shardId,
150+
{
151+
name: 'v{{version}} · {{totalServers}} guilds on shard {{shardNumber}}',
152+
type: 'Playing',
153+
},
154+
{ version },
155+
);
122156
}
123157

124158
resetShard(shardId: number) {

es/presence/presence-overview.mdx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ El sistema de presencia se integra con el sistema de sharding. Cuando tu bot cor
2020
El caso de uso más simple es definir una actividad fija que permanece hasta que la cambies. Llama a *PresenceManager.setActivity* con un nombre y un tipo. El nombre es el texto que aparece en la lista de miembros, y el tipo determina el prefijo que Discord agrega (Jugando, Viendo, Escuchando, Transmitiendo o Compitiendo).
2121

2222
```typescript filename="src/listeners/ready.listener.ts"
23-
import { Listener, On } from '@spraxium/core';
23+
import { Events, Listener, Once } from '@spraxium/common';
2424
import { PresenceManager } from '@spraxium/core';
2525

26-
@Listener()
26+
@Listener(Events.ClientReady)
2727
export class ReadyListener {
28-
@On('clientReady')
29-
onReady() {
28+
@Once()
29+
onReady(): void {
3030
PresenceManager.setActivity({
31-
name: 'your commands', type: 'Listening', });
31+
name: 'your commands',
32+
type: 'Listening',
33+
});
3234
}
3335
}
3436
```
@@ -37,7 +39,9 @@ El método *setActivity* solo cambia la actividad. No toca el indicador de estad
3739

3840
```typescript filename="src/listeners/ready.listener.ts"
3941
PresenceManager.setPresence({
40-
status: 'dnd', activities: [{ name: 'maintenance mode', type: 'Playing' }], });
42+
status: 'dnd',
43+
activities: [{ name: 'maintenance mode', type: 'Playing' }],
44+
});
4145
```
4246

4347
## Cambiando solo el estado
@@ -89,7 +93,9 @@ Los placeholders funcionan en todos los lugares donde se usan actividades: en *s
8993

9094
```typescript filename="src/listeners/ready.listener.ts"
9195
PresenceManager.setActivity({
92-
name: '{{totalServers}} servers · {{ping}}ms', type: 'Watching', });
96+
name: '{{totalServers}} servers · {{ping}}ms',
97+
type: 'Watching',
98+
});
9399
```
94100

95101
## Configuración de boot
@@ -102,8 +108,9 @@ En lugar de llamar métodos del *PresenceManager* en un listener, puedes declara
102108
import type { PresenceOptions } from '@spraxium/core';
103109

104110
export const presenceConfig: PresenceOptions = {
105-
status: 'online', activities: [
106-
{ name: '{{totalServers}} servers', type: 'Watching' }, ], };
111+
status: 'online',
112+
activities: [{ name: '{{totalServers}} servers', type: 'Watching' }],
113+
};
107114
```
108115
</Tab>
109116
<Tab label="src/main.ts">
@@ -113,7 +120,9 @@ import { presenceConfig } from '../config/presence.config';
113120
import { AppModule } from './app.module';
114121

115122
async function main() {
116-
const app = await SpraxiumFactory.create({ token: process.env.DISCORD_TOKEN });
123+
const app = await SpraxiumFactory.create({
124+
token: process.env.DISCORD_TOKEN,
125+
});
117126
app.useModule(AppModule);
118127
app.initPresence(presenceConfig);
119128
await app.listen();

es/presence/presence-rotation-shards.mdx

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@ category: Presence
1212
Cuando tu bot tiene múltiples cosas para mostrar, puedes ciclar actividades en un intervalo fijo. El método *startRotation* acepta un array de actividades y un intervalo en milisegundos. Define la primera actividad inmediatamente, luego avanza a la siguiente cada vez que el intervalo se dispara. La rotación vuelve al inicio cuando llega al final del array.
1313

1414
```typescript filename="src/listeners/ready.listener.ts"
15-
import { Listener, On } from '@spraxium/core';
15+
import { Events, Listener, Once } from '@spraxium/common';
1616
import { PresenceManager } from '@spraxium/core';
1717

18-
@Listener()
18+
@Listener(Events.ClientReady)
1919
export class ReadyListener {
20-
@On('clientReady')
21-
onReady() {
22-
PresenceManager.startRotation([
23-
{ name: '{{totalServers}} servers', type: 'Watching' }, { name: '/help for commands', type: 'Playing' }, { name: 'feedback from users', type: 'Listening' }, ], 30_000);
20+
@Once()
21+
onReady(): void {
22+
PresenceManager.startRotation(
23+
[
24+
{ name: '{{totalServers}} servers', type: 'Watching' },
25+
{ name: '/help for commands', type: 'Playing' },
26+
{ name: 'feedback from users', type: 'Listening' },
27+
],
28+
30_000,
29+
);
2430
}
2531
}
2632
```
@@ -35,8 +41,14 @@ También puedes configurar la rotación en el boot definiendo *rotateInterval* e
3541
import type { PresenceOptions } from '@spraxium/core';
3642

3743
export const presenceConfig: PresenceOptions = {
38-
status: 'online', activities: [
39-
{ name: '{{totalServers}} servers', type: 'Watching' }, { name: '/help', type: 'Playing' }, { name: '{{ping}}ms latency', type: 'Competing' }, ], rotateInterval: 20_000, };
44+
status: 'online',
45+
activities: [
46+
{ name: '{{totalServers}} servers', type: 'Watching' },
47+
{ name: '/help', type: 'Playing' },
48+
{ name: '{{ping}}ms latency', type: 'Competing' },
49+
],
50+
rotateInterval: 20_000,
51+
};
4052
```
4153
</Tab>
4254
<Tab label="src/main.ts">
@@ -46,7 +58,9 @@ import { presenceConfig } from '../config/presence.config';
4658
import { AppModule } from './app.module';
4759

4860
async function main() {
49-
const app = await SpraxiumFactory.create({ token: process.env.DISCORD_TOKEN });
61+
const app = await SpraxiumFactory.create({
62+
token: process.env.DISCORD_TOKEN,
63+
});
5064
app.useModule(AppModule);
5165
app.initPresence(presenceConfig);
5266
await app.listen();
@@ -65,7 +79,10 @@ El método *stopRotation* limpia el temporizador de intervalo. La última activi
6579
import { PresenceManager } from '@spraxium/core';
6680

6781
PresenceManager.stopRotation();
68-
PresenceManager.setActivity({ name: 'maintenance in progress', type: 'Playing' });
82+
PresenceManager.setActivity({
83+
name: 'maintenance in progress',
84+
type: 'Playing',
85+
});
6986
```
7087

7188
## Presencia por shard en el boot
@@ -80,10 +97,19 @@ Para una personalización más profunda, el objeto *PresenceOptions* soporta un
8097
import type { PresenceOptions } from '@spraxium/core';
8198

8299
export const presenceConfig: PresenceOptions = {
83-
status: 'online', activities: [
84-
{ name: 'Shard {{shardNumber}}/{{totalShards}}', type: 'Playing' }, ], perShard: {
100+
status: 'online',
101+
activities: [
102+
{ name: 'Shard {{shardNumber}}/{{totalShards}}', type: 'Playing' },
103+
],
104+
perShard: {
85105
0: {
86-
status: 'dnd', activities: [{ name: 'Primary shard · {{totalServers}} guilds', type: 'Watching' }], }, }, };
106+
status: 'dnd',
107+
activities: [
108+
{ name: 'Primary shard · {{totalServers}} guilds', type: 'Watching' },
109+
],
110+
},
111+
},
112+
};
87113
```
88114
</Tab>
89115
<Tab label="src/main.ts">
@@ -93,7 +119,9 @@ import { presenceConfig } from '../config/presence.config';
93119
import { AppModule } from './app.module';
94120

95121
async function main() {
96-
const app = await SpraxiumFactory.create({ token: process.env.DISCORD_TOKEN });
122+
const app = await SpraxiumFactory.create({
123+
token: process.env.DISCORD_TOKEN,
124+
});
97125
app.useModule(AppModule);
98126
app.initPresence(presenceConfig);
99127
await app.listen();
@@ -117,8 +145,14 @@ import { PresenceManager } from '@spraxium/core';
117145
@Injectable()
118146
export class ShardStatusService {
119147
updateShardActivity(shardId: number, version: string) {
120-
PresenceManager.setShardActivity(shardId, {
121-
name: 'v{{version}} · {{totalServers}} guilds on shard {{shardNumber}}', type: 'Playing', }, { version });
148+
PresenceManager.setShardActivity(
149+
shardId,
150+
{
151+
name: 'v{{version}} · {{totalServers}} guilds on shard {{shardNumber}}',
152+
type: 'Playing',
153+
},
154+
{ version },
155+
);
122156
}
123157

124158
resetShard(shardId: number) {

0 commit comments

Comments
 (0)