mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-04 14:06:07 +00:00
feat: Start shard with presence (#124)
* update presence on start * core impl
This commit is contained in:
parent
e4fa2a3ec3
commit
edef7989fe
@ -133,7 +133,12 @@ export type PickOptions = Pick<
|
||||
export interface BiscuitOptions {
|
||||
intents?: GatewayIntents;
|
||||
token: string;
|
||||
|
||||
precense?: {
|
||||
status: keyof typeof StatusTypes;
|
||||
afk: boolean;
|
||||
since: number | null;
|
||||
activities: Activities[];
|
||||
};
|
||||
events?: {
|
||||
adapter?: { new (...args: any[]): EventAdapter };
|
||||
options: any;
|
||||
@ -244,6 +249,7 @@ export class Session {
|
||||
token: this.options.token,
|
||||
intents: this.options.intents,
|
||||
},
|
||||
makePresence: this.options.precense
|
||||
};
|
||||
}
|
||||
|
||||
@ -341,39 +347,43 @@ export class Session {
|
||||
status: status.status,
|
||||
since: null,
|
||||
afk: false,
|
||||
activities: status.activities.map(activity => {
|
||||
return {
|
||||
name: activity.name,
|
||||
type: activity.type,
|
||||
url: activity.url,
|
||||
created_at: activity.createdAt,
|
||||
timestamps: activity.timestamps,
|
||||
application_id: this.applicationId,
|
||||
details: activity.details,
|
||||
state: activity.state,
|
||||
emoji: activity.emoji && {
|
||||
name: activity.emoji.name,
|
||||
id: activity.emoji.id,
|
||||
animated: activity.emoji.animated,
|
||||
},
|
||||
party: activity.party,
|
||||
assets: activity.assets &&
|
||||
{
|
||||
large_image: activity.assets.largeImage,
|
||||
large_text: activity.assets.largeText,
|
||||
small_image: activity.assets.smallImage,
|
||||
small_text: activity.assets.smallText,
|
||||
},
|
||||
secrets: activity.secrets,
|
||||
instance: activity.instance,
|
||||
flags: activity.flags,
|
||||
buttons: activity.buttons,
|
||||
};
|
||||
}),
|
||||
activities: this.makePresenceActivites(status.activities),
|
||||
},
|
||||
}, prio);
|
||||
}
|
||||
|
||||
private makePresenceActivites(act: Activities[]): Record<string, unknown>[] {
|
||||
return act.map(activity => {
|
||||
return {
|
||||
name: activity.name,
|
||||
type: activity.type,
|
||||
url: activity.url,
|
||||
created_at: activity.createdAt,
|
||||
timestamps: activity.timestamps,
|
||||
application_id: this.applicationId,
|
||||
details: activity.details,
|
||||
state: activity.state,
|
||||
emoji: activity.emoji && {
|
||||
name: activity.emoji.name,
|
||||
id: activity.emoji.id,
|
||||
animated: activity.emoji.animated,
|
||||
},
|
||||
party: activity.party,
|
||||
assets: activity.assets &&
|
||||
{
|
||||
large_image: activity.assets.largeImage,
|
||||
large_text: activity.assets.largeText,
|
||||
small_image: activity.assets.smallImage,
|
||||
small_text: activity.assets.smallText,
|
||||
},
|
||||
secrets: activity.secrets,
|
||||
instance: activity.instance,
|
||||
flags: activity.flags,
|
||||
buttons: activity.buttons,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// END PRESENCE
|
||||
|
||||
// INTERACTIONS
|
||||
|
@ -102,6 +102,8 @@ export class ShardManager {
|
||||
|
||||
config: this.options.config,
|
||||
|
||||
presence: this.options.makePresence,
|
||||
|
||||
handlePayloads: async (shard, payload) => {
|
||||
await this.options.handleDiscordPayload(shard, payload); // remove await?
|
||||
},
|
||||
|
@ -118,6 +118,7 @@ export class Shard {
|
||||
},
|
||||
intents: this.options.config.intents,
|
||||
shard: [this.options.id, this.options.gateway.shards],
|
||||
presence: this.options.presence
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import type { DiscordGatewayPayload, DiscordGetGatewayBot, GatewayIntents } from '@biscuitland/api-types';
|
||||
import type { DiscordGatewayPayload, DiscordGetGatewayBot, GatewayIntents, DiscordActivity } from '@biscuitland/api-types';
|
||||
|
||||
import type { ShardManager } from './services/shard-manager';
|
||||
import type { Shard } from './services/shard';
|
||||
@ -23,6 +23,14 @@ export interface SMO {
|
||||
token: string;
|
||||
};
|
||||
|
||||
/** Presence on identify */
|
||||
makePresence?: {
|
||||
status: 'idle' | 'dnd' | 'online' | 'offline';
|
||||
afk: boolean;
|
||||
since: number | null;
|
||||
activities: DiscordActivity[];
|
||||
};
|
||||
|
||||
/** Options shards */
|
||||
shards: ShardManagerShardsOptions;
|
||||
}
|
||||
@ -81,6 +89,9 @@ export interface SO {
|
||||
token: string;
|
||||
};
|
||||
|
||||
/** Presence on identify */
|
||||
presence?: ShardManagerOptions['makePresence'];
|
||||
|
||||
/** Function for interpretation of messages from discord */
|
||||
handlePayloads: (shard: Shard, data: DiscordGatewayPayload) => Promise<void>;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user