Files
discordeno/helpers/misc/editBotStatus.ts
Skillz4Killz a0a1554756 refactor: typings using ReturnType (#2105)
* fix: check new types idea

* fix: type errors

* fix: new style

* fix: more cleanup

* fix: more cleanup

* fix: cleanup audit logs

* fix: cleanup stickers

* fix: cleanup integrations

* fix: more cleanup

* fix: organize into 1 place

* fix: few errors

* fix: some broken import fixes

* fix: quite a lot of fixes across the board

* fix: more fixes for broken imports

* fix: more fixes for broken imports

* fix: handler imports

* fix: all remaining import errors

* fix: more errors needing fixes

* fix: clearing up transformers

* fix: few moer types

* fix: more cleanup of extra types

* fix: fmt

* fix: cleanup discordeno file

* Nuke Base Types (#2102)

* fix: cleanup snake stuff

* convert camelCase to snake_case (#2103)

* fix: add camelize

* fix: finalize remaining errors

* fix: imports in test

Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
2022-03-14 22:11:22 -04:00

78 lines
2.6 KiB
TypeScript

import type { Bot } from "../../bot.ts";
import { Activity } from "../../transformers/activity.ts";
import { StatusTypes } from "../../transformers/presence.ts";
import { GatewayOpcodes } from "../../types/shared.ts";
export function editBotStatus(bot: Bot, data: StatusUpdate) {
bot.gateway.shards.forEach((shard) => {
bot.events.debug(`Running forEach loop in editBotStatus function.`);
bot.gateway.sendShardMessage(bot.gateway, shard, {
op: GatewayOpcodes.PresenceUpdate,
d: {
since: null,
afk: false,
activities: data.activities.map((activity) => ({
name: activity.name,
type: activity.type,
url: activity.url,
created_at: activity.createdAt,
timestamps: activity.startedAt || activity.endedAt
? {
start: activity.startedAt,
end: activity.endedAt,
}
: undefined,
application_id: activity.applicationId?.toString(),
details: activity.details,
state: activity.state,
emoji: activity.emoji
? {
name: activity.emoji.name,
id: activity.emoji.id?.toString(),
animated: activity.emoji.animated,
}
: undefined,
party: activity.partyId
? {
id: activity.partyId.toString(),
size: activity.partyMaxSize,
}
: undefined,
assets: activity.largeImage || activity.largeText || activity.smallImage || activity.smallText
? {
large_image: activity.largeImage,
large_text: activity.largeText,
small_image: activity.smallImage,
small_text: activity.smallText,
}
: undefined,
secrets: activity.join || activity.spectate || activity.match
? {
join: activity.join,
spectate: activity.spectate,
match: activity.match,
}
: undefined,
instance: activity.instance,
flags: activity.flags,
buttons: activity.buttons,
})),
status: data.status,
},
});
});
}
/** https://discord.com/developers/docs/topics/gateway#update-status */
export interface StatusUpdate {
// /** Unix time (in milliseconds) of when the client went idle, or null if the client is not idle */
// since: number | null;
/** The user's activities */
activities: Activity[];
/** The user's new status */
status: StatusTypes;
// /** Whether or not the client is afk */
// afk: boolean;
}