This commit is contained in:
Skillz
2020-08-05 14:50:08 -04:00
parent d70ef64bc7
commit 65b5c3ac40
5 changed files with 27 additions and 61 deletions

View File

@@ -11,7 +11,6 @@ import { endpoints } from "../constants/discord.ts";
import { Errors } from "../types/errors.ts";
import { Permissions, Permission } from "../types/permission.ts";
import {
CreateChannelOptions,
ChannelCreatePayload,
ChannelTypes,
} from "../types/channel.ts";
@@ -28,6 +27,7 @@ import {
GuildEditOptions,
PruneOptions,
PrunePayload,
ChannelCreateOptions,
} from "../types/guild.ts";
import { RoleData } from "../types/role.ts";
import { createRole } from "../structures/role.ts";
@@ -93,7 +93,7 @@ export function guildBannerURL(
export async function createGuildChannel(
guild: Guild,
name: string,
options?: CreateChannelOptions,
options?: ChannelCreateOptions,
) {
if (!botHasPermission(guild.id, [Permissions.MANAGE_CHANNELS])) {
throw new Error(Errors.MISSING_MANAGE_CHANNELS);
@@ -510,10 +510,7 @@ export function channelHasPermissions(
const role = guild.roles.get(roleID);
if (!role) return bits;
bits |= role.permissions.reduce(
(bits, p) => bits & BigInt(Permissions[p]),
BigInt(0),
);
bits |= BigInt(role.permissions_new)
return bits;
}, BigInt(0));

View File

@@ -22,7 +22,7 @@ export interface ChannelEditOptions {
parent_id?: string;
}
export interface Base_Channel_Create {
export interface BaseChannelCreate {
/** The id of the guild */
guild_id?: string;
/** Sorting position of the channel */
@@ -65,37 +65,16 @@ export interface DMChannelCreatePayload {
}[];
}
export interface ChannelCreatePayload extends Base_Channel_Create {
export interface ChannelCreatePayload extends BaseChannelCreate {
/** The id of this channel */
id: string;
/** The type of the channel */
type: Channel_Type;
type: ChannelType;
/** Explicit permission overwrites for members and roles */
permission_overwrites?: RawOverwrite[];
}
export interface CreateChannelOptions {
/** The type of the channel */
type?: ChannelTypes;
/** The channel topic (0-1024 characters) */
topic?: string;
/** The bitrate (in bits) of the voice channel */
bitrate?: number;
/** The user limit of the voice channel */
user_limit?: number;
/** Amount of seconds a user has to wait before sending another message (0-21600) Bots and users with the permission MANAGE_MESSAGES or MANAGE_CHANNEL are unaffected. */
rate_limit_per_user?: number;
/** Sorting position of the channel */
position?: number;
/** Explicit permission overwrites for members and roles */
permission_overwrites?: Overwrite[];
/** The parent category id */
parent_id?: string | null;
/** Whether the channel is nsfw */
nsfw?: boolean;
}
export type Channel_Type = 0 | 1 | 2 | 4 | 5 | 6;
export type ChannelType = 0 | 1 | 2 | 4 | 5 | 6;
export enum ChannelTypes {
/** A text channel within a server */
@@ -114,10 +93,6 @@ export enum ChannelTypes {
GUILD_STORE,
}
// export interface File_Content {
// }
export interface MessageContent {
mentions?: {
/** An array of allowed mention types to parse from the content. */

View File

@@ -1,6 +1,6 @@
import { Activity } from "./message.ts";
import { ClientStatusPayload } from "./presence.ts";
import { Partial_User, UserPayload } from "./guild.ts";
import { PartialUser, UserPayload } from "./guild.ts";
import { MemberCreatePayload } from "./member.ts";
export interface DiscordPayload {
@@ -177,7 +177,7 @@ export interface Emoji {
animated?: boolean;
}
export enum StatusType {
export enum StatusTypes {
Online = "online",
DoNotDisturb = "dnd",
Idle = "idle",
@@ -185,7 +185,7 @@ export enum StatusType {
Offline = "offline",
}
export type Status_Type = "online" | "dnd" | "idle" | "invisible" | "offline";
export type StatusType = "online" | "dnd" | "idle" | "invisible" | "offline";
export interface Status {
afk: boolean;
@@ -199,7 +199,7 @@ export interface WebhookUpdatePayload {
export interface PresenceUpdatePayload {
/** The user presence is being updated for. */
user: Partial_User;
user: PartialUser;
/** The roles this user is in */
roles: string[];
/** null, or the user's current activity */
@@ -207,7 +207,7 @@ export interface PresenceUpdatePayload {
/** The id of the guild */
guild_id: string;
/** Either idle, dnd, online, or offline */
status: Status_Type;
status: StatusType;
/** All user's current activity */
activities: Activity[];
/** The user's platform dependent status */

View File

@@ -103,7 +103,7 @@ export interface UpdateGuildPayload {
/** The custom guild emojis */
emojis: Emoji[];
/** Enabled guild features */
features: Guild_Features[];
features: GuildFeatures[];
/** Required MFA level for the guild */
mfa_level: number;
/** True if the server widget is enabled */
@@ -151,7 +151,7 @@ export interface CreateGuildPayload extends UpdateGuildPayload {
unavailable: boolean;
/** Total number of members in this guild */
member_count?: number;
voice_states: Voice_State[];
voice_states: VoiceState[];
/** Users in the guild */
members: MemberCreatePayload[];
/** Channels in the guild */
@@ -159,7 +159,7 @@ export interface CreateGuildPayload extends UpdateGuildPayload {
presences: Presence[];
}
export type Guild_Features =
export type GuildFeatures =
| "INVITE_SPLASH"
| "VIP_REGIONS"
| "VANITY_URL"
@@ -173,7 +173,7 @@ export type Guild_Features =
| "ANIMATED_ICON"
| "BANNER";
export interface Voice_Region {
export interface VoiceRegion {
/** unique ID for the region */
id: string;
/** name of the region */
@@ -245,7 +245,7 @@ export interface EditIntegrationOptions {
enable_emoticons: boolean;
}
export interface Guild_Integration {
export interface GuildIntegration {
/** The integrations unique id */
id: string;
/** the integrations name */
@@ -304,7 +304,7 @@ export interface UserPayload {
premium_type?: number;
}
export interface Partial_User {
export interface PartialUser {
/** The user's id */
id: string;
/** the user's username, not unique across the platform */
@@ -331,7 +331,7 @@ export interface Partial_User {
premium_type?: number;
}
export enum User_Flags {
export enum UserFlags {
NONE,
DISCORD_EMPLOYEE,
DISCORD_PARTNER,
@@ -345,17 +345,17 @@ export enum User_Flags {
SYSTEM = 1 << 12,
}
export enum Nitro_Types {
export enum NitroTypes {
NITRO_CLASSIC = 1,
NITRO,
}
export interface Vanity_Invite {
export interface VanityInvite {
code: string | null;
uses: number;
}
export interface Guild_Embed {
export interface GuildEmbed {
/** Whether the embed is enbaled. */
enabled: boolean;
}
@@ -480,7 +480,7 @@ export interface RawOverwrite {
deny_new: string;
}
export interface ChannelCreate_Options {
export interface ChannelCreateOptions {
/** The type of the channel */
type?: ChannelType;
/** The channel topic. (0-1024 characters) */
@@ -536,7 +536,7 @@ export interface PruneOptions {
roles: string[];
}
export interface Voice_State {
export interface VoiceState {
/** the guild id this voice state is for */
guild_id?: string;
/** the channel id this user is connected to */

View File

@@ -17,13 +17,10 @@ export function memberHasPermission(
if (memberID === guild.ownerID) return true;
const permissionBits = memberRoleIDs.map((id) =>
guild.roles.get(id)?.permissions || []
guild.roles.get(id)?.permissions_new
)
.reduce((bits, permissions) => {
bits |= permissions.reduce(
(b, p) => b & BigInt(Permissions[p]),
BigInt(0),
);
bits |= BigInt(permissions)
return bits;
}, BigInt(0));
@@ -44,10 +41,7 @@ export function botHasPermission(guildID: string, permissions: Permissions[]) {
const permissionBits = member.roles
.map((id) => guild.roles.get(id)!)
.reduce((bits, data) => {
bits |= data.permissions.reduce(
(b, p) => b & BigInt(Permissions[p]),
BigInt(0),
);
bits |= BigInt(data.permissions_new)
return bits;
}, BigInt(0));