swc/bundler/tests/.cache/deno/15222a4c9ba619badd5892d3021ea3dde77fe193.ts
강동윤 d60c3242af
fix(swc): Fix bugs (#1739)
swc_bundler:
 - Fix cycle detection for complex circular imports. (denoland/deno#10752)

swc_ecma_transforms_typescript:
 - Allow using large values for an enum variant.
2021-05-25 14:30:17 +09:00

39 lines
1.3 KiB
TypeScript

// Loaded from https://deno.land/x/discordeno@11.0.0-rc.2/src/helpers/misc/edit_bot_profile.ts
import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/discordeno/errors.ts";
import type { User } from "../../types/users/user.ts";
import { endpoints } from "../../util/constants.ts";
import { urlToBase64 } from "../../util/utils.ts";
/** Modifies the bot's username or avatar.
* NOTE: username: if changed may cause the bot's discriminator to be randomized.
*/
export async function editBotProfile(username?: string, botAvatarURL?: string) {
// Nothing was edited
if (!username && !botAvatarURL) return;
// Check username requirements if username was provided
if (username) {
if (username.length > 32) {
throw new Error(Errors.USERNAME_MAX_LENGTH);
}
if (username.length < 2) {
throw new Error(Errors.USERNAME_MIN_LENGTH);
}
if (["@", "#", ":", "```"].some((char) => username.includes(char))) {
throw new Error(Errors.USERNAME_INVALID_CHARACTER);
}
if (["discordtag", "everyone", "here"].includes(username)) {
throw new Error(Errors.USERNAME_INVALID_USERNAME);
}
}
const avatar = botAvatarURL ? await urlToBase64(botAvatarURL) : undefined;
return await rest.runMethod<User>("patch", endpoints.USER_BOT, {
username: username?.trim(),
avatar,
});
}