Skip to content

Commit

Permalink
feat: presence configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
zapteryx committed Apr 27, 2023
1 parent 9f72abb commit 887d3e2
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 4 deletions.
12 changes: 12 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
"warning": "Orange",
"error": "DarkRed"
},
"status": {
"presence": "online",
"activityType": "Listening",
"name": "music",
"url": "",
"showVersion": true
},
"defaultLocaleCode": "en",
"disableAd": false,
"supportServer": "https://discord.gg/",
Expand Down Expand Up @@ -77,6 +84,11 @@
| `applicationId` | Your application ID. Typically the same as your [bot's user ID](https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-).<br />Alternatively, you can get it from the [Discord Developer Portal](https://discord.com/developers/applications). || |
| `clientSecret` | Your client secret. You can get it from the [Discord Developer Portal](https://discord.com/developers/applications) under `OAuth2 > General`. || |
| `colors` | The colors used for embeds. Valid values are available [here](https://discord.js.org/#/docs/discord.js/main/typedef/ColorResolvable). || |
| `status.presence` | The presence. Valid values are `online`, `idle`, `dnd`, and `invisible`. || `6.10.0` |
| `status.activityType` | The activity type. Valid values are `Playing`, `Streaming`, `Listening`, `Watching`, and `Competing`. || `6.10.0` |
| `status.name` | The activity name. || `6.10.0` |
| `status.url` | The activity URL. Only used if `status.activityType` is `Streaming`. || `6.10.0` |
| `status.showVersion` | Whether to show the version in the status. || `6.10.0` |
| `defaultLocaleCode` | The default locale code. Valid values are available in the `locales` folder.<br />**Note:** This is used for all logs, slash command descriptions (at the time of deployment), and for all guilds without a language set in `/settings`. || |
| `disableAd` | Whether to disable the ad in the `info` command (Sponsor Us button).<br />**Note:** Please do not disable the ad unless you really need to. Sponsors help keep the development of ZPTXDev projects going. Consider sponsoring us if you need to disable the ad! || |
| `supportServer` | The support server invite link. This is used in the `info` command (Support Server button) and some messages in the event of an error. || `6.6.0` |
Expand Down
7 changes: 7 additions & 0 deletions settings.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
"warning": "Orange",
"error": "DarkRed"
},
"status": {
"presence": "online",
"activityType": "Listening",
"name": "music",
"url": "",
"showVersion": true
},
"defaultLocaleCode": "en",
"disableAd": false,
"supportServer": "https://discord.gg/",
Expand Down
49 changes: 47 additions & 2 deletions src/events/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { QuaverClient } from '#src/lib/util/common.d.js';
import { logger } from '#src/lib/util/common.js';
import { settings } from '#src/lib/util/settings.js';
import { version } from '#src/lib/util/version.js';
import type { PresenceStatusData } from 'discord.js';
import { ActivityType } from 'discord.js';

export default {
Expand Down Expand Up @@ -42,8 +43,52 @@ export default {
label: 'Quaver',
});
}
client.user.setActivity(`music | ${version}`, {
type: ActivityType.Listening,
let activityType:
| ActivityType.Playing
| ActivityType.Streaming
| ActivityType.Listening
| ActivityType.Watching
| ActivityType.Competing;
switch (settings.status.activityType.toLowerCase()) {
case 'streaming':
activityType = ActivityType.Streaming;
break;
case 'listening':
activityType = ActivityType.Listening;
break;
case 'watching':
activityType = ActivityType.Watching;
break;
case 'competing':
activityType = ActivityType.Competing;
break;
default:
activityType = ActivityType.Playing;
break;
}
let presence: PresenceStatusData = 'online';
if (
['online', 'idle', 'dnd', 'invisible'].includes(
settings.status.presence.toLowerCase(),
)
) {
presence =
settings.status.presence.toLowerCase() as PresenceStatusData;
}
client.user.setPresence({
status: presence,
activities: [
{
name: `${settings.status.name}${
settings.status.showVersion ? ` | ${version}` : ''
}`,
type: activityType,
url:
settings.status.url === ''
? undefined
: settings.status.url,
},
],
});
client.music.connect(client.user.id);
await client.application.commands.fetch();
Expand Down
50 changes: 48 additions & 2 deletions src/events/shardResume.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,60 @@
import { logger } from '#src/lib/util/common.js';
import { settings } from '#src/lib/util/settings.js';
import { version } from '#src/lib/util/version.js';
import type { PresenceStatusData } from 'discord.js';
import { ActivityType } from 'discord.js';

export default {
name: 'shardResume',
once: false,
async execute(): Promise<void> {
const { bot } = await import('#src/main.js');
bot.user.setActivity(`music | ${version}`, {
type: ActivityType.Listening,
let activityType:
| ActivityType.Playing
| ActivityType.Streaming
| ActivityType.Listening
| ActivityType.Watching
| ActivityType.Competing;
switch (settings.status.activityType.toLowerCase()) {
case 'streaming':
activityType = ActivityType.Streaming;
break;
case 'listening':
activityType = ActivityType.Listening;
break;
case 'watching':
activityType = ActivityType.Watching;
break;
case 'competing':
activityType = ActivityType.Competing;
break;
default:
activityType = ActivityType.Playing;
break;
}
let presence: PresenceStatusData = 'online';
if (
['online', 'idle', 'dnd', 'invisible'].includes(
settings.status.presence.toLowerCase(),
)
) {
presence =
settings.status.presence.toLowerCase() as PresenceStatusData;
}
bot.user.setPresence({
status: presence,
activities: [
{
name: `${settings.status.name}${
settings.status.showVersion ? ` | ${version}` : ''
}`,
type: activityType,
url:
settings.status.url === ''
? undefined
: settings.status.url,
},
],
});
logger.info({ message: 'Reconnected.', label: 'Discord' });
},
Expand Down
9 changes: 9 additions & 0 deletions src/lib/util/settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type SettingsObject = {
applicationId?: Snowflake;
clientSecret?: string;
colors?: ColorsSettingsObject;
status?: StatusSettingsObject;
defaultLocaleCode?: string;
developerMode?: boolean;
disableAd?: boolean;
Expand All @@ -26,6 +27,14 @@ export type ColorsSettingsObject = {
error?: ColorResolvable;
};

export type StatusSettingsObject = {
presence?: string;
activityType?: string;
name?: string;
url?: string;
showVersion?: boolean;
};

export type DatabaseSettingsObject = {
protocol?: string;
path?: string;
Expand Down

0 comments on commit 887d3e2

Please sign in to comment.