mirror of
https://github.com/swc-project/swc.git
synced 2024-12-21 12:41:54 +03:00
d60c3242af
swc_bundler: - Fix cycle detection for complex circular imports. (denoland/deno#10752) swc_ecma_transforms_typescript: - Allow using large values for an enum variant.
39 lines
1.3 KiB
TypeScript
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,
|
|
});
|
|
}
|