change: prettier code

This commit is contained in:
Skillz4Killz
2021-10-23 15:50:59 +00:00
committed by GitHub Action
parent 72ffbdc4db
commit 1c1c93ed7f
29 changed files with 174 additions and 118 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
import {Bot} from "../../bot.ts";
import { Bot } from "../../bot.ts";
/** Gets an array of all the channels ids that are the children of this category.
* ⚠️ This does not work for custom cache users!
+32 -30
View File
@@ -5,38 +5,40 @@ import type { Bot } from "../../bot.ts";
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
export async function createChannel(bot: Bot, guildId: bigint, options?: CreateGuildChannel, reason?: string) {
if (options?.permissionOverwrites) {
await bot.utils.requireOverwritePermissions(bot, guildId, options.permissionOverwrites);
}
if (options?.permissionOverwrites) {
await bot.utils.requireOverwritePermissions(bot, guildId, options.permissionOverwrites);
}
// BITRATES ARE IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000
if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000;
// BITRATES ARE IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000
if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000;
const result = await bot.rest.runMethod<Channel>(
bot.rest,
"post",
bot.constants.endpoints.GUILD_CHANNELS(guildId),
options ? {
name: options.name,
topic: options.topic,
bitrate: options.bitrate,
userLimit: options.userLimit,
rateLimitPerUser: options.rateLimitPerUser,
position: options.position,
parentId: options.parentId,
nsfw: options.nsfw,
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
...perm,
allow: bot.utils.calculateBits(perm.allow),
deny: bot.utils.calculateBits(perm.deny),
})),
type: options?.type || DiscordChannelTypes.GuildText,
reason,
} : {}
);
const result = await bot.rest.runMethod<Channel>(
bot.rest,
"post",
bot.constants.endpoints.GUILD_CHANNELS(guildId),
options
? {
name: options.name,
topic: options.topic,
bitrate: options.bitrate,
userLimit: options.userLimit,
rateLimitPerUser: options.rateLimitPerUser,
position: options.position,
parentId: options.parentId,
nsfw: options.nsfw,
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
...perm,
allow: bot.utils.calculateBits(perm.allow),
deny: bot.utils.calculateBits(perm.deny),
})),
type: options?.type || DiscordChannelTypes.GuildText,
reason,
}
: {}
);
const discordenoChannel = bot.transformers.channel(result);
await bot.cache.channels.set(discordenoChannel.id, discordenoChannel);
const discordenoChannel = bot.transformers.channel(result);
await bot.cache.channels.set(discordenoChannel.id, discordenoChannel);
return discordenoChannel;
return discordenoChannel;
}
+5 -10
View File
@@ -19,14 +19,9 @@ export async function createStageInstance(bot: Bot, channelId: bigint, topic: st
throw new Error(bot.constants.Errors.INVALID_TOPIC_LENGTH);
}
return await bot.rest.runMethod<StageInstance>(
bot.rest,
"post",
bot.constants.endpoints.STAGE_INSTANCES,
{
channel_id: channelId,
topic,
privacy_level: privacyLevel,
}
);
return await bot.rest.runMethod<StageInstance>(bot.rest, "post", bot.constants.endpoints.STAGE_INSTANCES, {
channel_id: channelId,
topic,
privacy_level: privacyLevel,
});
}
+3 -1
View File
@@ -19,5 +19,7 @@ export async function deleteChannel(bot: Bot, channelId: bigint, reason?: string
await bot.utils.requireBotGuildPermissions(bot, guild, ["MANAGE_CHANNELS"]);
}
return await bot.rest.runMethod<undefined>(bot.rest, "delete", bot.constants.endpoints.CHANNEL_BASE(channelId), { reason });
return await bot.rest.runMethod<undefined>(bot.rest, "delete", bot.constants.endpoints.CHANNEL_BASE(channelId), {
reason,
});
}
@@ -2,12 +2,16 @@ import type { Bot } from "../../bot.ts";
/** Delete the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
export async function deleteChannelOverwrite(
bot: Bot,
bot: Bot,
guildId: bigint,
channelId: bigint,
overwriteId: bigint
): Promise<undefined> {
await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]);
return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwriteId));
return await bot.rest.runMethod<undefined>(
bot.rest,
"delete",
bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwriteId)
);
}
+6 -4
View File
@@ -2,7 +2,7 @@ import type { DiscordenoChannel } from "../../structures/channel.ts";
import type { Channel } from "../../types/channels/channel.ts";
import type { ModifyChannel } from "../../types/channels/modify_channel.ts";
import type { Bot } from "../../bot.ts";
import {SnakeCasedPropertiesDeep} from "../../types/util.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
export async function editChannel(bot: Bot, channelId: bigint, options: ModifyChannel, reason?: string) {
@@ -41,7 +41,7 @@ export async function editChannel(bot: Bot, channelId: bigint, options: ModifyCh
}
const result = await bot.rest.runMethod<SnakeCasedPropertiesDeep<Channel>>(
bot.rest,
bot.rest,
"patch",
bot.constants.endpoints.CHANNEL_BASE(channelId),
{
@@ -103,13 +103,15 @@ function processEditChannelQueue(bot: Bot) {
if (!details) return;
await bot.helpers.editChannel(bot, details.channelId, details.options)
await bot.helpers
.editChannel(bot, details.channelId, details.options)
.then((result) => details.resolve(result))
.catch(details.reject);
const secondDetails = request.items.shift();
if (!secondDetails) return;
await bot.helpers.editChannel(bot, secondDetails.channelId, secondDetails.options)
await bot.helpers
.editChannel(bot, secondDetails.channelId, secondDetails.options)
.then((result) => secondDetails.resolve(result))
.catch(secondDetails.reject);
return;
+11 -6
View File
@@ -3,7 +3,7 @@ import type { Bot } from "../../bot.ts";
/** Edit the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
export async function editChannelOverwrite(
bot: Bot,
bot: Bot,
guildId: bigint,
channelId: bigint,
overwriteId: bigint,
@@ -11,9 +11,14 @@ export async function editChannelOverwrite(
): Promise<undefined> {
await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]);
return await bot.rest.runMethod<undefined>(bot.rest,"put", bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwriteId), {
allow: bot.utils.calculateBits(options.allow),
deny: bot.utils.calculateBits(options.deny),
type: options.type,
});
return await bot.rest.runMethod<undefined>(
bot.rest,
"put",
bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwriteId),
{
allow: bot.utils.calculateBits(options.allow),
deny: bot.utils.calculateBits(options.deny),
type: options.type,
}
);
}
+8 -3
View File
@@ -5,9 +5,14 @@ import type { Bot } from "../../bot.ts";
export async function followChannel(bot: Bot, sourceChannelId: bigint, targetChannelId: bigint) {
await bot.utils.requireBotChannelPermissions(bot, targetChannelId, ["MANAGE_WEBHOOKS"]);
const data = await bot.rest.runMethod<FollowedChannel>(bot.rest,"post", bot.constants.endpoints.CHANNEL_FOLLOW(sourceChannelId), {
webhook_channel_id: targetChannelId,
});
const data = await bot.rest.runMethod<FollowedChannel>(
bot.rest,
"post",
bot.constants.endpoints.CHANNEL_FOLLOW(sourceChannelId),
{
webhook_channel_id: targetChannelId,
}
);
return data.webhookId;
}
+5 -7
View File
@@ -6,14 +6,12 @@ import type { Channel } from "../../types/channels/channel.ts";
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
*/
export async function getChannel(bot: Bot, channelId: bigint, addToCache = true) {
const result = await bot.rest.runMethod<Channel>(bot.rest,"get", bot.constants.endpoints.CHANNEL_BASE(channelId));
const result = await bot.rest.runMethod<Channel>(bot.rest, "get", bot.constants.endpoints.CHANNEL_BASE(channelId));
const discordenoChannel = bot.transformers.channel(
{
channel: result,
guildId: result.guildId ? bot.transformers.snowflake(result.guildId) : undefined
}
);
const discordenoChannel = bot.transformers.channel({
channel: result,
guildId: result.guildId ? bot.transformers.snowflake(result.guildId) : undefined,
});
if (addToCache) {
await bot.cache.channels.set(discordenoChannel.id, discordenoChannel);
}
+5 -1
View File
@@ -6,7 +6,11 @@ import type { Bot } from "../../bot.ts";
export async function getChannelWebhooks(bot: Bot, channelId: bigint) {
await bot.utils.requireBotChannelPermissions(bot, channelId, ["MANAGE_WEBHOOKS"]);
const result = await bot.rest.runMethod<Webhook[]>(bot.rest,"get", bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId));
const result = await bot.rest.runMethod<Webhook[]>(
bot.rest,
"get",
bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId)
);
return new Collection(result.map((webhook) => [webhook.id, webhook]));
}
+2 -2
View File
@@ -7,13 +7,13 @@ import type { Bot } from "../../bot.ts";
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
*/
export async function getChannels(bot: Bot, guildId: bigint, addToCache = true) {
const result = await bot.rest.runMethod<Channel[]>(bot.rest,"get", bot.constants.endpoints.GUILD_CHANNELS(guildId));
const result = await bot.rest.runMethod<Channel[]>(bot.rest, "get", bot.constants.endpoints.GUILD_CHANNELS(guildId));
return new Collection(
(
await Promise.all(
result.map(async (res) => {
const discordenoChannel = await bot.transformers.channel({channel: res, guildId});
const discordenoChannel = await bot.transformers.channel({ channel: res, guildId });
if (addToCache) {
await bot.cache.channels.set(discordenoChannel.id, discordenoChannel);
}
+1 -1
View File
@@ -3,7 +3,7 @@ import type { Bot } from "../../bot.ts";
/** Get pinned messages in this channel. */
export async function getPins(bot: Bot, channelId: bigint) {
const result = await bot.rest.runMethod<Message[]>(bot.rest,"get", bot.constants.endpoints.CHANNEL_PINS(channelId));
const result = await bot.rest.runMethod<Message[]>(bot.rest, "get", bot.constants.endpoints.CHANNEL_PINS(channelId));
return result.map(bot.transformers.message);
}
+1 -1
View File
@@ -12,5 +12,5 @@ export async function getStageInstance(bot: Bot, channelId: bigint) {
}
}
return await bot.rest.runMethod<StageInstance>(bot.rest,"get", bot.constants.endpoints.STAGE_INSTANCE(channelId));
return await bot.rest.runMethod<StageInstance>(bot.rest, "get", bot.constants.endpoints.STAGE_INSTANCE(channelId));
}
+1 -1
View File
@@ -29,5 +29,5 @@ export async function startTyping(bot: Bot, channelId: bigint) {
}
}
return await bot.rest.runMethod<undefined>(bot.rest,"post", bot.constants.endpoints.CHANNEL_TYPING(channelId));
return await bot.rest.runMethod<undefined>(bot.rest, "post", bot.constants.endpoints.CHANNEL_TYPING(channelId));
}
+13 -8
View File
@@ -7,12 +7,17 @@ export async function swapChannels(bot: Bot, guildId: bigint, channelPositions:
throw "You must provide at least two channels to be swapped.";
}
return await bot.rest.runMethod<undefined>(bot.rest,"patch", bot.constants.endpoints.GUILD_CHANNELS(guildId), channelPositions.map((channelPosition) => {
return {
id: channelPosition.id,
position: channelPosition.position,
lock_positions: channelPosition.lockPositions,
parent_id: channelPosition.parentId
}
}));
return await bot.rest.runMethod<undefined>(
bot.rest,
"patch",
bot.constants.endpoints.GUILD_CHANNELS(guildId),
channelPositions.map((channelPosition) => {
return {
id: channelPosition.id,
position: channelPosition.position,
lock_positions: channelPosition.lockPositions,
parent_id: channelPosition.parentId,
};
})
);
}
@@ -4,7 +4,7 @@ import type { ChannelTypes } from "../../types/channels/channel_types.ts";
/** Updates fields of an existing Stage instance. Requires the user to be a moderator of the Stage channel. */
export async function updateStageInstance(
bot: Bot,
bot: Bot,
channelId: bigint,
data: Partial<Pick<StageInstance, "topic" | "privacyLevel">> = {}
) {
@@ -28,8 +28,8 @@ export async function updateStageInstance(
throw new Error(bot.constants.Errors.INVALID_TOPIC_LENGTH);
}
return await bot.rest.runMethod<StageInstance>(bot.rest,"patch", bot.constants.endpoints.STAGE_INSTANCE(channelId), {
return await bot.rest.runMethod<StageInstance>(bot.rest, "patch", bot.constants.endpoints.STAGE_INSTANCE(channelId), {
topic: data.topic,
privacy_level: data.privacyLevel
privacy_level: data.privacyLevel,
});
}
+11 -8
View File
@@ -18,14 +18,17 @@ export async function updateBotVoiceState(
options: UpdateSelfVoiceState | ({ userId: bigint } & UpdateOthersVoiceState)
) {
return await bot.rest.runMethod(
bot.rest,
bot.rest,
"patch",
bot.constants.endpoints.UPDATE_VOICE_STATE(guildId, bot.utils.hasOwnProperty(options, "userId") ? options.userId : undefined),
{
channel_id: options.channelId,
suppress: options.suppress,
request_to_speak_timestamp: options.requestToSpeakTimestamp,
user_id: options.userId
}
bot.constants.endpoints.UPDATE_VOICE_STATE(
guildId,
bot.utils.hasOwnProperty(options, "userId") ? options.userId : undefined
),
{
channel_id: options.channelId,
suppress: options.suppress,
request_to_speak_timestamp: options.requestToSpeakTimestamp,
user_id: options.userId,
}
);
}