mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
feat: http voice states (#235)
* feat: http voice states * fix: ups * fix: typo * fix: structure
This commit is contained in:
parent
571ab18f4f
commit
d6ff9767a1
@ -15,6 +15,7 @@ import type {
|
||||
RESTGetAPIAuditLogResult,
|
||||
RESTGetAPIAutoModerationRuleResult,
|
||||
RESTGetAPIAutoModerationRulesResult,
|
||||
RESTGetAPICurrentUserVoiceState,
|
||||
RESTGetAPIGuildBanResult,
|
||||
RESTGetAPIGuildBansQuery,
|
||||
RESTGetAPIGuildBansResult,
|
||||
@ -53,6 +54,7 @@ import type {
|
||||
RESTGetAPIGuildWidgetJSONResult,
|
||||
RESTGetAPIGuildWidgetSettingsResult,
|
||||
RESTGetAPITemplateResult,
|
||||
RESTGetAPIUserVoiceState,
|
||||
RESTPatchAPIAutoModerationRuleJSONBody,
|
||||
RESTPatchAPIAutoModerationRuleResult,
|
||||
RESTPatchAPICurrentGuildMemberJSONBody,
|
||||
@ -313,13 +315,15 @@ export interface GuildRoutes {
|
||||
patch(
|
||||
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody>,
|
||||
): Promise<RESTPatchAPIGuildVoiceStateCurrentMemberResult>;
|
||||
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPICurrentUserVoiceState>;
|
||||
};
|
||||
(
|
||||
id: string,
|
||||
userId: string,
|
||||
): {
|
||||
patch(
|
||||
args: RestArguments<ProxyRequestMethod.Patch, RESTPatchAPIGuildVoiceStateUserJSONBody>,
|
||||
): Promise<RESTPatchAPIGuildVoiceStateUserResult>;
|
||||
get(args?: RestArguments<ProxyRequestMethod.Get>): Promise<RESTGetAPIUserVoiceState>;
|
||||
};
|
||||
};
|
||||
stickers: {
|
||||
|
14
src/cache/resources/voice-states.ts
vendored
14
src/cache/resources/voice-states.ts
vendored
@ -1,14 +1,14 @@
|
||||
import type { GatewayVoiceState } from '../../types';
|
||||
import type { APIVoiceState } from '../../types';
|
||||
import type { ReturnCache } from '../..';
|
||||
import { fakePromise } from '../../common';
|
||||
import { GuildBasedResource } from './default/guild-based';
|
||||
import { Transformers, type VoiceStateStructure } from '../../client/transformers';
|
||||
|
||||
export class VoiceStates extends GuildBasedResource<any, GatewayVoiceState> {
|
||||
export class VoiceStates extends GuildBasedResource<any, APIVoiceState> {
|
||||
namespace = 'voice_state';
|
||||
|
||||
//@ts-expect-error
|
||||
filter(data: GatewayVoiceState, id: string, guild_id: string) {
|
||||
filter(data: APIVoiceState, id: string, guild_id: string) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ export class VoiceStates extends GuildBasedResource<any, GatewayVoiceState> {
|
||||
);
|
||||
}
|
||||
|
||||
raw(memberId: string, guildId: string): ReturnCache<GatewayVoiceState | undefined> {
|
||||
raw(memberId: string, guildId: string): ReturnCache<APIVoiceState | undefined> {
|
||||
return super.get(memberId, guildId);
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ export class VoiceStates extends GuildBasedResource<any, GatewayVoiceState> {
|
||||
);
|
||||
}
|
||||
|
||||
bulkRaw(ids: string[], guild: string): ReturnCache<GatewayVoiceState[]> {
|
||||
bulkRaw(ids: string[], guild: string): ReturnCache<APIVoiceState[]> {
|
||||
return super.bulk(ids, guild);
|
||||
}
|
||||
|
||||
@ -46,9 +46,9 @@ export class VoiceStates extends GuildBasedResource<any, GatewayVoiceState> {
|
||||
);
|
||||
}
|
||||
|
||||
valuesRaw(guildId: string): ReturnCache<GatewayVoiceState[]> {
|
||||
valuesRaw(guildId: string): ReturnCache<APIVoiceState[]> {
|
||||
return super.values(guildId);
|
||||
}
|
||||
}
|
||||
|
||||
export type VoiceStateResource = Omit<GatewayVoiceState, 'member'> & { guild_id: string };
|
||||
export type VoiceStateResource = Omit<APIVoiceState, 'member'> & { guild_id: string };
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
import { PermissionsBitField } from '../../structures/extra/Permissions';
|
||||
import type { GuildMemberResolvable } from '../types/resolvables';
|
||||
import { BaseShorter } from './base';
|
||||
import { Transformers } from '../../client/transformers';
|
||||
import { Transformers, type VoiceStateStructure } from '../../client/transformers';
|
||||
|
||||
export class MemberShorter extends BaseShorter {
|
||||
/**
|
||||
@ -222,8 +222,17 @@ export class MemberShorter extends BaseShorter {
|
||||
return this.client.cache.presences?.get(memberId);
|
||||
}
|
||||
|
||||
voice(guildId: string, memberId: string) {
|
||||
return this.client.cache.voiceStates?.get(memberId, guildId);
|
||||
async voice(guildId: string, memberId: '@me', force?: boolean): Promise<VoiceStateStructure>;
|
||||
async voice(guildId: string, memberId: string, force?: boolean): Promise<VoiceStateStructure>;
|
||||
async voice(guildId: string, memberId: string | '@me', force = false) {
|
||||
if (!force) {
|
||||
const state = await this.client.cache.voiceStates?.get(memberId, guildId);
|
||||
if (state) return state;
|
||||
}
|
||||
|
||||
const state = await this.client.proxy.guilds(guildId)['voice-states'](memberId).get();
|
||||
await this.client.cache.voiceStates?.set(memberId, guildId, state);
|
||||
return Transformers.VoiceState(this.client, state);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,8 +74,8 @@ export class BaseGuildMember extends DiscordBase {
|
||||
return this.client.members.presence(this.id);
|
||||
}
|
||||
|
||||
voice() {
|
||||
return this.client.members.voice(this.guildId, this.id);
|
||||
voice(force = false) {
|
||||
return this.client.members.voice(this.guildId, this.id, force);
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
@ -2,14 +2,14 @@ import type { UsingClient } from '../';
|
||||
import type { VoiceStateResource } from '../cache/resources/voice-states';
|
||||
import { type GuildMemberStructure, Transformers } from '../client/transformers';
|
||||
import type { ObjectToLower } from '../common';
|
||||
import type { GatewayVoiceState } from '../types';
|
||||
import type { APIVoiceState } from '../types';
|
||||
import { Base } from './extra/Base';
|
||||
|
||||
export interface VoiceState extends Base, ObjectToLower<Omit<VoiceStateResource, 'member'>> {}
|
||||
|
||||
export class VoiceState extends Base {
|
||||
protected withMember?: GuildMemberStructure;
|
||||
constructor(client: UsingClient, data: GatewayVoiceState) {
|
||||
constructor(client: UsingClient, data: APIVoiceState) {
|
||||
super(client);
|
||||
const { member, ...rest } = data;
|
||||
this.__patchThis(rest);
|
||||
@ -68,6 +68,11 @@ export class VoiceState extends Base {
|
||||
return this.setChannel(null, reason);
|
||||
}
|
||||
|
||||
async fetch(force = false) {
|
||||
const member = this.withMember ?? (await this.member(force));
|
||||
return this.client.members.voice(this.guildId, member.id, force);
|
||||
}
|
||||
|
||||
async setChannel(channel_id: null | string, reason?: string) {
|
||||
const member = await this.client.members.edit(this.guildId, this.userId, { channel_id }, reason);
|
||||
this.channelId = channel_id;
|
||||
|
@ -26,7 +26,7 @@ import type {
|
||||
GatewayPresenceUpdate as RawGatewayPresenceUpdate,
|
||||
GatewayThreadListSync as RawGatewayThreadListSync,
|
||||
GatewayThreadMembersUpdate as RawGatewayThreadMembersUpdate,
|
||||
GatewayVoiceState,
|
||||
APIVoiceState,
|
||||
InviteTargetType,
|
||||
PresenceUpdateStatus,
|
||||
AutoModerationRuleTriggerType,
|
||||
@ -554,7 +554,7 @@ export interface GatewayGuildCreateDispatchData extends APIGuild {
|
||||
*
|
||||
* See https://discord.com/developers/docs/resources/voice#voice-state-object
|
||||
*/
|
||||
voice_states: Omit<GatewayVoiceState, 'guild_id'>[];
|
||||
voice_states: Omit<APIVoiceState, 'guild_id'>[];
|
||||
/**
|
||||
* Users in the guild
|
||||
*
|
||||
@ -1517,7 +1517,7 @@ export type GatewayVoiceStateUpdateDispatch = DataPayload<
|
||||
/**
|
||||
* https://discord.com/developers/docs/topics/gateway-events#voice-state-update
|
||||
*/
|
||||
export type GatewayVoiceStateUpdateDispatchData = GatewayVoiceState;
|
||||
export type GatewayVoiceStateUpdateDispatchData = APIVoiceState;
|
||||
|
||||
/**
|
||||
* https://discord.com/developers/docs/topics/gateway-events#voice-server-update
|
||||
|
@ -681,6 +681,8 @@ export enum MessageType {
|
||||
GuildIncidentAlertModeDisabled,
|
||||
GuildIncidentReportRaid,
|
||||
GuildIncidentReportFalseAlarm,
|
||||
PurchaseNotification = 44,
|
||||
PollResult = 46,
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,7 +8,7 @@ import type { APIGuildMember } from './guild';
|
||||
/**
|
||||
* https://discord.com/developers/docs/resources/voice#voice-state-object
|
||||
*/
|
||||
export interface GatewayVoiceState {
|
||||
export interface APIVoiceState {
|
||||
/**
|
||||
* The guild id this voice state is for
|
||||
*/
|
||||
|
@ -1,10 +1,20 @@
|
||||
import type { APIVoiceRegion } from '../payloads';
|
||||
import type { APIVoiceRegion, APIVoiceState } from '../payloads';
|
||||
|
||||
/**
|
||||
* https://discord.com/developers/docs/resources/voice#list-voice-regions
|
||||
*/
|
||||
export type RESTGetAPIVoiceRegionsResult = APIVoiceRegion[];
|
||||
|
||||
/**
|
||||
* https://discord.com/developers/docs/resources/voice#get-current-user-voice-state
|
||||
*/
|
||||
export type RESTGetAPICurrentUserVoiceState = RESTGetAPIUserVoiceState;
|
||||
|
||||
/**
|
||||
* https://discord.com/developers/docs/resources/voice#get-user-voice-state
|
||||
*/
|
||||
export type RESTGetAPIUserVoiceState = APIVoiceState;
|
||||
|
||||
/**
|
||||
* @deprecated This was exported with the wrong name, use `RESTGetAPIVoiceRegionsResult` instead
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user