mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-21 02:40:08 +00:00
ton of fixes
This commit is contained in:
11
.prettierrc
11
.prettierrc
@@ -1,11 +1,4 @@
|
||||
|
||||
{
|
||||
"singleQuote": true,
|
||||
"tabWidth": 2,
|
||||
"semi": false,
|
||||
"printWidth": 120,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": true,
|
||||
"arrowParens": "avoid",
|
||||
"endOfLine": "auto"
|
||||
"semi": false,
|
||||
"printWidth": 120
|
||||
}
|
||||
|
||||
10
.vscode/setting.json
vendored
10
.vscode/setting.json
vendored
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"deno.enable": true,
|
||||
"editor.formatOnSave": true,
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "axetroy.vscode-deno"
|
||||
},
|
||||
"[json]": {
|
||||
"editor.defaultFormatter": "axetroy.vscode-deno"
|
||||
}
|
||||
}
|
||||
10
.vscode/settings.json
vendored
Normal file
10
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"deno.enable": true,
|
||||
"editor.formatOnSave": true,
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[json]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,13 @@ import {
|
||||
Get_Messages_Before,
|
||||
MessageContent,
|
||||
Create_Invite_Options
|
||||
} from '../types/channel'
|
||||
import Client from '../module/client'
|
||||
} from '../types/channel.ts'
|
||||
import Client from '../module/client.ts'
|
||||
import { endpoints } from '../constants/discord.ts'
|
||||
import { create_message, Message } from './message'
|
||||
import { Message_Create_Options } from '../types/message'
|
||||
import { Permission, Permissions } from '../types/permission'
|
||||
import { Guild } from '../types/return-type'
|
||||
import { create_message, Message } from './message.ts'
|
||||
import { Message_Create_Options } from '../types/message.ts'
|
||||
import { Permission, Permissions } from '../types/permission.ts'
|
||||
import { Guild } from '../types/return-type.ts'
|
||||
|
||||
export const create_channel = (data: Channel_Create_Options, guild: Guild, client: Client) => {
|
||||
const base_channel = {
|
||||
@@ -49,7 +49,9 @@ export const create_channel = (data: Channel_Create_Options, guild: Guild, clien
|
||||
},
|
||||
/** Get pinned messages in this channel. */
|
||||
get_pins: async () => {
|
||||
const result = (await client.discordRequestManager.get(endpoints.CHANNEL_PINS(data.id))) as Message_Create_Options[]
|
||||
const result = (await client.discordRequestManager.get(
|
||||
endpoints.CHANNEL_PINS(data.id)
|
||||
)) as Message_Create_Options[]
|
||||
return result.map(res => create_message(res, client))
|
||||
},
|
||||
/** Send a message to the channel. Requires SEND_MESSAGES permission. */
|
||||
@@ -71,11 +73,12 @@ export const create_channel = (data: Channel_Create_Options, guild: Guild, clien
|
||||
}
|
||||
|
||||
// If it is a dm channel
|
||||
if (data.type === Channel_Types.DM)
|
||||
if (data.type === Channel_Types.DM) {
|
||||
return {
|
||||
...base_channel,
|
||||
...base_text_channel
|
||||
}
|
||||
}
|
||||
|
||||
// GUILD CHANNEL ONLY
|
||||
const base_guild_channel = {
|
||||
@@ -94,8 +97,9 @@ export const create_channel = (data: Channel_Create_Options, guild: Guild, clien
|
||||
if (id === guild.owner_id()) return true
|
||||
|
||||
const member = guild.members.get(id)
|
||||
if (!member)
|
||||
if (!member) {
|
||||
throw 'Invalid member id provided. This member was not found in the cache. Please fetch them with getMember on guild.'
|
||||
}
|
||||
|
||||
let permissionBits = member.roles().reduce((bits, role_id) => {
|
||||
const role = guild.roles.get(role_id)
|
||||
@@ -117,7 +121,7 @@ export const create_channel = (data: Channel_Create_Options, guild: Guild, clien
|
||||
}
|
||||
|
||||
// Guild Text Channel
|
||||
if ([Channel_Types.GUILD_TEXT, Channel_Types.GUILD_NEWS].includes(data.type))
|
||||
if ([Channel_Types.GUILD_TEXT, Channel_Types.GUILD_NEWS].includes(data.type)) {
|
||||
return {
|
||||
...base_guild_channel,
|
||||
...base_text_channel,
|
||||
@@ -128,11 +132,14 @@ export const create_channel = (data: Channel_Create_Options, guild: Guild, clien
|
||||
/** Delete messages from the channel. 2-100. Requires the MANAGE_MESSAGES permission */
|
||||
delete_messages: (ids: string[], reason?: string) => {
|
||||
// TODO: Requires the MANAGE_MESSAGES permission.
|
||||
if (ids.length < 2) throw 'This endpoint will only accept 2-100 message ids.'
|
||||
if (ids.length > 100)
|
||||
if (ids.length < 2) {
|
||||
throw 'This endpoint will only accept 2-100 message ids.'
|
||||
}
|
||||
if (ids.length > 100) {
|
||||
console.warn(
|
||||
`This endpoint only accepts a maximum of 100 messages. Deleting the first 100 message ids provided.`
|
||||
)
|
||||
}
|
||||
return client.discordRequestManager.POST(endpoints.CHANNEL_BULK_DELETE(data.id), {
|
||||
messages: ids.splice(0, 100),
|
||||
reason
|
||||
@@ -154,16 +161,18 @@ export const create_channel = (data: Channel_Create_Options, guild: Guild, clien
|
||||
return client.discordRequestManager.get(endpoints.CHANNEL_WEBHOOKS(data.id))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.type === Channel_Types.GUILD_CATEGORY)
|
||||
if (data.type === Channel_Types.GUILD_CATEGORY) {
|
||||
return {
|
||||
...base_guild_channel,
|
||||
/** Gets an array of all the channels ids that are the children of this category. */
|
||||
children_ids: () =>
|
||||
Object.keys(guild.channels).filter(channel => guild.channels.get(channel).parent_id === data.id)
|
||||
}
|
||||
}
|
||||
|
||||
if (data.type === Channel_Types.GUILD_VOICE)
|
||||
if (data.type === Channel_Types.GUILD_VOICE) {
|
||||
return {
|
||||
...base_guild_channel,
|
||||
// TODO: after learning opus and stuff
|
||||
@@ -172,6 +181,7 @@ export const create_channel = (data: Channel_Create_Options, guild: Guild, clien
|
||||
/** Leave a voice channel */
|
||||
leave: () => {}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...data,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Client from "../module/client.ts";
|
||||
import { endpoints } from "../constants/discord.ts";
|
||||
import { format_image_url } from "../utils/cdn.ts";
|
||||
import Client from '../module/client.ts'
|
||||
import { endpoints } from '../constants/discord.ts'
|
||||
import { format_image_url } from '../utils/cdn.ts'
|
||||
import {
|
||||
Create_Guild_Payload,
|
||||
ChannelTypes,
|
||||
@@ -13,14 +13,13 @@ import {
|
||||
Create_Emojis_Options,
|
||||
Edit_Emojis_Options,
|
||||
Create_Role_Options
|
||||
} from "../types/guild";
|
||||
import { create_role, Role } from "./role.ts";
|
||||
import { create_member } from "./member.ts";
|
||||
import { create_channel } from "./channel.ts";
|
||||
import { Channel_Create_Options, Channel } from "../types/channel.ts";
|
||||
import { Image_Size, Image_Formats } from "../types/cdn.ts";
|
||||
import { Permissions, Permission } from "../types/permission.ts";
|
||||
import { Member } from "../types/member.ts";
|
||||
} from '../types/guild.ts'
|
||||
import { create_role } from './role.ts'
|
||||
import { create_member } from './member.ts'
|
||||
import { create_channel } from './channel.ts'
|
||||
import { Channel_Create_Options } from '../types/channel.ts'
|
||||
import { Image_Size, Image_Formats } from '../types/cdn.ts'
|
||||
import { Permissions, Permission } from '../types/permission.ts'
|
||||
|
||||
export const create_guild = (data: Create_Guild_Payload, client: Client) => {
|
||||
const guild = {
|
||||
@@ -45,7 +44,7 @@ export const create_guild = (data: Create_Guild_Payload, client: Client) => {
|
||||
/** The verification level required for the guild */
|
||||
verification_level: () => data.verification_level,
|
||||
/** The roles in the guild */
|
||||
roles: new Map<string, Role>(),
|
||||
roles: () => new Map(data.roles.map(r => [r.id, create_role(r)])),
|
||||
/** The custom guild emojis */
|
||||
emojis: () => data.emojis,
|
||||
/** The enabled guild features. */
|
||||
@@ -65,9 +64,9 @@ export const create_guild = (data: Create_Guild_Payload, client: Client) => {
|
||||
/** The current open voice states in the guild. */
|
||||
voice_states: () => data.voice_states,
|
||||
/** The users in this guild. */
|
||||
members: new Map<string, Member>(),
|
||||
members: new Map(data.members.map(m => [m.user.id, create_member(m, data.id, data.roles, data.owner_id, client)])),
|
||||
/** The channels in the guild */
|
||||
channels: new Map<string, Channel>(),
|
||||
channels: new Map(data.channels.map(c => [c.id, create_channel(c, client)])),
|
||||
/** The presences of all the users in the guild. */
|
||||
presences: new Map(data.presences.map(p => [p.user.id, p])),
|
||||
/** The maximum amount of presences for the guild(the default value, currently 5000 is in effect when null is returned.) */
|
||||
@@ -87,29 +86,14 @@ export const create_guild = (data: Create_Guild_Payload, client: Client) => {
|
||||
/** The preferred locale of this guild only set if the guild has the DISCOVERABLE feature, defaults to en-US */
|
||||
preferred_locale: () => data.preferred_locale,
|
||||
/** The full URL of the icon from Discords CDN. Undefined when no icon is set. */
|
||||
icon_url: (size: Image_Size = 128, format?: Image_Formats) => data.icon
|
||||
? format_image_url(
|
||||
endpoints.GUILD_ICON(data.id, data.icon),
|
||||
size,
|
||||
format
|
||||
)
|
||||
: undefined,
|
||||
icon_url: (size: Image_Size = 128, format?: Image_Formats) =>
|
||||
data.icon ? format_image_url(endpoints.GUILD_ICON(data.id, data.icon), size, format) : undefined,
|
||||
/** The full URL of the splash from Discords CDN. Undefined if no splash is set. */
|
||||
splash_url: (size: Image_Size = 128, format?: Image_Formats) => data.splash
|
||||
? format_image_url(
|
||||
endpoints.GUILD_SPLASH(data.id, data.splash),
|
||||
size,
|
||||
format
|
||||
)
|
||||
: undefined,
|
||||
splash_url: (size: Image_Size = 128, format?: Image_Formats) =>
|
||||
data.splash ? format_image_url(endpoints.GUILD_SPLASH(data.id, data.splash), size, format) : undefined,
|
||||
/** The full URL of the banner from Discords CDN. Undefined if no banner is set. */
|
||||
banner_url: (size: Image_Size = 128, format?: Image_Formats) => data.banner
|
||||
? format_image_url(
|
||||
endpoints.GUILD_BANNER(data.id, data.banner),
|
||||
size,
|
||||
format
|
||||
)
|
||||
: undefined,
|
||||
banner_url: (size: Image_Size = 128, format?: Image_Formats) =>
|
||||
data.banner ? format_image_url(endpoints.GUILD_BANNER(data.id, data.banner), size, format) : undefined,
|
||||
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
||||
create_channel: (name: string, options: Channel_Create_Options) => {
|
||||
// TODO: Check if the bot has `MANAGE_CHANNELS` permission before making a channel
|
||||
@@ -118,52 +102,43 @@ export const create_guild = (data: Create_Guild_Payload, client: Client) => {
|
||||
type: options?.type ? ChannelTypes[options.type] : undefined,
|
||||
permission_overwrites: options?.permission_overwrites
|
||||
? options.permission_overwrites.map(perm => ({
|
||||
...perm,
|
||||
allow: perm.allow.map(p => Permissions[p]),
|
||||
deny: perm.deny.map(p => Permissions[p])
|
||||
}))
|
||||
...perm,
|
||||
allow: perm.allow.map(p => Permissions[p]),
|
||||
deny: perm.deny.map(p => Permissions[p])
|
||||
}))
|
||||
: undefined,
|
||||
...options
|
||||
});
|
||||
})
|
||||
},
|
||||
/** Returns a list of guild channel objects.
|
||||
*
|
||||
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
|
||||
*/
|
||||
get_channels: () => {
|
||||
return client.discordRequestManager.get(endpoints.GUILD_CHANNELS(data.id));
|
||||
return client.discordRequestManager.get(endpoints.GUILD_CHANNELS(data.id))
|
||||
},
|
||||
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
|
||||
swap_channels: (channel_positions: Position_Swap[]) => {
|
||||
if (channel_positions.length <
|
||||
2)
|
||||
{
|
||||
throw "You must provide atleast two channels to be swapped.";
|
||||
if (channel_positions.length < 2) {
|
||||
throw 'You must provide atleast two channels to be swapped.'
|
||||
}
|
||||
return client.discordRequestManager.patch(
|
||||
endpoints.GUILD_CHANNELS(data.id),
|
||||
channel_positions
|
||||
);
|
||||
return client.discordRequestManager.patch(endpoints.GUILD_CHANNELS(data.id), channel_positions)
|
||||
},
|
||||
/** Returns a guild member object for the specified user.
|
||||
*
|
||||
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your members will be cached in your guild.**
|
||||
*/
|
||||
get_member: (id: string) => {
|
||||
return client.discordRequestManager.get(endpoints.GUILD_MEMBER(data.id, id));
|
||||
return client.discordRequestManager.get(endpoints.GUILD_MEMBER(data.id, id))
|
||||
},
|
||||
/** Create an emoji in the server. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. */
|
||||
create_emoji: (
|
||||
name: string,
|
||||
image: string,
|
||||
options: Create_Emojis_Options
|
||||
) => {
|
||||
create_emoji: (name: string, image: string, options: Create_Emojis_Options) => {
|
||||
// TODO: Check if the bot has `MANAGE_EMOJIS` permission
|
||||
return client.discordRequestManager.post(endpoints.GUILD_EMOJIS(data.id), {
|
||||
...options,
|
||||
name,
|
||||
image
|
||||
});
|
||||
})
|
||||
},
|
||||
/** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */
|
||||
edit_emoji: (id: string, options: Edit_Emojis_Options) => {
|
||||
@@ -171,42 +146,33 @@ export const create_guild = (data: Create_Guild_Payload, client: Client) => {
|
||||
return client.discordRequestManager.patch(endpoints.GUILD_EMOJI(data.id, id), {
|
||||
name: options.name,
|
||||
roles: options.roles
|
||||
});
|
||||
})
|
||||
},
|
||||
/** Delete the given emoji. Requires the MANAGE_EMOJIS permission. Returns 204 No Content on success. */
|
||||
delete_emoji: (id: string, reason?: string) => {
|
||||
// TODO: check if the bot has `MANAGE_EMOJIS` permission
|
||||
return client.discordRequestManager.delete(
|
||||
endpoints.GUILD_EMOJI(data.id, id),
|
||||
{ reason }
|
||||
);
|
||||
return client.discordRequestManager.delete(endpoints.GUILD_EMOJI(data.id, id), { reason })
|
||||
},
|
||||
/** Create a new role for the guild. Requires the MANAGE_ROLES permission. */
|
||||
create_role: async (options: Create_Role_Options) => {
|
||||
// TODO: check if the bot has the `MANAGE_ROLES` permission.
|
||||
const role = await client.discordRequestManager.post(
|
||||
endpoints.GUILD_ROLES(data.id),
|
||||
{
|
||||
...options,
|
||||
permissions: options.permissions?.map(perm => Permissions[perm])
|
||||
}
|
||||
);
|
||||
const role = await client.discordRequestManager.post(endpoints.GUILD_ROLES(data.id), {
|
||||
...options,
|
||||
permissions: options.permissions?.map(perm => Permissions[perm])
|
||||
})
|
||||
// TODO: cache this role
|
||||
|
||||
return role;
|
||||
return role
|
||||
},
|
||||
/** Edit a guild role. Requires the MANAGE_ROLES permission. */
|
||||
edit_role: (id: string, options: Create_Role_Options) => {
|
||||
// TODO: check if the bot has the `MANAGE_ROLES` permission.
|
||||
return client.discordRequestManager.patch(
|
||||
endpoints.GUILD_ROLE(data.id, id),
|
||||
options
|
||||
);
|
||||
return client.discordRequestManager.patch(endpoints.GUILD_ROLE(data.id, id), options)
|
||||
},
|
||||
/** Delete a guild role. Requires the MANAGE_ROLES permission. */
|
||||
delete_role: (id: string) => {
|
||||
// TODO: check if the bot has the `MANAGE_ROLES` permission.
|
||||
return client.discordRequestManager.delete(endpoints.GUILD_ROLE(data.id, id));
|
||||
return client.discordRequestManager.delete(endpoints.GUILD_ROLE(data.id, id))
|
||||
},
|
||||
/** Returns a list of role objects for the guild.
|
||||
*
|
||||
@@ -214,38 +180,27 @@ export const create_guild = (data: Create_Guild_Payload, client: Client) => {
|
||||
*/
|
||||
get_roles: () => {
|
||||
// TODO: check if the bot has the `MANAGE_ROLES` permission.
|
||||
return client.discordRequestManager.get(endpoints.GUILD_ROLES(data.id));
|
||||
return client.discordRequestManager.get(endpoints.GUILD_ROLES(data.id))
|
||||
},
|
||||
/** Modify the positions of a set of role objects for the guild. Requires the MANAGE_ROLES permission. */
|
||||
swap_roles: (rolePositons: Position_Swap) => {
|
||||
// TODO: check if the bot has the `MANAGE_ROLES` permission.
|
||||
return client.discordRequestManager.patch(
|
||||
endpoints.GUILD_ROLES(data.id),
|
||||
rolePositons
|
||||
);
|
||||
return client.discordRequestManager.patch(endpoints.GUILD_ROLES(data.id), rolePositons)
|
||||
},
|
||||
/** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */
|
||||
get_prune_count: async (days: number) => {
|
||||
if (days <
|
||||
1)
|
||||
{
|
||||
throw `The number of days to count prune for must be 1 or more.`;
|
||||
if (days < 1) {
|
||||
throw `The number of days to count prune for must be 1 or more.`
|
||||
}
|
||||
// TODO: check if the bot has `KICK_MEMBERS` permission
|
||||
const result = (await client.discordRequestManager.get(
|
||||
endpoints.GUILD_PRUNE(data.id),
|
||||
{ days }
|
||||
)) as PrunePayload;
|
||||
return result.pruned;
|
||||
const result = (await client.discordRequestManager.get(endpoints.GUILD_PRUNE(data.id), { days })) as PrunePayload
|
||||
return result.pruned
|
||||
},
|
||||
/** Begin pruning all members in the given time period */
|
||||
prune_members: (days: number) => {
|
||||
if (days < 1) throw `The number of days must be 1 or more.`;
|
||||
if (days < 1) throw `The number of days must be 1 or more.`
|
||||
// TODO: check if the bot has `KICK_MEMBERS` permission.
|
||||
return client.discordRequestManager.post(
|
||||
endpoints.GUILD_PRUNE(data.id),
|
||||
{ days }
|
||||
);
|
||||
return client.discordRequestManager.post(endpoints.GUILD_PRUNE(data.id), { days })
|
||||
},
|
||||
// TODO: REQUEST THIS OVER WEBSOCKET WITH GET_GUILD_MEMBERS ENDPOINT
|
||||
// fetch_all_members: () => {
|
||||
@@ -255,142 +210,114 @@ export const create_guild = (data: Create_Guild_Payload, client: Client) => {
|
||||
// TODO: check if the bot has VIEW_AUDIT_LOGS permission
|
||||
return client.discordRequestManager.get(endpoints.GUILD_AUDIT_LOGS(data.id), {
|
||||
...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
|
||||
})
|
||||
},
|
||||
/** Returns the guild embed object. Requires the MANAGE_GUILD permission. */
|
||||
get_embed: () => {
|
||||
// TODO: check if the bot has the MANAGE_GUILD permission
|
||||
return client.discordRequestManager.get(endpoints.GUILD_EMBED(data.id));
|
||||
return client.discordRequestManager.get(endpoints.GUILD_EMBED(data.id))
|
||||
},
|
||||
/** Modify a guild embed object for the guild. Requires the MANAGE_GUILD permission. */
|
||||
edit_embed: (enabled: boolean, channel_id?: string | null) => {
|
||||
// TODO: Requires the MANAGE_GUILD permission.
|
||||
return client.discordRequestManager.patch(
|
||||
endpoints.GUILD_EMBED(data.id),
|
||||
{ enabled, channel_id }
|
||||
);
|
||||
return client.discordRequestManager.patch(endpoints.GUILD_EMBED(data.id), { enabled, channel_id })
|
||||
},
|
||||
/** Returns the code and uses of the vanity url for this server if it is enabled. Requires the MANAGE_GUILD permission. */
|
||||
get_vanity_url: () => {
|
||||
return client.discordRequestManager.get(endpoints.GUILD_VANITY_URL(data.id));
|
||||
return client.discordRequestManager.get(endpoints.GUILD_VANITY_URL(data.id))
|
||||
},
|
||||
/** Returns a list of integrations for the guild. Requires the MANAGE_GUILD permission. */
|
||||
get_integrations: () => {
|
||||
// TODO: requires the MANAGE_GUILD permission
|
||||
return client.discordRequestManager.get(endpoints.GUILD_INTEGRATIONS(data.id));
|
||||
return client.discordRequestManager.get(endpoints.GUILD_INTEGRATIONS(data.id))
|
||||
},
|
||||
/** Modify the behavior and settings of an integration object for the guild. Requires the MANAGE_GUILD permission. */
|
||||
edit_integration: (id: string, options: Edit_Integration_Options) => {
|
||||
// TODO: requires the MANAGE_GUILD permission
|
||||
return client.discordRequestManager.patch(
|
||||
endpoints.GUILD_INTEGRATION(data.id, id),
|
||||
options
|
||||
);
|
||||
return client.discordRequestManager.patch(endpoints.GUILD_INTEGRATION(data.id, id), options)
|
||||
},
|
||||
/** Delete the attached integration object for the guild with this id. Requires MANAGE_GUILD permission. */
|
||||
delete_integration: (id: string) => {
|
||||
// TODO: requires the MANAGE_GUILD permission
|
||||
return client.discordRequestManager.delete(
|
||||
endpoints.GUILD_INTEGRATION(data.id, id)
|
||||
);
|
||||
return client.discordRequestManager.delete(endpoints.GUILD_INTEGRATION(data.id, id))
|
||||
},
|
||||
/** Sync an integration. Requires teh MANAGE_GUILD permission. */
|
||||
sync_integration: (id: string) => {
|
||||
// TODO: requires MANAGE_GUILD
|
||||
return client.discordRequestManager.post(
|
||||
endpoints.GUILD_INTEGRATION_SYNC(data.id, id)
|
||||
);
|
||||
return client.discordRequestManager.post(endpoints.GUILD_INTEGRATION_SYNC(data.id, id))
|
||||
},
|
||||
/** Returns a list of ban objects for the users banned from this guild. Requires the BAN_MEMBERS permission. */
|
||||
get_bans: () => {
|
||||
// TODO: requires the BAN_MEMBERS permission
|
||||
return client.discordRequestManager.get(endpoints.GUILD_BANS(data.id));
|
||||
return client.discordRequestManager.get(endpoints.GUILD_BANS(data.id))
|
||||
},
|
||||
/** Ban a user from the guild and optionally delete previous messages sent by the user. Requires teh BAN_MEMBERS permission. */
|
||||
ban: (id: string, options: BanOptions) => {
|
||||
// TODO: requires the BAN_MEMBERS permission
|
||||
return client.discordRequestManager.put(
|
||||
endpoints.GUILD_BAN(data.id, id),
|
||||
options
|
||||
);
|
||||
return client.discordRequestManager.put(endpoints.GUILD_BAN(data.id, id), options)
|
||||
},
|
||||
/** Remove the ban for a user. REquires BAN_MEMBERS permission */
|
||||
unban: (id: string) => {
|
||||
// TODO: requires the BAN_MEMBERS permission
|
||||
return client.discordRequestManager.delete(endpoints.GUILD_BAN(data.id, id));
|
||||
return client.discordRequestManager.delete(endpoints.GUILD_BAN(data.id, id))
|
||||
},
|
||||
/** Check whether a member has certain permissions in this channel. */
|
||||
channel_has_permissions: (
|
||||
channel_id: string,
|
||||
member_id: string,
|
||||
permissions: Permission[]
|
||||
) => {
|
||||
if (member_id === data.owner_id) return true;
|
||||
channel_has_permissions: (channel_id: string, member_id: string, permissions: Permission[]) => {
|
||||
if (member_id === data.owner_id) return true
|
||||
|
||||
const member = guild.members.get(member_id);
|
||||
const member = guild.members.get(member_id)
|
||||
if (!member) {
|
||||
throw "Invalid member id provided. This member was not found in the cache. Please fetch them with getMember on guild.";
|
||||
throw 'Invalid member id provided. This member was not found in the cache. Please fetch them with getMember on guild.'
|
||||
}
|
||||
|
||||
const channel = guild.channels.get(channel_id);
|
||||
const channel = guild.channels.get(channel_id)
|
||||
if (!channel) {
|
||||
throw "Invalid channel id provided. This channel was not found in the cache.";
|
||||
throw 'Invalid channel id provided. This channel was not found in the cache.'
|
||||
}
|
||||
|
||||
let permissionBits = member.roles().reduce((bits, role_id) => {
|
||||
const role = guild.roles.get(role_id);
|
||||
if (!role) return bits;
|
||||
const role = guild.roles.get(role_id)
|
||||
if (!role) return bits
|
||||
|
||||
bits |= role.permissions();
|
||||
|
||||
return bits;
|
||||
}, 0);
|
||||
bits |= role.permissions()
|
||||
|
||||
return bits
|
||||
}, 0)
|
||||
|
||||
data.permission_overwrites?.forEach(overwrite => {
|
||||
permissionBits = (permissionBits & ~overwrite.deny) | overwrite.allow;
|
||||
});
|
||||
permissionBits = (permissionBits & ~overwrite.deny) | overwrite.allow
|
||||
})
|
||||
|
||||
if (permissionBits & Permissions.ADMINISTRATOR) return true
|
||||
|
||||
return permissions.every(
|
||||
permission => permissionBits & Permissions[permission]
|
||||
);
|
||||
return permissions.every(permission => permissionBits & Permissions[permission])
|
||||
},
|
||||
/** Modify a guilds settings. Requires the MANAGE_GUILD permission. */
|
||||
edit: (options: Guild_Edit_Options) => {
|
||||
// TODO: requires the MANAGE_GUILD permission
|
||||
return client.discordRequestManager.patch(endpoints.GUILD(data.id), options);
|
||||
return client.discordRequestManager.patch(endpoints.GUILD(data.id), options)
|
||||
},
|
||||
/** Get all the invites for this guild. Requires MANAGE_GUILD permission */
|
||||
get_invites: () => {
|
||||
// TODO: requires MANAGE_GUILD permission
|
||||
return client.discordRequestManager.get(endpoints.GUILD_INVITES(data.id));
|
||||
return client.discordRequestManager.get(endpoints.GUILD_INVITES(data.id))
|
||||
},
|
||||
/** Leave a guild */
|
||||
leave: () => {
|
||||
return client.discordRequestManager.delete(endpoints.GUILD_LEAVE(data.id));
|
||||
return client.discordRequestManager.delete(endpoints.GUILD_LEAVE(data.id))
|
||||
},
|
||||
/** 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. */
|
||||
get_voice_regions: () => {
|
||||
return client.discordRequestManager.get(endpoints.GUILD_REGIONS(data.id));
|
||||
return client.discordRequestManager.get(endpoints.GUILD_REGIONS(data.id))
|
||||
},
|
||||
/** Returns a list of guild webhooks objects. Requires the MANAGE_WEBHOOKs permission. */
|
||||
get_webhooks: () => {
|
||||
// TODO: requires MANAGE_WEBHOOKS
|
||||
return client.discordRequestManager.get(endpoints.GUILD_WEBHOOKS(data.id));
|
||||
return client.discordRequestManager.get(endpoints.GUILD_WEBHOOKS(data.id))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
data.roles.forEach(r => guild.roles.set(r.id, create_role(r)));
|
||||
data.members.forEach(
|
||||
m => guild.members.set(m.user.id, create_member(m, data.id, data.roles, data.owner_id, client))
|
||||
);
|
||||
data.channels.forEach(
|
||||
c => guild.channels.set(c.id, create_channel(c, client))
|
||||
);
|
||||
return guild;
|
||||
};
|
||||
|
||||
return guild
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { UserPayload } from "./user.ts";
|
||||
import { ActivityPayload } from "./activity";
|
||||
import { StatusType } from "../types/discord";
|
||||
import { User_Payload } from "./user.ts";
|
||||
import { ActivityPayload } from "./activity.ts";
|
||||
import { StatusType } from "../types/discord.ts";
|
||||
|
||||
export type PresencePayload = Partial<{
|
||||
/** The user presence is being updated for */
|
||||
user: UserPayload;
|
||||
user: User_Payload;
|
||||
|
||||
/** Roles this user is in */
|
||||
roles: string[];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Raw_Overwrite, Overwrite } from './guild'
|
||||
import { create_channel } from '../structures/channel'
|
||||
import { Raw_Overwrite, Overwrite } from './guild.ts'
|
||||
import { Embed } from './message.ts'
|
||||
|
||||
export interface Base_Channel_Create {
|
||||
/** The id of this channel */
|
||||
@@ -69,7 +69,7 @@ export interface MessageContent {
|
||||
/** The contents of the file being sent */
|
||||
file?: File_Content
|
||||
/** Embed object */
|
||||
embed?: Embed_Object
|
||||
embed?: Embed
|
||||
/** JSON encoded body of any additional request fields. */
|
||||
payload_json?: string
|
||||
}
|
||||
@@ -105,4 +105,3 @@ export interface Create_Invite_Options {
|
||||
unique: boolean
|
||||
}
|
||||
|
||||
export type Channel = ReturnType<typeof create_channel>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Emoji, StatusType } from './discord'
|
||||
import { User } from '../structures/user'
|
||||
import { Permission } from './permission'
|
||||
import { Role_Data } from './role'
|
||||
import { Member_Create_Payload } from './member'
|
||||
import { Activity } from './message'
|
||||
import { ClientStatusPayload } from '../structures/presence'
|
||||
import { Channel_Create_Options } from './channel'
|
||||
import { Emoji, StatusType } from './discord.ts'
|
||||
import { User } from '../structures/user.ts'
|
||||
import { Permission } from './permission.ts'
|
||||
import { Role_Data } from './role.ts'
|
||||
import { Member_Create_Payload } from './member.ts'
|
||||
import { Activity } from './message.ts'
|
||||
import { ClientStatusPayload } from '../structures/presence.ts'
|
||||
import { Channel_Create_Options } from './channel.ts'
|
||||
|
||||
export interface Create_Guild_Payload {
|
||||
/** The guild id */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Member } from '../structures/member'
|
||||
import { ChannelType, User_Data } from './guild'
|
||||
import { User } from '../structures/user'
|
||||
import { ChannelType, User_Data } from './guild.ts'
|
||||
import { User } from '../structures/user.ts'
|
||||
import { Member } from './member.ts'
|
||||
|
||||
export interface MentionedUser extends User {
|
||||
member: Member
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { create_guild } from "../structures/guild";
|
||||
import { create_guild } from "../structures/guild.ts";
|
||||
import { create_channel } from "../structures/channel.ts";
|
||||
|
||||
export type Guild = ReturnType<typeof create_guild>;
|
||||
export type Channel = ReturnType<typeof create_channel>
|
||||
|
||||
Reference in New Issue
Block a user