Skip to content

Commit

Permalink
Make PresenceOptions a partial
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciach0 committed Jan 22, 2023
1 parent d96ce2e commit 612884c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ yarn-error.log*

dist/
**/dist/
src/testing/
26 changes: 20 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
"npm": ">=7.0.0",
"node": ">=14.0.0"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"dependencies": {
"dotenv": "^16.0.3"
}
}
25 changes: 20 additions & 5 deletions packages/tiscord/src/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import process from 'node:process';
import { arch, release, type } from 'node:os';
import { EventEmitter } from 'node:events';
import { GatewayIntentBits, GatewayPresenceUpdateData } from 'discord-api-types/v10';
import { GatewayIntentBits, GatewayPresenceUpdateData, PresenceUpdateStatus } from 'discord-api-types/v10';
import { REST } from '../rest/REST';
// @ts-expect-error
import { version } from '../../package.json';
Expand Down Expand Up @@ -75,7 +75,7 @@ export class Client extends EventEmitter {
raw: boolean;
cacheOptions: CacheOptions;
debugLogs: typeof console.log;
presence: GatewayPresenceUpdateData;
presence: Partial<GatewayPresenceUpdateData>;
allowedMentions: RawMentions;
applicationId: bigint;
applicationCommands: ApplicationCommandManager;
Expand All @@ -99,7 +99,14 @@ export class Client extends EventEmitter {
this.applicationCommands = new ApplicationCommandManager(this);
this.debugLogs = options.debug;
if (options.allowedMentions) this.allowedMentions = new AllowedMentions(options.allowedMentions);
this.presence = options.presence;
this.presence = {
activities: [
...options.presence?.activities
],
status: options.presence?.status ?? PresenceUpdateStatus.Online,
since: options.presence?.since ?? null,
afk: options.presence?.afk ?? false
};
this.cache = {
members: this.cacheOptions?.members === false ? new FakeCache() : new Cache<Member>(),
guilds: this.cacheOptions?.guilds === false ? new FakeMap() : new Map<bigint, Guild>(),
Expand Down Expand Up @@ -144,7 +151,15 @@ export class Client extends EventEmitter {
* Change the bot's presence
* @param options - The presence options
*/
setPresence(options: GatewayPresenceUpdateData): void {
this.ws.send({ op: 3, d: options });
setPresence(options: Partial<GatewayPresenceUpdateData>): void {
this.ws.send({
op: 3,
d: {
activities: [...options.activities],
status: options.status ?? PresenceUpdateStatus.Online,
afk: options.afk ?? false,
since: options.since ?? null
}
});
}
}
4 changes: 2 additions & 2 deletions packages/tiscord/src/options/ClientOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { APIAllowedMentions, GatewayIntentBits, GatewayPresenceUpdateData } from
* @property {boolean} rawDataStorage - Whether to store raw data, turning it on might make ram usage a lot higher
* @property {CacheOptions} cache - Cache options
* @property {boolean} debug - Whether to enable debug logs
* @property {GatewayPresenceUpdateData} presence - Presence data
* @property {Partial<GatewayPresenceUpdateData>} presence - Presence data
* @property {APIAllowedMentions} allowedMentions - Allowed mentions
*/
export interface ClientOptions {
Expand All @@ -20,6 +20,6 @@ export interface ClientOptions {
rawDataStorage?: boolean;
cache?: CacheOptions;
debug?: typeof console.log;
presence?: GatewayPresenceUpdateData;
presence?: Partial<GatewayPresenceUpdateData>;
allowedMentions?: APIAllowedMentions;
}

0 comments on commit 612884c

Please sign in to comment.