change: prettier code

This commit is contained in:
TriForMine
2021-10-21 17:38:57 +00:00
committed by GitHub Action
parent 20616e8a36
commit 3a08aa15f4
23 changed files with 76 additions and 63 deletions
+3 -3
View File
@@ -4,7 +4,7 @@ import type { Bot } from "../../bot.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. */ /** 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(bot: Bot, options: CreateGuild) { export async function createGuild(bot: Bot, options: CreateGuild) {
const result = await bot.rest.runMethod<Guild>(bot.rest,"post", bot.constants.endpoints.GUILDS, { const result = await bot.rest.runMethod<Guild>(bot.rest, "post", bot.constants.endpoints.GUILDS, {
name: options.name, name: options.name,
afk_channel_id: options.afkChannelId, afk_channel_id: options.afkChannelId,
afk_timeout: options.afkTimeout, afk_timeout: options.afkTimeout,
@@ -15,10 +15,10 @@ export async function createGuild(bot: Bot, options: CreateGuild) {
roles: options.roles, roles: options.roles,
system_channel_flags: options.systemChannelFlags, system_channel_flags: options.systemChannelFlags,
system_channel_id: options.systemChannelId, system_channel_id: options.systemChannelId,
verification_level: options.verificationLevel verification_level: options.verificationLevel,
}); });
const guild = bot.transformers.guild(bot, {guild: result, shardId: 0}); const guild = bot.transformers.guild(bot, { guild: result, shardId: 0 });
// MANUALLY CACHE THE GUILD // MANUALLY CACHE THE GUILD
await bot.cache.guilds.set(guild.id, guild); await bot.cache.guilds.set(guild.id, guild);
// MANUALLY CACHE THE BOT // MANUALLY CACHE THE BOT
+1 -1
View File
@@ -2,5 +2,5 @@ import type { Bot } from "../../bot.ts";
/** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */ /** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */
export async function deleteGuild(bot: Bot, guildId: bigint) { export async function deleteGuild(bot: Bot, guildId: bigint) {
return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.GUILDS_BASE(guildId)); return await bot.rest.runMethod<undefined>(bot.rest, "delete", bot.constants.endpoints.GUILDS_BASE(guildId));
} }
+5 -9
View File
@@ -18,16 +18,12 @@ export async function editGuild(bot: Bot, guildId: bigint, options: ModifyGuild)
options.splash = await bot.utils.urlToBase64(options.splash); options.splash = await bot.utils.urlToBase64(options.splash);
} }
const result = await bot.rest.runMethod<Guild>(bot.rest,"patch", bot.constants.endpoints.GUILDS_BASE(guildId), { const result = await bot.rest.runMethod<Guild>(bot.rest, "patch", bot.constants.endpoints.GUILDS_BASE(guildId), {});
});
const cached = await bot.cache.guilds.get(guildId); const cached = await bot.cache.guilds.get(guildId);
return bot.transformers.guild( return bot.transformers.guild(bot, {
bot,
{
guild: result, guild: result,
shardId: cached?.shardId || Number((BigInt(result.id) >> 22n % BigInt(bot.gateway.botGatewayData.shards)).toString()) shardId:
} cached?.shardId || Number((BigInt(result.id) >> 22n % BigInt(bot.gateway.botGatewayData.shards)).toString()),
); });
} }
+3 -3
View File
@@ -10,9 +10,9 @@ export async function editWelcomeScreen(bot: Bot, guildId: bigint, options: Modi
channel_id: welcomeScreen.channelId, channel_id: welcomeScreen.channelId,
description: welcomeScreen.description, description: welcomeScreen.description,
emoji_id: welcomeScreen.emojiId, emoji_id: welcomeScreen.emojiId,
emoji_name: welcomeScreen.emojiName emoji_name: welcomeScreen.emojiName,
} };
}), }),
description: options.description description: options.description,
}); });
} }
+1 -1
View File
@@ -5,7 +5,7 @@ import type { Bot } from "../../bot.ts";
export async function editWidget(bot: Bot, guildId: bigint, enabled: boolean, channelId?: string | null) { export async function editWidget(bot: Bot, guildId: bigint, enabled: boolean, channelId?: string | null) {
await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]); await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
return await bot.rest.runMethod<GuildWidget>(bot.rest,"patch", bot.constants.endpoints.GUILD_WIDGET(guildId), { return await bot.rest.runMethod<GuildWidget>(bot.rest, "patch", bot.constants.endpoints.GUILD_WIDGET(guildId), {
enabled, enabled,
channel_id: channelId, channel_id: channelId,
}); });
+2 -7
View File
@@ -6,15 +6,10 @@ import type { Bot } from "../../bot.ts";
export async function getAuditLogs(bot: Bot, guildId: bigint, options?: GetGuildAuditLog) { export async function getAuditLogs(bot: Bot, guildId: bigint, options?: GetGuildAuditLog) {
await bot.utils.requireBotGuildPermissions(bot, guildId, ["VIEW_AUDIT_LOG"]); await bot.utils.requireBotGuildPermissions(bot, guildId, ["VIEW_AUDIT_LOG"]);
return await bot.rest.runMethod<AuditLog>( return await bot.rest.runMethod<AuditLog>(bot.rest, "get", bot.constants.endpoints.GUILD_AUDIT_LOGS(guildId), {
bot.rest,
"get",
bot.constants.endpoints.GUILD_AUDIT_LOGS(guildId),
{
user_id: options.userId, user_id: options.userId,
action_type: options.actionType, action_type: options.actionType,
before: options.before, before: options.before,
limit: options?.limit && options.limit >= 1 && options.limit <= 100 ? options.limit : 50, limit: options?.limit && options.limit >= 1 && options.limit <= 100 ? options.limit : 50,
} });
);
} }
@@ -3,5 +3,5 @@ import type { Bot } from "../../bot.ts";
/** Returns an array of voice regions that can be used when creating servers. */ /** Returns an array of voice regions that can be used when creating servers. */
export async function getAvailableVoiceRegions(bot: Bot) { export async function getAvailableVoiceRegions(bot: Bot) {
return await bot.rest.runMethod<VoiceRegion>(bot.rest,"get", bot.constants.endpoints.VOICE_REGIONS); return await bot.rest.runMethod<VoiceRegion>(bot.rest, "get", bot.constants.endpoints.VOICE_REGIONS);
} }
+1 -1
View File
@@ -5,5 +5,5 @@ import type { Bot } from "../../bot.ts";
export async function getBan(bot: Bot, guildId: bigint, memberId: bigint) { export async function getBan(bot: Bot, guildId: bigint, memberId: bigint) {
await bot.utils.requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]); await bot.utils.requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]);
return await bot.rest.runMethod<Ban>(bot.rest,"get", bot.constants.endpoints.GUILD_BAN(guildId, memberId)); return await bot.rest.runMethod<Ban>(bot.rest, "get", bot.constants.endpoints.GUILD_BAN(guildId, memberId));
} }
+1 -1
View File
@@ -6,7 +6,7 @@ import { Collection } from "../../util/collection.ts";
export async function getBans(bot: Bot, guildId: bigint) { export async function getBans(bot: Bot, guildId: bigint) {
await bot.utils.requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]); await bot.utils.requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]);
const results = await bot.rest.runMethod<Ban[]>(bot.rest,"get", bot.constants.endpoints.GUILD_BANS(guildId)); const results = await bot.rest.runMethod<Ban[]>(bot.rest, "get", bot.constants.endpoints.GUILD_BANS(guildId));
return new Collection<bigint, Ban>(results.map((res) => [bot.transformers.snowflake(res.user.id), res])); return new Collection<bigint, Ban>(results.map((res) => [bot.transformers.snowflake(res.user.id), res]));
} }
+4 -7
View File
@@ -16,17 +16,14 @@ export async function getGuild(
addToCache: true, addToCache: true,
} }
) { ) {
const result = await bot.rest.runMethod<Guild>(bot.rest,"get", bot.constants.endpoints.GUILDS_BASE(guildId), { const result = await bot.rest.runMethod<Guild>(bot.rest, "get", bot.constants.endpoints.GUILDS_BASE(guildId), {
with_counts: options.counts, with_counts: options.counts,
}); });
const guild = await bot.transformers.guild( const guild = await bot.transformers.guild(bot, {
bot,
{
guild: result, guild: result,
shardId: Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards)) shardId: Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards)),
} });
);
if (options.addToCache) { if (options.addToCache) {
await bot.cache.guilds.set(guild.id, guild); await bot.cache.guilds.set(guild.id, guild);
+1 -1
View File
@@ -3,5 +3,5 @@ import type { Bot } from "../../bot.ts";
/** Returns the guild preview object for the given id. If the bot is not in the guild, then the guild must be Discoverable. */ /** Returns the guild preview object for the given id. If the bot is not in the guild, then the guild must be Discoverable. */
export async function getGuildPreview(bot: Bot, guildId: bigint) { export async function getGuildPreview(bot: Bot, guildId: bigint) {
return await bot.rest.runMethod<GuildPreview>(bot.rest,"get", bot.constants.endpoints.GUILD_PREVIEW(guildId)); return await bot.rest.runMethod<GuildPreview>(bot.rest, "get", bot.constants.endpoints.GUILD_PREVIEW(guildId));
} }
+10 -3
View File
@@ -10,10 +10,17 @@ export async function getPruneCount(bot: Bot, guildId: bigint, options?: GetGuil
await bot.utils.requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]); await bot.utils.requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
const result = await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.GUILD_PRUNE(guildId), options ? { const result = await bot.rest.runMethod(
bot.rest,
"get",
bot.constants.endpoints.GUILD_PRUNE(guildId),
options
? {
days: options.days, days: options.days,
include_roles: options.includeRoles include_roles: options.includeRoles,
} : {}); }
: {}
);
return result.pruned as number; return result.pruned as number;
} }
+1 -1
View File
@@ -8,5 +8,5 @@ export async function getVanityURL(bot: Bot, guildId: bigint) {
| { | {
code: null; code: null;
} }
>(bot.rest,"get", bot.constants.endpoints.GUILD_VANITY_URL(guildId)); >(bot.rest, "get", bot.constants.endpoints.GUILD_VANITY_URL(guildId));
} }
+5 -1
View File
@@ -4,7 +4,11 @@ import type { Bot } from "../../bot.ts";
/** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */ /** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */
export async function getVoiceRegions(boot: Bot, guildId: bigint) { export async function getVoiceRegions(boot: Bot, guildId: bigint) {
const result = await bot.rest.runMethod<VoiceRegion[]>(bot.rest,"get", bot.constants.endpoints.GUILD_REGIONS(guildId)); const result = await bot.rest.runMethod<VoiceRegion[]>(
bot.rest,
"get",
bot.constants.endpoints.GUILD_REGIONS(guildId)
);
return new Collection<string, VoiceRegion>(result.map((region) => [region.id, region])); return new Collection<string, VoiceRegion>(result.map((region) => [region.id, region]));
} }
+5 -1
View File
@@ -2,5 +2,9 @@ import type { WelcomeScreen } from "../../types/guilds/welcome_screen.ts";
import type { Bot } from "../../bot.ts"; import type { Bot } from "../../bot.ts";
export async function getWelcomeScreen(bot: Bot, guildId: bigint) { export async function getWelcomeScreen(bot: Bot, guildId: bigint) {
return await bot.rest.runMethod<WelcomeScreen>(bot.rset,"get", bot.constants.endpoints.GUILD_WELCOME_SCREEN(guildId)); return await bot.rest.runMethod<WelcomeScreen>(
bot.rset,
"get",
bot.constants.endpoints.GUILD_WELCOME_SCREEN(guildId)
);
} }
+5 -1
View File
@@ -9,5 +9,9 @@ export async function getWidget(bot: Bot, guildId: bigint, options?: { force: bo
if (!guild?.widgetEnabled) throw new Error(bot.constants.Errors.GUILD_WIDGET_NOT_ENABLED); if (!guild?.widgetEnabled) throw new Error(bot.constants.Errors.GUILD_WIDGET_NOT_ENABLED);
} }
return await bot.rest.runMethod<GuildWidgetDetails>(bot.rest,"get", `${bot.constants.endpoints.GUILD_WIDGET(guildId)}.json`); return await bot.rest.runMethod<GuildWidgetDetails>(
bot.rest,
"get",
`${bot.constants.endpoints.GUILD_WIDGET(guildId)}.json`
);
} }
+5 -1
View File
@@ -2,7 +2,11 @@ import type { Bot } from "../../bot.ts";
import type { GetGuildWidgetImageQuery } from "../../types/guilds/get_guild_widget_image.ts"; import type { GetGuildWidgetImageQuery } from "../../types/guilds/get_guild_widget_image.ts";
/** Returns the widget image URL for the guild. */ /** Returns the widget image URL for the guild. */
export async function getWidgetImageURL(bot: Bot, guildId: bigint, options?: GetGuildWidgetImageQuery & { force?: boolean }) { export async function getWidgetImageURL(
bot: Bot,
guildId: bigint,
options?: GetGuildWidgetImageQuery & { force?: boolean }
) {
if (!options?.force) { if (!options?.force) {
const guild = await bot.cache.guilds.get(guildId); const guild = await bot.cache.guilds.get(guildId);
if (!guild) throw new Error(bot.constants.Errors.GUILD_NOT_FOUND); if (!guild) throw new Error(bot.constants.Errors.GUILD_NOT_FOUND);
+1 -1
View File
@@ -5,5 +5,5 @@ import type { Bot } from "../../bot.ts";
export async function getWidgetSettings(bot: Bot, guildId: bigint) { export async function getWidgetSettings(bot: Bot, guildId: bigint) {
await bot.utils.requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); await bot.utils.requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
return await bot.rest.runMethod<GuildWidget>(bot.rest,"get", bot.constants.endpoints.GUILD_WIDGET(guildId)); return await bot.rest.runMethod<GuildWidget>(bot.rest, "get", bot.constants.endpoints.GUILD_WIDGET(guildId));
} }
+3 -1
View File
@@ -17,7 +17,9 @@ export function guildIconURL(
? bot.utils.formatImageURL( ? bot.utils.formatImageURL(
bot.constants.endpoints.GUILD_ICON( bot.constants.endpoints.GUILD_ICON(
id, id,
typeof options.icon === "string" ? options.icon : bot.utils.iconBigintToHash(options.icon, options.animated ?? true) typeof options.icon === "string"
? options.icon
: bot.utils.iconBigintToHash(options.icon, options.animated ?? true)
), ),
options.size || 128, options.size || 128,
options.format options.format
+1 -1
View File
@@ -2,5 +2,5 @@ import type { Bot } from "../../bot.ts";
/** Leave a guild */ /** Leave a guild */
export async function leaveGuild(bot: Bot, guildId: bigint) { export async function leaveGuild(bot: Bot, guildId: bigint) {
return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.GUILD_LEAVE(guildId)); return await bot.rest.runMethod<undefined>(bot.rest, "delete", bot.constants.endpoints.GUILD_LEAVE(guildId));
} }
+1 -1
View File
@@ -18,7 +18,7 @@ export async function sendDirectMessage(bot: Bot, memberId: bigint, content: str
recipient_id: memberId, recipient_id: memberId,
} }
); );
const discordenoChannel = await bot.transformers.channel(bot, {channel: dmChannelData}); const discordenoChannel = await bot.transformers.channel(bot, { channel: dmChannelData });
// Recreate the channel and add it under the users id // Recreate the channel and add it under the users id
await bot.cache.channels.set(memberId, discordenoChannel); await bot.cache.channels.set(memberId, discordenoChannel);
dmChannel = discordenoChannel; dmChannel = discordenoChannel;