From 7ac20b2a2740b389db65557deb5ff356768c7a53 Mon Sep 17 00:00:00 2001 From: socram03 Date: Sun, 17 Jul 2022 15:00:43 -0400 Subject: [PATCH] feat: editProfile() --- packages/biscuit/Routes.ts | 3 ++- packages/biscuit/Session.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/biscuit/Routes.ts b/packages/biscuit/Routes.ts index 20f5f28..9d74dee 100644 --- a/packages/biscuit/Routes.ts +++ b/packages/biscuit/Routes.ts @@ -3,7 +3,8 @@ import type { Snowflake } from "./Snowflake.ts"; // cdn endpoints export * from "./Cdn.ts"; -export function USER(userId: Snowflake): string { +export function USER(userId?: Snowflake): string { + if (!userId) return "/users/@me"; return `/users/${userId}`; } diff --git a/packages/biscuit/Session.ts b/packages/biscuit/Session.ts index 881e00e..c92674e 100644 --- a/packages/biscuit/Session.ts +++ b/packages/biscuit/Session.ts @@ -28,6 +28,7 @@ import { } from "../discordeno/mod.ts"; import User from "./structures/User.ts"; +import { urlToBase64 } from "./util/urlToBase64.ts"; import * as Routes from "./Routes.ts"; import * as Actions from "./Actions.ts"; @@ -200,6 +201,15 @@ export class Session extends EventEmitter { return super.emit(event, ...params); } + async editProfile(nick?: string, avatarURL?: string | null ): Promise { + const avatar = avatarURL ? await urlToBase64(avatarURL) : avatarURL; + const user = await this.rest.runMethod(this.rest, 'PATCH', Routes.USER(), { + username: nick, + avatar: avatar + }); + return new User(this, user); + } + /** * Edit bot's status * tip: execute this on the ready event if possible