This commit is contained in:
Nicolás Serna 2022-07-31 23:20:12 -03:00
commit fd09fee3b6
3 changed files with 22 additions and 10 deletions

View File

@ -9,7 +9,7 @@ import type { PermissionsOverwrites } from '../utils/util';
import { urlToBase64 } from '../utils/url-to-base-64'; import { urlToBase64 } from '../utils/url-to-base-64';
/** Classes and routes */ /** Classes and routes */
import type { import {
DiscordChannel, DiscordChannel,
DiscordInvite, DiscordInvite,
DiscordInviteMetadata, DiscordInviteMetadata,
@ -22,7 +22,8 @@ import type {
VideoQualityModes, VideoQualityModes,
GetReactions, GetReactions,
GetMessagesOptions, GetMessagesOptions,
ListArchivedThreads } from '@biscuitland/api-types'; ListArchivedThreads,
USER_DM} from '@biscuitland/api-types';
import { import {
CHANNEL, CHANNEL,
CHANNEL_PINS, CHANNEL_PINS,
@ -102,8 +103,8 @@ export abstract class BaseChannel implements Model {
return this.type === ChannelTypes.GuildStageVoice; return this.type === ChannelTypes.GuildStageVoice;
} }
async fetch(): Promise<Channel> { async fetch(channelId?: Snowflake): Promise<Channel> {
const channel = await this.session.rest.get<DiscordChannel>(CHANNEL(this.id)); const channel = await this.session.rest.get<DiscordChannel>(CHANNEL(channelId ?? this.id));
return ChannelFactory.from(this.session, channel); return ChannelFactory.from(this.session, channel);
} }
@ -684,6 +685,12 @@ export class DMChannel extends BaseChannel implements Model {
return new DMChannel(this.session, channel); return new DMChannel(this.session, channel);
} }
async open(userId: Snowflake): Promise<DMChannel> {
const channel = await this.session.rest.post<DiscordChannel>(USER_DM(), { recipient_id: userId});
return new DMChannel(this.session, channel);
}
} }
export interface DMChannel extends Omit<TextChannel, 'type'>, Omit<BaseChannel, 'type'> {} export interface DMChannel extends Omit<TextChannel, 'type'>, Omit<BaseChannel, 'type'> {}

View File

@ -58,7 +58,7 @@ import {
CHANNEL, CHANNEL,
GUILD_CHANNELS, GUILD_CHANNELS,
} from '@biscuitland/api-types'; } from '@biscuitland/api-types';
import { ChannelFactory, GuildChannel, ReturnThreadsArchive, ThreadChannel, Channel } from './channels'; import { ChannelFactory, GuildChannel, ReturnThreadsArchive, ThreadChannel, ChannelInGuild } from './channels';
import { Member, ThreadMember } from './members'; import { Member, ThreadMember } from './members';
import { Role } from './role'; import { Role } from './role';
import { GuildEmoji } from './emojis'; import { GuildEmoji } from './emojis';
@ -1216,16 +1216,16 @@ export class Guild extends BaseGuild implements Model {
return new GuildPreview(this.session, preview); return new GuildPreview(this.session, preview);
} }
async fetchChannel(channelID: string): Promise<Channel> { async fetchChannel(channelId: string): Promise<ChannelInGuild> {
const channel = await this.session.rest.get<DiscordChannel>(CHANNEL(channelID)); const channel = await this.session.rest.get<DiscordChannel>(CHANNEL(channelId));
return ChannelFactory.from(this.session, channel); return ChannelFactory.fromGuildChannel(this.session, channel);
} }
async fetchChannels(): Promise<Channel[]> { async fetchChannels(): Promise<ChannelInGuild[]> {
const channels = await this.session.rest.get<DiscordChannel[]>(GUILD_CHANNELS(this.id)); const channels = await this.session.rest.get<DiscordChannel[]>(GUILD_CHANNELS(this.id));
return channels.map(channel => ChannelFactory.from(this.session, channel)); return channels.map(channel => ChannelFactory.fromGuildChannel(this.session, channel));
} }
/** fetches a member */ /** fetches a member */

View File

@ -5,6 +5,7 @@ import type { DiscordUser, PremiumTypes, UserFlags } from '@biscuitland/api-type
import type { ImageFormat, ImageSize } from '../utils/util'; import type { ImageFormat, ImageSize } from '../utils/util';
import { USER, USER_AVATAR, USER_DEFAULT_AVATAR } from '@biscuitland/api-types'; import { USER, USER_AVATAR, USER_DEFAULT_AVATAR } from '@biscuitland/api-types';
import { Util } from '../utils/util'; import { Util } from '../utils/util';
import { DMChannel } from './channels';
export type AvatarOptions = { export type AvatarOptions = {
format?: ImageFormat; format?: ImageFormat;
@ -113,6 +114,10 @@ export class User implements Model {
return Util.formatImageURL(url, options.size ?? 128, options.format); return Util.formatImageURL(url, options.size ?? 128, options.format);
} }
openDM(): Promise<DMChannel> {
return DMChannel.prototype.open.call({ session: this.session }, this.id);
}
toString(): string { toString(): string {
return `<@${this.id}>`; return `<@${this.id}>`;
} }