change: prettier code

This commit is contained in:
TriForMine
2021-10-21 16:07:35 +00:00
committed by GitHub Action
parent fe22c5ea73
commit 9a1f8f41a5
14 changed files with 112 additions and 68 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
import type { DiscordImageFormat } from "../../types/misc/image_format.ts";
import type { DiscordImageSize } from "../../types/misc/image_size.ts";
import type {Bot} from "../../bot.ts";
import type { Bot } from "../../bot.ts";
/** The users custom avatar or the default avatar if you don't have a member object. */
export function avatarURL(
+11 -4
View File
@@ -1,14 +1,21 @@
import type { CreateGuildBan } from "../../types/guilds/create_guild_ban.ts";
import type {Bot} from "../../bot.ts";
import type { Bot } from "../../bot.ts";
/** Ban a user from the guild and optionally delete previous messages sent by the user. Requires the BAN_MEMBERS permission. */
export async function ban(bot: Bot, guildId: bigint, id: bigint, options?: CreateGuildBan) {
await bot.utils.requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]);
return await bot.rest.runMethod<undefined>(bot.rest,"put", bot.constants.endpoints.GUILD_BAN(guildId, id), (options ? {
return await bot.rest.runMethod<undefined>(
bot.rest,
"put",
bot.constants.endpoints.GUILD_BAN(guildId, id),
options
? {
delete_message_days: options.deleteMessageDays,
reason: options.reason
} : {}));
reason: options.reason,
}
: {}
);
}
// aliases
+1 -1
View File
@@ -1,4 +1,4 @@
import type {Bot} from "../../bot.ts";
import type { Bot } from "../../bot.ts";
/** Kicks a member from a voice channel */
export function disconnectMember(bot: Bot, guildId: bigint, memberId: bigint) {
+9 -4
View File
@@ -1,12 +1,17 @@
import type {Bot} from "../../bot.ts";
import type { Bot } from "../../bot.ts";
/** Edit the nickname of the bot in this guild */
export async function editBotNickname(bot: Bot, guildId: bigint, nickname: string | null) {
await bot.utils.requireBotGuildPermissions(bot,guildId, ["CHANGE_NICKNAME"]);
await bot.utils.requireBotGuildPermissions(bot, guildId, ["CHANGE_NICKNAME"]);
const response = await bot.rest.runMethod<{ nick: string }>(bot.rest,"patch", bot.constants.endpoints.USER_NICK(guildId), {
const response = await bot.rest.runMethod<{ nick: string }>(
bot.rest,
"patch",
bot.constants.endpoints.USER_NICK(guildId),
{
nick: nickname,
});
}
);
return response.nick;
}
+6 -6
View File
@@ -1,8 +1,8 @@
import type { ModifyGuildMember } from "../../types/guilds/modify_guild_member.ts";
import type { GuildMemberWithUser } from "../../types/members/guild_member.ts";
import type { PermissionStrings } from "../../types/permissions/permission_strings.ts";
import type {Bot} from "../../bot.ts";
import type {SnakeCasedPropertiesDeep} from "../../types/util.ts";
import type { Bot } from "../../bot.ts";
import type { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/** Edit the member */
export async function editMember(bot: Bot, guildId: bigint, memberId: bigint, options: ModifyGuildMember) {
@@ -35,13 +35,13 @@ export async function editMember(bot: Bot, guildId: bigint, memberId: bigint, op
if (options.channelId) {
const requiredVoicePerms: Set<PermissionStrings> = new Set(["CONNECT", "MOVE_MEMBERS"]);
if (memberVoiceState) {
await bot.utils.requireBotChannelPermissions(bot,memberVoiceState?.channelId, [...requiredVoicePerms]);
await bot.utils.requireBotChannelPermissions(bot, memberVoiceState?.channelId, [...requiredVoicePerms]);
}
await bot.utils.requireBotChannelPermissions(bot,options.channelId, [...requiredVoicePerms]);
await bot.utils.requireBotChannelPermissions(bot, options.channelId, [...requiredVoicePerms]);
}
}
await bot.utils.requireBotGuildPermissions(bot,guildId, [...requiredPerms]);
await bot.utils.requireBotGuildPermissions(bot, guildId, [...requiredPerms]);
const result = await bot.rest.runMethod<SnakeCasedPropertiesDeep<GuildMemberWithUser>>(
bot.rest,
@@ -52,7 +52,7 @@ export async function editMember(bot: Bot, guildId: bigint, memberId: bigint, op
roles: options.roles,
mute: options.mute,
deaf: options.deaf,
channel_id: options.channelId
channel_id: options.channelId,
}
);
+10 -5
View File
@@ -1,9 +1,9 @@
import type { RequestGuildMembers } from "../../types/members/request_guild_members.ts";
import { Collection } from "../../util/collection.ts";
import type {Bot} from "../../bot.ts";
import {DiscordGatewayIntents} from "../../types/gateway/gateway_intents.ts";
import {DiscordGatewayOpcodes} from "../../types/codes/gateway_opcodes.ts";
import type {DiscordenoMember} from "../../transformers/member.ts";
import type { Bot } from "../../bot.ts";
import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts";
import { DiscordGatewayOpcodes } from "../../types/codes/gateway_opcodes.ts";
import type { DiscordenoMember } from "../../transformers/member.ts";
/**
* ⚠️ BEGINNER DEVS!! YOU SHOULD ALMOST NEVER NEED THIS AND YOU CAN GET FROM cache.members.get()
@@ -13,7 +13,12 @@ import type {DiscordenoMember} from "../../transformers/member.ts";
* REST: 50/s global(across all shards) rate limit with ALL requests this included
* GW(this function): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is now 960/m.
*/
export function fetchMembers(bot: Bot, guildId: bigint, shardId: number, options?: Omit<RequestGuildMembers, "guildId">) {
export function fetchMembers(
bot: Bot,
guildId: bigint,
shardId: number,
options?: Omit<RequestGuildMembers, "guildId">
) {
// You can request 1 member without the intent
// Check if intents is not 0 as proxy ws won't set intents in other instances
if (
+7 -3
View File
@@ -1,6 +1,6 @@
import type { GuildMemberWithUser } from "../../types/members/guild_member.ts";
import type {Bot} from "../../bot.ts";
import type {SnakeCasedPropertiesDeep} from "../../types/util.ts";
import type { Bot } from "../../bot.ts";
import type { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/** Returns a guild member object for the specified user.
*
@@ -10,7 +10,11 @@ export async function getMember(bot: Bot, guildId: bigint, id: bigint, options?:
const guild = await bot.cache.guilds.get(guildId);
if (!guild && !options?.force) return;
const data = await bot.rest.runMethod<SnakeCasedPropertiesDeep<GuildMemberWithUser>>(bot.rest,"get", bot.constants.endpoints.GUILD_MEMBER(guildId, id));
const data = await bot.rest.runMethod<SnakeCasedPropertiesDeep<GuildMemberWithUser>>(
bot.rest,
"get",
bot.constants.endpoints.GUILD_MEMBER(guildId, id)
);
const discordenoMember = await bot.transformers.member(bot, data, guildId);
await bot.cache.members.set(discordenoMember.id, discordenoMember);
+8 -5
View File
@@ -1,10 +1,10 @@
import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts";
import type { GuildMemberWithUser } from "../../types/members/guild_member.ts";
import type { ListGuildMembers } from "../../types/members/list_guild_members.ts";
import type {Bot} from "../../bot.ts";
import {Collection} from "../../util/collection.ts";
import type {DiscordenoMember} from "../../transformers/member.ts";
import type {SnakeCasedPropertiesDeep} from "../../types/util.ts";
import type { Bot } from "../../bot.ts";
import { Collection } from "../../util/collection.ts";
import type { DiscordenoMember } from "../../transformers/member.ts";
import type { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/**
* ⚠️ BEGINNER DEVS!! YOU SHOULD ALMOST NEVER NEED THIS AND YOU CAN GET FROM cache.members.get()
@@ -16,7 +16,10 @@ import type {SnakeCasedPropertiesDeep} from "../../types/util.ts";
*/
export async function getMembers(bot: Bot, guildId: bigint, options?: ListGuildMembers & { addToCache?: boolean }) {
// Check if intents is not 0 as proxy ws won't set intents in other instances
if (bot.gateway.identifyPayload.intents && !(bot.gateway.identifyPayload.intents & DiscordGatewayIntents.GuildMembers)) {
if (
bot.gateway.identifyPayload.intents &&
!(bot.gateway.identifyPayload.intents & DiscordGatewayIntents.GuildMembers)
) {
throw new Error(bot.cache.Errors.MISSING_INTENT_GUILD_MEMBERS);
}
+10 -5
View File
@@ -1,15 +1,20 @@
import {Bot} from "../../bot.ts";
import { Bot } from "../../bot.ts";
/** Kick a member from the server */
export async function kick(bot: Bot, guildId: bigint, memberId: bigint, reason?: string) {
const botsHighestRole = await bot.utils.highestRole(bot,guildId, botId);
const membersHighestRole = await bot.utils.highestRole(bot,guildId, memberId);
const botsHighestRole = await bot.utils.highestRole(bot, guildId, botId);
const membersHighestRole = await bot.utils.highestRole(bot, guildId, memberId);
if (botsHighestRole && membersHighestRole && botsHighestRole.position <= membersHighestRole.position) {
throw new Error(bot.constants.Errors.BOTS_HIGHEST_ROLE_TOO_LOW);
}
await bot.utils.requireBotGuildPermissions(bot,guildId, ["KICK_MEMBERS"]);
await bot.utils.requireBotGuildPermissions(bot, guildId, ["KICK_MEMBERS"]);
return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.GUILD_MEMBER(guildId, memberId), { reason });
return await bot.rest.runMethod<undefined>(
bot.rest,
"delete",
bot.constants.endpoints.GUILD_MEMBER(guildId, memberId),
{ reason }
);
}
// aliases
+1 -1
View File
@@ -1,4 +1,4 @@
import type {Bot} from "../../bot.ts";
import type { Bot } from "../../bot.ts";
/**
* Move a member from a voice channel to another.
+10 -5
View File
@@ -1,5 +1,5 @@
import type { BeginGuildPrune } from "../../types/guilds/begin_guild_prune.ts";
import type {Bot} from "../../bot.ts";
import type { Bot } from "../../bot.ts";
/**
* Begin a prune operation. Requires the KICK_MEMBERS permission. Returns an object with one 'pruned' key indicating the number of members that were removed in the prune operation. For large guilds it's recommended to set the computePruneCount option to false, forcing 'pruned' to null. Fires multiple Guild Member Remove Gateway events.
@@ -10,13 +10,18 @@ export async function pruneMembers(bot: Bot, guildId: bigint, options: BeginGuil
if (options.days && options.days < 1) throw new Error(bot.constants.Errors.PRUNE_MIN_DAYS);
if (options.days && options.days > 30) throw new Error(bot.constants.Errors.PRUNE_MAX_DAYS);
await bot.utils.requireBotGuildPermissions(bot,guildId, ["KICK_MEMBERS"]);
await bot.utils.requireBotGuildPermissions(bot, guildId, ["KICK_MEMBERS"]);
const result = await bot.rest.runMethod<{ pruned: number }>(bot.rest,"post", bot.constants.endpoints.GUILD_PRUNE(guildId), {
const result = await bot.rest.runMethod<{ pruned: number }>(
bot.rest,
"post",
bot.constants.endpoints.GUILD_PRUNE(guildId),
{
days: options.days,
compute_prune_count: options.computePruneCount,
include_roles: options.includeRoles
});
include_roles: options.includeRoles,
}
);
return result.pruned;
}
+10 -5
View File
@@ -1,9 +1,9 @@
import type { GuildMemberWithUser } from "../../types/members/guild_member.ts";
import type { SearchGuildMembers } from "../../types/members/search_guild_members.ts";
import { Collection } from "../../util/collection.ts";
import {Bot} from "../../bot.ts";
import {DiscordenoMember} from "../../transformers/member.ts";
import type {SnakeCasedPropertiesDeep} from "../../types/util.ts";
import { Bot } from "../../bot.ts";
import { DiscordenoMember } from "../../transformers/member.ts";
import type { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/**
* ⚠️ BEGINNER DEVS!! YOU SHOULD ALMOST NEVER NEED THIS AND YOU CAN GET FROM cache.members.filter()
@@ -25,10 +25,15 @@ export async function searchMembers(
}
}
const result = await bot.rest.runMethod<SnakeCasedPropertiesDeep<GuildMemberWithUser>[]>(bot.rest,"get", bot.constants.endpoints.GUILD_MEMBERS_SEARCH(guildId), {
const result = await bot.rest.runMethod<SnakeCasedPropertiesDeep<GuildMemberWithUser>[]>(
bot.rest,
"get",
bot.constants.endpoints.GUILD_MEMBERS_SEARCH(guildId),
{
...options,
query,
});
}
);
const members = await Promise.all(
result.map(async (member) => {
+9 -4
View File
@@ -1,7 +1,7 @@
import type { Channel } from "../../types/channels/channel.ts";
import type { CreateMessage } from "../../types/messages/create_message.ts";
import type {Bot} from "../../bot.ts";
import type {SnakeCasedPropertiesDeep} from "../../types/util.ts";
import type { Bot } from "../../bot.ts";
import type { SnakeCasedPropertiesDeep } from "../../types/util.ts";
/** Send a message to a users DM. Note: this takes 2 API calls. 1 is to fetch the users dm channel. 2 is to send a message to that channel. */
export async function sendDirectMessage(bot: Bot, memberId: bigint, content: string | CreateMessage) {
@@ -10,9 +10,14 @@ export async function sendDirectMessage(bot: Bot, memberId: bigint, content: str
let dmChannel = await bot.cache.channels.get(memberId);
if (!dmChannel) {
// If not available in cache create a new one.
const dmChannelData = await bot.rest.runMethod<SnakeCasedPropertiesDeep<Channel>>(bot.rest,"post", bot.constants.endpoints.USER_DM, {
const dmChannelData = await bot.rest.runMethod<SnakeCasedPropertiesDeep<Channel>>(
bot.rest,
"post",
bot.constants.endpoints.USER_DM,
{
recipient_id: memberId,
});
}
);
const discordenoChannel = await bot.transformers.channel(bot, dmChannelData);
// Recreate the channel and add it under the users id
await bot.cache.channels.set(memberId, discordenoChannel);
+2 -2
View File
@@ -1,10 +1,10 @@
import type {Bot} from "../../bot.ts";
import type { Bot } from "../../bot.ts";
/** Remove the ban for a user. Requires BAN_MEMBERS permission */
export async function unban(bot: Bot, guildId: bigint, id: bigint) {
await bot.utils.requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.GUILD_BAN(guildId, id));
return await bot.rest.runMethod<undefined>(bot.rest, "delete", bot.constants.endpoints.GUILD_BAN(guildId, id));
}
// aliases