mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
Prettified Code!
This commit is contained in:
@@ -9,11 +9,7 @@ import { getMember } from "../members/get_member.ts";
|
||||
|
||||
/** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */
|
||||
export async function createGuild(options: CreateGuild) {
|
||||
const result = await rest.runMethod<Guild>(
|
||||
"post",
|
||||
endpoints.GUILDS,
|
||||
options,
|
||||
);
|
||||
const result = await rest.runMethod<Guild>("post", endpoints.GUILDS, options);
|
||||
|
||||
const guild = await structures.createDiscordenoGuild(result, 0);
|
||||
// MANUALLY CACHE THE GUILD
|
||||
|
||||
@@ -5,6 +5,6 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function deleteGuild(guildId: bigint) {
|
||||
return await rest.runMethod<undefined>(
|
||||
"delete",
|
||||
endpoints.GUILDS_BASE(guildId),
|
||||
endpoints.GUILDS_BASE(guildId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export async function editGuild(guildId: bigint, options: ModifyGuild) {
|
||||
const result = await rest.runMethod<Guild>(
|
||||
"patch",
|
||||
endpoints.GUILDS_BASE(guildId),
|
||||
options,
|
||||
options
|
||||
);
|
||||
|
||||
const cached = await cacheHandlers.get("guilds", guildId);
|
||||
@@ -35,8 +35,7 @@ export async function editGuild(guildId: bigint, options: ModifyGuild) {
|
||||
result,
|
||||
cached?.shardId ||
|
||||
Number(
|
||||
(BigInt(result.id) >> 22n % BigInt(ws.botGatewayData.shards))
|
||||
.toString(),
|
||||
),
|
||||
(BigInt(result.id) >> 22n % BigInt(ws.botGatewayData.shards)).toString()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ import { snakelize } from "../../util/utils.ts";
|
||||
|
||||
export async function editWelcomeScreen(
|
||||
guildId: bigint,
|
||||
options: ModifyGuildWelcomeScreen,
|
||||
options: ModifyGuildWelcomeScreen
|
||||
) {
|
||||
return await rest.runMethod<WelcomeScreen>(
|
||||
"patch",
|
||||
endpoints.GUILD_WELCOME_SCREEN(guildId),
|
||||
snakelize(options),
|
||||
snakelize(options)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
export async function editWidget(
|
||||
guildId: bigint,
|
||||
enabled: boolean,
|
||||
channelId?: string | null,
|
||||
channelId?: string | null
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
@@ -17,6 +17,6 @@ export async function editWidget(
|
||||
{
|
||||
enabled,
|
||||
channel_id: channelId,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import { snakelize } from "../../util/utils.ts";
|
||||
|
||||
/** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */
|
||||
export async function getAuditLogs(
|
||||
guildId: bigint,
|
||||
options: GetGuildAuditLog,
|
||||
) {
|
||||
export async function getAuditLogs(guildId: bigint, options: GetGuildAuditLog) {
|
||||
await requireBotGuildPermissions(guildId, ["VIEW_AUDIT_LOG"]);
|
||||
|
||||
return await rest.runMethod<AuditLog>(
|
||||
@@ -17,9 +14,10 @@ export async function getAuditLogs(
|
||||
endpoints.GUILD_AUDIT_LOGS(guildId),
|
||||
snakelize({
|
||||
...options,
|
||||
limit: options.limit && options.limit >= 1 && options.limit <= 100
|
||||
? options.limit
|
||||
: 50,
|
||||
}),
|
||||
limit:
|
||||
options.limit && options.limit >= 1 && options.limit <= 100
|
||||
? options.limit
|
||||
: 50,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ export async function getBan(guildId: bigint, memberId: bigint) {
|
||||
|
||||
return await rest.runMethod<Ban>(
|
||||
"get",
|
||||
endpoints.GUILD_BAN(guildId, memberId),
|
||||
endpoints.GUILD_BAN(guildId, memberId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ export async function getBans(guildId: bigint) {
|
||||
|
||||
const results = await rest.runMethod<Ban[]>(
|
||||
"get",
|
||||
endpoints.GUILD_BANS(guildId),
|
||||
endpoints.GUILD_BANS(guildId)
|
||||
);
|
||||
|
||||
return new Collection<bigint, Ban>(
|
||||
results.map((res) => [snowflakeToBigint(res.user.id), res]),
|
||||
results.map((res) => [snowflakeToBigint(res.user.id), res])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,19 +17,19 @@ export async function getGuild(
|
||||
options: { counts?: boolean; addToCache?: boolean } = {
|
||||
counts: true,
|
||||
addToCache: true,
|
||||
},
|
||||
}
|
||||
) {
|
||||
const result = await rest.runMethod<Guild>(
|
||||
"get",
|
||||
endpoints.GUILDS_BASE(guildId),
|
||||
{
|
||||
with_counts: options.counts,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const guild = await structures.createDiscordenoGuild(
|
||||
result,
|
||||
Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards)),
|
||||
Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards))
|
||||
);
|
||||
|
||||
if (options.addToCache) {
|
||||
|
||||
@@ -6,6 +6,6 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function getGuildPreview(guildId: bigint) {
|
||||
return await rest.runMethod<GuildPreview>(
|
||||
"get",
|
||||
endpoints.GUILD_PREVIEW(guildId),
|
||||
endpoints.GUILD_PREVIEW(guildId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { snakelize } from "../../util/utils.ts";
|
||||
/** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */
|
||||
export async function getPruneCount(
|
||||
guildId: bigint,
|
||||
options?: GetGuildPruneCountQuery,
|
||||
options?: GetGuildPruneCountQuery
|
||||
) {
|
||||
if (options?.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
|
||||
if (options?.days && options.days > 30) {
|
||||
@@ -20,7 +20,7 @@ export async function getPruneCount(
|
||||
const result = await rest.runMethod(
|
||||
"get",
|
||||
endpoints.GUILD_PRUNE(guildId),
|
||||
snakelize(options ?? {}),
|
||||
snakelize(options ?? {})
|
||||
);
|
||||
|
||||
return result.pruned as number;
|
||||
|
||||
@@ -5,11 +5,9 @@ import { endpoints } from "../../util/constants.ts";
|
||||
/** Returns the code and uses of the vanity url for this server if it is enabled else `code` will be null. Requires the `MANAGE_GUILD` permission. */
|
||||
export async function getVanityURL(guildId: bigint) {
|
||||
return await rest.runMethod<
|
||||
(Partial<InviteMetadata> & Pick<InviteMetadata, "uses" | "code">) | {
|
||||
code: null;
|
||||
}
|
||||
>(
|
||||
"get",
|
||||
endpoints.GUILD_VANITY_URL(guildId),
|
||||
);
|
||||
| (Partial<InviteMetadata> & Pick<InviteMetadata, "uses" | "code">)
|
||||
| {
|
||||
code: null;
|
||||
}
|
||||
>("get", endpoints.GUILD_VANITY_URL(guildId));
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function getVoiceRegions(guildId: bigint) {
|
||||
const result = await rest.runMethod<VoiceRegion[]>(
|
||||
"get",
|
||||
endpoints.GUILD_REGIONS(guildId),
|
||||
endpoints.GUILD_REGIONS(guildId)
|
||||
);
|
||||
|
||||
return new Collection<string, VoiceRegion>(
|
||||
result.map((region) => [region.id, region]),
|
||||
result.map((region) => [region.id, region])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function getWelcomeScreen(guildId: bigint) {
|
||||
return await rest.runMethod<WelcomeScreen>(
|
||||
"get",
|
||||
endpoints.GUILD_WELCOME_SCREEN(guildId),
|
||||
endpoints.GUILD_WELCOME_SCREEN(guildId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,6 @@ export async function getWidget(guildId: bigint, options?: { force: boolean }) {
|
||||
|
||||
return await rest.runMethod<GuildWidgetDetails>(
|
||||
"get",
|
||||
`${endpoints.GUILD_WIDGET(guildId)}.json`,
|
||||
`${endpoints.GUILD_WIDGET(guildId)}.json`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
/** Returns the widget image URL for the guild. */
|
||||
export async function getWidgetImageURL(
|
||||
guildId: bigint,
|
||||
options?: GetGuildWidgetImageQuery & { force?: boolean },
|
||||
options?: GetGuildWidgetImageQuery & { force?: boolean }
|
||||
) {
|
||||
if (!options?.force) {
|
||||
const guild = await cacheHandlers.get("guilds", guildId);
|
||||
@@ -14,6 +14,7 @@ export async function getWidgetImageURL(
|
||||
if (!guild.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
|
||||
}
|
||||
|
||||
return `${endpoints.GUILD_WIDGET(guildId)}.png?style=${options?.style ??
|
||||
"shield"}`;
|
||||
return `${endpoints.GUILD_WIDGET(guildId)}.png?style=${
|
||||
options?.style ?? "shield"
|
||||
}`;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ export async function getWidgetSettings(guildId: bigint) {
|
||||
|
||||
return await rest.runMethod<GuildWidget>(
|
||||
"get",
|
||||
endpoints.GUILD_WIDGET(guildId),
|
||||
endpoints.GUILD_WIDGET(guildId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,19 +12,18 @@ export function guildBannerURL(
|
||||
size?: DiscordImageSize;
|
||||
format?: DiscordImageFormat;
|
||||
animated?: boolean;
|
||||
},
|
||||
}
|
||||
) {
|
||||
return options.banner
|
||||
? formatImageURL(
|
||||
endpoints.GUILD_BANNER(
|
||||
id,
|
||||
typeof options.banner === "string" ? options.banner : iconBigintToHash(
|
||||
options.banner,
|
||||
options.animated ?? true,
|
||||
endpoints.GUILD_BANNER(
|
||||
id,
|
||||
typeof options.banner === "string"
|
||||
? options.banner
|
||||
: iconBigintToHash(options.banner, options.animated ?? true)
|
||||
),
|
||||
),
|
||||
options.size || 128,
|
||||
options.format,
|
||||
)
|
||||
options.size || 128,
|
||||
options.format
|
||||
)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
@@ -12,19 +12,18 @@ export function guildIconURL(
|
||||
size?: DiscordImageSize;
|
||||
format?: DiscordImageFormat;
|
||||
animated?: boolean;
|
||||
},
|
||||
}
|
||||
) {
|
||||
return options.icon
|
||||
? formatImageURL(
|
||||
endpoints.GUILD_ICON(
|
||||
id,
|
||||
typeof options.icon === "string" ? options.icon : iconBigintToHash(
|
||||
options.icon,
|
||||
options.animated ?? true,
|
||||
endpoints.GUILD_ICON(
|
||||
id,
|
||||
typeof options.icon === "string"
|
||||
? options.icon
|
||||
: iconBigintToHash(options.icon, options.animated ?? true)
|
||||
),
|
||||
),
|
||||
options.size || 128,
|
||||
options.format,
|
||||
)
|
||||
options.size || 128,
|
||||
options.format
|
||||
)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
@@ -12,19 +12,18 @@ export function guildSplashURL(
|
||||
size?: DiscordImageSize;
|
||||
format?: DiscordImageFormat;
|
||||
animated?: boolean;
|
||||
},
|
||||
}
|
||||
) {
|
||||
return options.splash
|
||||
? formatImageURL(
|
||||
endpoints.GUILD_SPLASH(
|
||||
id,
|
||||
typeof options.splash === "string" ? options.splash : iconBigintToHash(
|
||||
options.splash,
|
||||
options.animated ?? true,
|
||||
endpoints.GUILD_SPLASH(
|
||||
id,
|
||||
typeof options.splash === "string"
|
||||
? options.splash
|
||||
: iconBigintToHash(options.splash, options.animated ?? true)
|
||||
),
|
||||
),
|
||||
options.size || 128,
|
||||
options.format,
|
||||
)
|
||||
options.size || 128,
|
||||
options.format
|
||||
)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function leaveGuild(guildId: bigint) {
|
||||
return await rest.runMethod<undefined>(
|
||||
"delete",
|
||||
endpoints.GUILD_LEAVE(guildId),
|
||||
endpoints.GUILD_LEAVE(guildId)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user