devland.js
Advanced tools
Comparing version 1.0.26 to 1.1.0
19
index.js
@@ -30,2 +30,12 @@ const Client = require('./structures/client/client') | ||
const Role = require('./structures/models/Role') | ||
const AuditLogs = require('./structures/models/AuditLogs') | ||
const Log = require('./structures/models/Log') | ||
const Invite = require('./structures/models/Invite') | ||
const Webhook = require('./structures/models/Webhook') | ||
const Integration = require('./structures/models/Integration') | ||
const VoiceState = require('./structures/models/VoiceState') | ||
const Interaction = require('./structures/models/Interaction') | ||
const Modal = require('./structures/models/Modal') | ||
const Collector = require('./structures/models/Collector') | ||
const { __exportStar } = require('tslib'); | ||
module.exports = { | ||
@@ -61,2 +71,11 @@ Client, | ||
Role, | ||
AuditLogs, | ||
Log, | ||
Invite, | ||
Webhook, | ||
Integration, | ||
VoiceState, | ||
Interaction, | ||
Modal, | ||
Collector, | ||
} |
@@ -6,6 +6,7 @@ { | ||
"phin": "^3.6.1", | ||
"tslib": "^2.4.1", | ||
"ws": "^8.5.0" | ||
}, | ||
"name": "devland.js", | ||
"version": "1.0.26", | ||
"version": "1.1.0", | ||
"description": "A powerful API wrapper for the Discord API designed for modern bots", | ||
@@ -19,3 +20,3 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "git+https://github.com/Jeotique/Luma.js-V2.git" | ||
"url": "git+https://github.com/Jeotique/devland.js.git" | ||
}, | ||
@@ -38,3 +39,5 @@ "keywords": [ | ||
"eris.js", | ||
"erisjs" | ||
"erisjs", | ||
"oceanic", | ||
"oceanic.js" | ||
], | ||
@@ -44,3 +47,3 @@ "author": "Jeotique", | ||
"bugs": { | ||
"url": "https://github.com/Jeotique/Luma.js-V2/issues" | ||
"url": "https://github.com/Jeotique/devland.js/issues" | ||
}, | ||
@@ -51,3 +54,3 @@ "contributors": [ | ||
], | ||
"homepage": "https://github.com/Jeotique/Luma.js-V2#readme" | ||
"homepage": "https://github.com/Jeotique/devland.js#readme" | ||
} |
@@ -35,17 +35,10 @@ const { EventEmitter } = require('events') | ||
* @property {number} messagesLifeTime | ||
* @property {boolean} messagesLifeTimeResetAfterEvents | ||
* @property {number} guildsLifeTime | ||
* @property {boolean} guildsLifeTimeResetAfterEvents | ||
* @property {number} channelsLifeTime | ||
* @property {boolean} channelsLifeTimeResetAfterEvents | ||
* @property {number} usersLifeTime | ||
* @property {boolean} usersLifeTimeResetAfterEvents | ||
* @property {number} channelsLifeTime | ||
* @property {boolean} channelsLifeTimeResetAfterEvents | ||
* @property {number} threadsLifeTime | ||
* @property {boolean} threadsLifeTimeResetAfterEvents | ||
* @property {number} membersLifeTime | ||
* @property {boolean} membersLifeTimeResetAfterEvents | ||
* @property {number} rolesLifeTime | ||
* @property {boolean} rolesLifeTimeResetAfterEvents | ||
* @property {number} invitesLifeTime | ||
*/ | ||
@@ -105,2 +98,3 @@ /** | ||
WEBHOOKS_TOKEN: (webhookID, webhookToken) => { return DiscordAPI + '/webhooks/' + webhookID + '/' + webhookToken; }, | ||
WEBHOOKS_MESSAGE: (webhookID, webhookToken, messageID) => { return DiscordAPI + '/webhooks/' + webhookID + '/' + webhookToken + '/messages/' + messageID; }, | ||
BULD_DELETE: (channelID) => { return `${this._ENDPOINTS.CHANNEL(channelID)}/messages/bulk-delete`; }, | ||
@@ -114,2 +108,7 @@ TYPING: (channelID) => { return `${this._ENDPOINTS.CHANNEL(channelID)}/typing`; }, | ||
STAGE: () => { return `${DiscordAPI}/stage-instances`; }, | ||
PRUNE: (serverID) => { return `${this._ENDPOINTS.SERVERS(serverID)}/prune`; }, | ||
SERVER_INVITES: (serverID) => { return `${this._ENDPOINTS.SERVERS(serverID)}/invites`; }, | ||
INTEGRATIONS: (serverID, integrationID) => { return `${this._ENDPOINTS.SERVERS(serverID)}/integrations${integrationID?`/${integrationID}`:``}`; }, | ||
INTERACTIONS: (interactionID, interactionToken) => { return DiscordAPI + '/interactions/' + interactionID + '/' + interactionToken + '/callback'; }, | ||
INTERACTIONS_MESSAGE: (interactionID, interactionToken) => { return DiscordAPI + '/interactions/' + interactionID + '/' + interactionToken; }, | ||
} | ||
@@ -175,2 +174,6 @@ | ||
} | ||
if (this.options.invitesLifeTime > 0 && !this.options.guildsLifeTime) { | ||
this.options.invitesLifeTime = null | ||
process.emitWarning("The guilds cache must be enabled if you want to use the invites cache") | ||
} | ||
this.rest = new RESTHandler(this) | ||
@@ -223,2 +226,10 @@ this.user = new Models.ClientUser(this) | ||
this.dmChannels = new Store() | ||
/** | ||
* @private | ||
*/ | ||
this.collectorCache = {} | ||
/** | ||
* @private | ||
*/ | ||
this.deletedmessages = new Store() | ||
if (this.options && this.options.connect == false) { | ||
@@ -225,0 +236,0 @@ return this; |
@@ -17,3 +17,3 @@ const Client = require('../../client/client') | ||
} else { | ||
if(!guild instanceof Guild) guild = new Guild(client, guild) | ||
if(!(guild instanceof Guild)) guild = new Guild(client, guild) | ||
if (data.type === 0) { // text channel | ||
@@ -20,0 +20,0 @@ let text = new TextChannel(client, guild, data) |
@@ -17,4 +17,7 @@ const Client = require('../../client/client') | ||
} else { | ||
client.messages.map(msg => { | ||
if(msg.channelId === data.id) client.messages.delete(msg.id) | ||
}) | ||
if (typeof client.options.channelsLifeTime === "number" && client.options.channelsLifeTime > 0) { | ||
if(!guild instanceof Guild) guild = new Guild(client, guild) | ||
if(!(guild instanceof Guild)) guild = new Guild(client, guild) | ||
if (data.type === 0) { // text channel | ||
@@ -21,0 +24,0 @@ let channel = client.textChannels.get(data.id) |
@@ -16,3 +16,3 @@ const Client = require('../../client/client') | ||
} else { | ||
if(!guild instanceof Guild) guild = new Guild(client, guild) | ||
if(!(guild instanceof Guild)) guild = new Guild(client, guild) | ||
let oldChannel = { error: "Enable the channels cache to get the old channel data", id: data.id, data_is_available: false } | ||
@@ -19,0 +19,0 @@ if (data.type === 0) { // text channel |
@@ -13,3 +13,3 @@ const Client = require('../../client/client') | ||
let guild = client.guilds.get(data.guild_id) || await client.rest.get(client._ENDPOINTS.SERVERS(data.guild_id)).catch(e => { }) | ||
if (!guild instanceof Guild) guild = new Guild(client, guild) | ||
if (!(guild instanceof Guild)) guild = new Guild(client, guild) | ||
let member = new Member(client, guild, data) | ||
@@ -19,5 +19,8 @@ let oldMember = guild.members.get(member.id) | ||
client.emit('memberUpdate', oldMember, member) | ||
member.cachedAt = Date.now() | ||
member.expireAt = Date.now() + client.options.membersLifeTime | ||
guild.members.set(member.id, member) | ||
if (typeof client.options.membersLifeTime === "number" && client.options.membersLifeTime > 0) { | ||
member.cachedAt = Date.now() | ||
member.expireAt = Date.now() + client.options.membersLifeTime | ||
guild.members.set(member.id, member) | ||
client.guilds.set(guild.id, guild) | ||
} | ||
} else { | ||
@@ -24,0 +27,0 @@ /** |
@@ -32,3 +32,3 @@ const Client = require('../../client/client') | ||
} else { | ||
if(!guild instanceof Guild) guild = new Guild(client, guild) | ||
if(!(guild instanceof Guild)) guild = new Guild(client, guild) | ||
let channel = await client.rest.get(client._ENDPOINTS.CHANNEL(data.channel_id)).catch(e => { }) | ||
@@ -35,0 +35,0 @@ if (!channel) return |
@@ -14,3 +14,3 @@ const Client = require('../../client/client') | ||
let guild = client.guilds.get(data.guild_id) || await client.rest.get(client._ENDPOINTS.SERVERS(data.guild_id)).catch(e => { }) | ||
if(guild && !guild instanceof Guild) guild = new Guild(client, guild) | ||
if(guild && !(guild instanceof Guild)) guild = new Guild(client, guild) | ||
if (!guild) { | ||
@@ -17,0 +17,0 @@ let channel = await client.rest.get(client._ENDPOINTS.CHANNEL(data.channel_id)).catch(e => { }) |
@@ -25,3 +25,3 @@ const Client = require('../../client/client') | ||
if (client.guilds.size < 1) { | ||
clearInverval(checkGuilds) | ||
clearInterval(checkGuilds) | ||
client.ready = true | ||
@@ -55,7 +55,15 @@ /** | ||
var o = setInterval(() => { | ||
if (typeof client.options.guildsLifeTime !== 'number') return clearInterval(o) | ||
if (client.options.guildsLifeTime < 1) return clearInverval(o) | ||
if (typeof client.options.rolesLifeTime !== 'number') return clearInterval(o) | ||
if (client.options.rolesLifeTime < 1) return clearInverval(o) | ||
client.cacheInverval = setInterval(() => { | ||
checkGuildsCache() | ||
checkRoleCache() | ||
checkMembersCache() | ||
checkUsersCache() | ||
checkMessagesCache() | ||
checkChannelsCache() | ||
}, 4000) | ||
async function checkRoleCache() { | ||
if (typeof client.options.guildsLifeTime !== 'number') return | ||
if (client.options.guildsLifeTime < 1) return | ||
if (typeof client.options.rolesLifeTime !== 'number') return | ||
if (client.options.rolesLifeTime < 1) return | ||
client.guilds.map(guild => { | ||
@@ -69,8 +77,8 @@ guild.roles.map(role => { | ||
}) | ||
}, 3000) | ||
var t = setInterval(() => { | ||
if (typeof client.options.guildsLifeTime !== 'number') return clearInterval(t) | ||
if (client.options.guildsLifeTime < 1) return clearInverval(t) | ||
if (typeof client.options.membersLifeTime !== 'number') return clearInterval(t) | ||
if (client.options.membersLifeTime < 1) return clearInverval(t) | ||
} | ||
async function checkMembersCache() { | ||
if (typeof client.options.guildsLifeTime !== 'number') return | ||
if (client.options.guildsLifeTime < 1) return | ||
if (typeof client.options.membersLifeTime !== 'number') return | ||
if (client.options.membersLifeTime < 1) return | ||
client.guilds.map(guild => { | ||
@@ -84,6 +92,6 @@ guild.members.map(member => { | ||
}) | ||
}, 3000) | ||
var w = setInterval(() => { | ||
if (typeof client.options.usersLifeTime !== 'number') return clearInterval(w) | ||
if (client.options.usersLifeTime < 1) return clearInverval(w) | ||
} | ||
async function checkUsersCache() { | ||
if (typeof client.options.usersLifeTime !== 'number') return | ||
if (client.options.usersLifeTime < 1) return | ||
client.users.map(user => { | ||
@@ -94,6 +102,6 @@ if (Date.now() < user.expireAt) return | ||
}) | ||
}, 3000) | ||
var y = setInterval(() => { | ||
if (typeof client.options.guildsLifeTime !== 'number') return clearInterval(y) | ||
if (client.options.guildsLifeTime < 1) return clearInverval(y) | ||
} | ||
async function checkGuildsCache() { | ||
if (typeof client.options.guildsLifeTime !== 'number') return | ||
if (client.options.guildsLifeTime < 1) return | ||
client.guilds.map(guild => { | ||
@@ -104,6 +112,6 @@ if (Date.now() < guild.expireAt) return | ||
}) | ||
}, 3000) | ||
var x = setInterval(() => { | ||
if (typeof client.options.messagesLifeTime !== 'number') return clearInterval(x) | ||
if (client.options.messagesLifeTime < 1) return clearInverval(x) | ||
} | ||
async function checkMessagesCache() { | ||
if (typeof client.options.messagesLifeTime !== 'number') return | ||
if (client.options.messagesLifeTime < 1) return | ||
client.messages.map(message => { | ||
@@ -114,6 +122,6 @@ if (Date.now() < message.expireAt) return | ||
}) | ||
}, 3000) | ||
var z = setInterval(() => { | ||
if (typeof client.options.channelsLifeTime !== 'number') return clearInterval(z) | ||
if (client.options.channelsLifeTime < 1) return clearInverval(z) | ||
} | ||
async function checkChannelsCache() { | ||
if (typeof client.options.channelsLifeTime !== 'number') return | ||
if (client.options.channelsLifeTime < 1) return | ||
client.textChannels.map(text => { | ||
@@ -154,4 +162,4 @@ if (Date.now() < text.expireAt) return | ||
}) | ||
}, 3000) | ||
} | ||
} | ||
} |
@@ -18,3 +18,3 @@ const Client = require('../../client/client') | ||
} else { | ||
if(!guild instanceof Guild) guild = new Guild(client, guild) | ||
if(!(guild instanceof Guild)) guild = new Guild(client, guild) | ||
let thread = new Thread(client, guild, data) | ||
@@ -21,0 +21,0 @@ /** |
@@ -18,3 +18,3 @@ const Client = require('../../client/client') | ||
} else { | ||
if(!guild instanceof Guild) guild = new Guild(client, guild) | ||
if(!(guild instanceof Guild)) guild = new Guild(client, guild) | ||
let thread = client.threadChannels.get(data.id) | ||
@@ -21,0 +21,0 @@ if(thread) thread.guild = guild |
@@ -18,3 +18,3 @@ const Client = require('../../client/client') | ||
} else { | ||
if(!guild instanceof Guild) guild = new Guild(client, guild) | ||
if(!(guild instanceof Guild)) guild = new Guild(client, guild) | ||
let thread = new Thread(client, guild, data) | ||
@@ -24,3 +24,3 @@ let oldThread = client.threadChannels.get(thread.id) | ||
/** | ||
* Emitted whenever a thread is deleted | ||
* Emitted whenever a thread is updated | ||
* @event client#threadUpdate | ||
@@ -27,0 +27,0 @@ * @param {Thread} oldThread |
@@ -41,4 +41,6 @@ const ws = require('ws'); | ||
presence: { | ||
activities: client.options.presence.activities, | ||
status: client.options.presence.status, | ||
afk: client.options.presence.afk, | ||
since: client.options.presence.since, | ||
}, | ||
@@ -59,3 +61,5 @@ intents: client.options.intents | ||
let event = eventFiles.get(Events[d.t]) | ||
try{ | ||
event.run(client, d) | ||
}catch(err){} | ||
break; | ||
@@ -62,0 +66,0 @@ } |
const Button = require("./Button") | ||
const ChannelSelect = require("./ChannelSelect") | ||
const MentionableSelect = require("./MentionableSelect") | ||
const Modal = require("./Modal") | ||
const RoleSelect = require("./RoleSelect") | ||
@@ -21,3 +22,4 @@ const StringSelect = require("./StringSelect") | ||
if(!comp.pack) { | ||
switch(comp.type) { | ||
if(comp.isModal) comp = new Modal(comp) | ||
else switch(comp.type) { | ||
case 2: comp = new Button(comp); break; | ||
@@ -24,0 +26,0 @@ case 3: comp = new StringSelect(comp); break; |
@@ -10,2 +10,3 @@ const Client = require('../client/client') | ||
const ForumTag = require('./ForumTag') | ||
const Webhook = require('./Webhook') | ||
module.exports = class AnnouncementChannel { | ||
@@ -43,3 +44,3 @@ /** | ||
this.data_is_available = true | ||
data.permission_overwrites.map(perm => { | ||
data.permission_overwrites?.map(perm => { | ||
this.permission_overwrites.push({ | ||
@@ -100,3 +101,3 @@ id: perm.id, | ||
}) | ||
this.client.rest.post(this.client._ENDPOINTS.MESSAGES(this.channelId), data).then(messageData => { | ||
this.client.rest.post(this.client._ENDPOINTS.MESSAGES(this.id), data).then(messageData => { | ||
return resolve(new Message(this.client, this.guild, this, messageData)) | ||
@@ -461,2 +462,85 @@ }).catch(e => { | ||
} | ||
async createWebhook(options = {}) { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof options !== "object") return reject(new TypeError("Create webhook options must be a object")) | ||
if (typeof options.name !== "string") return reject(new TypeError("Create webhook options name must be provided (string)")) | ||
if (options.name.length < 1 || options.name.length > 80) return reject(new TypeError("Create webhook options name must have a length between 1 and 80")) | ||
if (typeof options.reason !== "undefined" && typeof options.reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
this.client.rest.post(this.client._ENDPOINTS.CHANNEL_WEBHOOKS(this.id), options).then(res => { | ||
resolve(new Webhook(this.client, this.client.guilds.get(this.guildId) || this.guild, res)) | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async fetchWebhooks() { | ||
return new Promise(async (resolve, reject) => { | ||
this.client.rest.get(this.client._ENDPOINTS.CHANNEL_WEBHOOKS(this.id)).then(res => { | ||
let collect = new Store() | ||
res.map(web => collect.set(web.id, new Webhook(this.client, this.client.guilds.get(this.guildId) || this.guild, web))) | ||
resolve(collect) | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
createCollector(options = {}){ | ||
if(typeof options !== "object") throw new TypeError("You must provide options for the collector") | ||
if(typeof options.count !== "undefined"){ | ||
if(typeof options.count !== "number") throw new TypeError("The count must be a number") | ||
} | ||
if(typeof options.type !== "undefined"){ | ||
if(typeof options.type !== "string") throw new TypeError("The type must be a string") | ||
options.type = options.type.toLowerCase() | ||
if(!["message", "component"].includes(options.type)) throw new TypeError("Invalid collector type (message or component)") | ||
} | ||
if(typeof options.time !== "undefined"){ | ||
if(typeof options.time !== "number") throw new TypeError("The time must be a number") | ||
} | ||
if(typeof options.componentType !== "undefined"){ | ||
if(typeof options.componentType !== "number") throw new TypeError("The componentType must be a number") | ||
if(options.componentType < 1 || options.componentType > 8) throw new TypeError("Invalid componentType for the collector") | ||
} | ||
if(typeof options.filter !== "undefined"){ | ||
if(typeof options.filter !== "function") throw new TypeError("The filter must be a filter function for the collector, example : 'filter: (collected) => collected.author.id === message.author.id'") | ||
} | ||
let identifier = Date.now() | ||
this.client.collectorCache[identifier] = new Collector(this.client, this.client.guilds.get(this.guildId)||this.guild, null, this.channel, options) | ||
this.client.collectorCache[identifier]?.on('end', () => { | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
return this.client.collectorCache[identifier] | ||
} | ||
awaitMessages(options = {}) { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof options !== "object") throw new TypeError("You must provide options for the collector") | ||
if (typeof options.count !== "undefined") { | ||
if (typeof options.count !== "number") throw new TypeError("The count must be a number") | ||
} | ||
options.type = "await_message" | ||
if (typeof options.time !== "undefined") { | ||
if (typeof options.time !== "number") throw new TypeError("The time must be a number") | ||
} | ||
if (typeof options.componentType !== "undefined") { | ||
if (typeof options.componentType !== "number") throw new TypeError("The componentType must be a number") | ||
if (options.componentType < 1 || options.componentType > 8) throw new TypeError("Invalid componentType for the collector") | ||
} | ||
if (typeof options.filter !== "undefined") { | ||
if (typeof options.filter !== "function") throw new TypeError("The filter must be a filter function for the collector, example : 'filter: (collected) => collected.author.id === message.author.id'") | ||
} | ||
let identifier = Date.now() | ||
this.client.collectorCache[identifier] = new Collector(this.client, this.client.guilds.get(this.guildId) || this.guild, null, this, options) | ||
this.client.collectorCache[identifier]?.on('end', () => { | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
this.client.collectorCache[identifier]?.on('collected', collected => { | ||
resolve(collected) | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
}) | ||
} | ||
} |
const { parseEmoji } = require("../util") | ||
const Emoji = require('./Emoji') | ||
module.exports = class Button { | ||
@@ -4,0 +4,0 @@ /** |
@@ -38,3 +38,3 @@ const Client = require('../client/client') | ||
this.data_is_available = true | ||
data.permission_overwrites.map(perm => { | ||
data.permission_overwrites?.map(perm => { | ||
this.permission_overwrites.push({ | ||
@@ -41,0 +41,0 @@ id: perm.id, |
const { parseEmoji } = require("../util") | ||
const Emoji = require('./Emoji') | ||
module.exports = class ChannelSelect { | ||
@@ -31,9 +31,9 @@ /** | ||
else if(this.channelTypes.find(type => type < 0 || type > 15)) throw new TypeError("invalid channel type provided") | ||
if(this.channelTypes.length > 0) this.channel_types = this.channelTypes | ||
if(this.channelTypes && this.channelTypes.length > 0) this.channel_types = this.channelTypes | ||
else if(this.channel_types.length < 1) this.channel_types = undefined | ||
if(this.channel_types.find(type => type > 0 || type > 15)) throw new TypeError("invalid channel type provided") | ||
if(this.channel_types && this.channel_types.find(type => type > 0 || type > 15)) throw new TypeError("invalid channel type provided") | ||
return { | ||
type: 8, | ||
placeholder: this.placeholder, | ||
max_values: this.max_values || 1, | ||
max_values: this.max_values || this.min_values ? this.min_values : 1, | ||
min_values: this.min_values || 0, | ||
@@ -40,0 +40,0 @@ custom_id: this.custom_id || this.customId, |
const Client = require('../client/client') | ||
module.exports = class ClientUser { | ||
constructor(client, data = {}){ | ||
/** | ||
* @private | ||
*/ | ||
/** | ||
* The client that instantiated this | ||
* @name Base#client | ||
* @type {Client} | ||
* @readonly | ||
constructor(client, data = {}) { | ||
/** | ||
* @private | ||
*/ | ||
/** | ||
* The client that instantiated this | ||
* @name Base#client | ||
* @type {Client} | ||
* @readonly | ||
*/ | ||
Object.defineProperty(this, 'client', { value: client }) | ||
/** | ||
* @type {boolean} | ||
*/ | ||
this.verified = data.verified | ||
/** | ||
* @type {string} | ||
*/ | ||
this.username = data.username | ||
/** | ||
* @type {boolean} | ||
*/ | ||
this.mfa_enabled = data.mfa_enabled | ||
/** | ||
* @type {string} | ||
*/ | ||
this.id = data.id | ||
/** | ||
* @type {number} | ||
*/ | ||
this.flags = data.flags | ||
/** | ||
* @type {string} | ||
*/ | ||
this.email = data.email | ||
/** | ||
* @type {string} | ||
*/ | ||
this.discriminator = data.discriminator | ||
/** | ||
* @type {boolean} | ||
*/ | ||
this.bot = data.bot | ||
/** | ||
* @type {string} | ||
*/ | ||
this.avatar = data.avatar | ||
/** | ||
* @type {string} | ||
*/ | ||
this.tag = data.tag | ||
/** | ||
* @type {boolean} | ||
*/ | ||
this.verified = data.verified | ||
/** | ||
* @type {string} | ||
*/ | ||
this.username = data.username | ||
/** | ||
* @type {boolean} | ||
*/ | ||
this.mfa_enabled = data.mfa_enabled | ||
/** | ||
* @type {string} | ||
*/ | ||
this.id = data.id | ||
/** | ||
* @type {number} | ||
*/ | ||
this.flags = data.flags | ||
/** | ||
* @type {string} | ||
*/ | ||
this.email = data.email | ||
/** | ||
* @type {string} | ||
*/ | ||
this.discriminator = data.discriminator | ||
/** | ||
* @type {boolean} | ||
*/ | ||
this.bot = data.bot | ||
/** | ||
* @type {string} | ||
*/ | ||
this.avatar = data.avatar | ||
/** | ||
* @type {string} | ||
*/ | ||
this.tag = data.tag | ||
} | ||
setPresence(presence) { | ||
if (typeof presence !== "object") throw new TypeError("The presence data must be a object") | ||
let packed = this._parse(presence) | ||
this._patch(packed) | ||
this.client.ws.socket.send(JSON.stringify({ op: 3, d: packed })) | ||
this.client.options.presence = packed | ||
} | ||
setName(name) { | ||
return new Promise(async (resolve, reject) => { | ||
if(typeof name !== "string") return reject(new TypeError("Invalid name")) | ||
this.client.rest.patch(this.client._ENDPOINTS.ME, { | ||
username: name | ||
}).then(res => { | ||
let newClientUser = new ClientUser(this.client, res) | ||
resolve(newClientUser) | ||
Object.keys(newClientUser).map(k => this[k] = newClientUser[k]) | ||
}).catch(e=>{ | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
setAvatar(avatar){ | ||
return new Promise(async(resolve, reject) => { | ||
if(typeof avatar === "undefined") return reject(new TypeError("You need to provid me a avatar")) | ||
this.client.rest.patch(this.client._ENDPOINTS.ME, { | ||
avatar: avatar | ||
}).then(res => { | ||
let newClientUser = new ClientUser(this.client, res) | ||
resolve(newClientUser) | ||
Object.keys(newClientUser).map(k => this[k] = newClientUser[k]) | ||
}).catch(e=>{ | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
/** | ||
* Parses presence data into a packet ready to be sent to Discord | ||
* @param {PresenceData} presence The data to parse | ||
* @returns {APIPresence} | ||
* @private | ||
*/ | ||
_parse({ status, since, afk, activities }) { | ||
const data = { | ||
activities: [], | ||
afk: typeof afk === 'boolean' ? afk : false, | ||
since: typeof since === 'number' && !Number.isNaN(since) ? since : null, | ||
status: status ?? this.status, | ||
}; | ||
if (activities?.length) { | ||
for (const [i, activity] of activities.entries()) { | ||
if (typeof activity.name !== 'string') { | ||
throw new Error(`activities[${i}].name`, 'string'); | ||
} | ||
activity.type ??= 0; | ||
data.activities.push({ | ||
type: activity.type, | ||
name: activity.name, | ||
url: activity.url, | ||
}); | ||
} | ||
} else if (!activities && (status || afk || since) && this.activities.length) { | ||
data.activities.push( | ||
...this.activities.map(a => ({ | ||
name: a.name, | ||
type: a.type, | ||
url: a.url ?? undefined, | ||
})), | ||
); | ||
} | ||
return data; | ||
} | ||
_patch(data) { | ||
if ('status' in data) { | ||
/** | ||
* The status of this presence | ||
* @type {PresenceStatus} | ||
*/ | ||
this.status = data.status; | ||
} else { | ||
this.status ??= 'offline'; | ||
} | ||
if ('activities' in data) { | ||
/** | ||
* The activities of this presence | ||
* @type {Activity[]} | ||
*/ | ||
this.activities = data.activities; | ||
} else { | ||
this.activities ??= []; | ||
} | ||
if ('client_status' in data) { | ||
/** | ||
* The devices this presence is on | ||
* @type {?Object} | ||
* @property {?ClientPresenceStatus} web The current presence in the web application | ||
* @property {?ClientPresenceStatus} mobile The current presence in the mobile application | ||
* @property {?ClientPresenceStatus} desktop The current presence in the desktop application | ||
*/ | ||
this.clientStatus = data.client_status; | ||
} else { | ||
this.clientStatus ??= null; | ||
} | ||
return this; | ||
} | ||
} |
@@ -82,3 +82,3 @@ const Client = require('../client/client') | ||
}) | ||
this.client.rest.post(this.client._ENDPOINTS.MESSAGES(this.channelId), data).then(messageData => { | ||
this.client.rest.post(this.client._ENDPOINTS.MESSAGES(this.id), data).then(messageData => { | ||
return resolve(new Message(this.client, this.guild, this, messageData)) | ||
@@ -226,2 +226,59 @@ }).catch(e => { | ||
} | ||
createCollector(options = {}){ | ||
if(typeof options !== "object") throw new TypeError("You must provide options for the collector") | ||
if(typeof options.count !== "undefined"){ | ||
if(typeof options.count !== "number") throw new TypeError("The count must be a number") | ||
} | ||
if(typeof options.type !== "undefined"){ | ||
if(typeof options.type !== "string") throw new TypeError("The type must be a string") | ||
options.type = options.type.toLowerCase() | ||
if(!["message", "component"].includes(options.type)) throw new TypeError("Invalid collector type (message or component)") | ||
} | ||
if(typeof options.time !== "undefined"){ | ||
if(typeof options.time !== "number") throw new TypeError("The time must be a number") | ||
} | ||
if(typeof options.componentType !== "undefined"){ | ||
if(typeof options.componentType !== "number") throw new TypeError("The componentType must be a number") | ||
if(options.componentType < 1 || options.componentType > 8) throw new TypeError("Invalid componentType for the collector") | ||
} | ||
if(typeof options.filter !== "undefined"){ | ||
if(typeof options.filter !== "function") throw new TypeError("The filter must be a filter function for the collector, example : 'filter: (collected) => collected.author.id === message.author.id'") | ||
} | ||
let identifier = Date.now() | ||
this.client.collectorCache[identifier] = new Collector(this.client, this.client.guilds.get(this.guildId)||this.guild, null, this.channel, options) | ||
this.client.collectorCache[identifier]?.on('end', () => { | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
return this.client.collectorCache[identifier] | ||
} | ||
awaitMessages(options = {}) { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof options !== "object") throw new TypeError("You must provide options for the collector") | ||
if (typeof options.count !== "undefined") { | ||
if (typeof options.count !== "number") throw new TypeError("The count must be a number") | ||
} | ||
options.type = "await_message" | ||
if (typeof options.time !== "undefined") { | ||
if (typeof options.time !== "number") throw new TypeError("The time must be a number") | ||
} | ||
if (typeof options.componentType !== "undefined") { | ||
if (typeof options.componentType !== "number") throw new TypeError("The componentType must be a number") | ||
if (options.componentType < 1 || options.componentType > 8) throw new TypeError("Invalid componentType for the collector") | ||
} | ||
if (typeof options.filter !== "undefined") { | ||
if (typeof options.filter !== "function") throw new TypeError("The filter must be a filter function for the collector, example : 'filter: (collected) => collected.author.id === message.author.id'") | ||
} | ||
let identifier = Date.now() | ||
this.client.collectorCache[identifier] = new Collector(this.client, this.client.guilds.get(this.guildId) || this.guild, null, this, options) | ||
this.client.collectorCache[identifier]?.on('end', () => { | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
this.client.collectorCache[identifier]?.on('collected', collected => { | ||
resolve(collected) | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
}) | ||
} | ||
} |
const Client = require('../client/client') | ||
const Guild = require('./Guild') | ||
const Member = require('./Member') | ||
const User = require('./User') | ||
@@ -21,3 +22,3 @@ | ||
this.guild = guild | ||
this.guildId = guild.id | ||
this.guildId = guild?.id | ||
this.name = data.name | ||
@@ -30,3 +31,3 @@ this.id = data.id | ||
this.available = data.available | ||
this.user = new User(client, data.user) | ||
this.user = data.user ? new User(client, data.user) : null | ||
} | ||
@@ -33,0 +34,0 @@ |
@@ -47,3 +47,3 @@ const Client = require('../client/client') | ||
this.data_is_available = true | ||
data.permission_overwrites.map(perm => { | ||
data.permission_overwrites?.map(perm => { | ||
this.permission_overwrites.push({ | ||
@@ -439,2 +439,59 @@ id: perm.id, | ||
} | ||
createCollector(options = {}){ | ||
if(typeof options !== "object") throw new TypeError("You must provide options for the collector") | ||
if(typeof options.count !== "undefined"){ | ||
if(typeof options.count !== "number") throw new TypeError("The count must be a number") | ||
} | ||
if(typeof options.type !== "undefined"){ | ||
if(typeof options.type !== "string") throw new TypeError("The type must be a string") | ||
options.type = options.type.toLowerCase() | ||
if(!["message", "component"].includes(options.type)) throw new TypeError("Invalid collector type (message or component)") | ||
} | ||
if(typeof options.time !== "undefined"){ | ||
if(typeof options.time !== "number") throw new TypeError("The time must be a number") | ||
} | ||
if(typeof options.componentType !== "undefined"){ | ||
if(typeof options.componentType !== "number") throw new TypeError("The componentType must be a number") | ||
if(options.componentType < 1 || options.componentType > 8) throw new TypeError("Invalid componentType for the collector") | ||
} | ||
if(typeof options.filter !== "undefined"){ | ||
if(typeof options.filter !== "function") throw new TypeError("The filter must be a filter function for the collector, example : 'filter: (collected) => collected.author.id === message.author.id'") | ||
} | ||
let identifier = Date.now() | ||
this.client.collectorCache[identifier] = new Collector(this.client, this.client.guilds.get(this.guildId)||this.guild, null, this.channel, options) | ||
this.client.collectorCache[identifier]?.on('end', () => { | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
return this.client.collectorCache[identifier] | ||
} | ||
awaitMessages(options = {}) { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof options !== "object") throw new TypeError("You must provide options for the collector") | ||
if (typeof options.count !== "undefined") { | ||
if (typeof options.count !== "number") throw new TypeError("The count must be a number") | ||
} | ||
options.type = "await_message" | ||
if (typeof options.time !== "undefined") { | ||
if (typeof options.time !== "number") throw new TypeError("The time must be a number") | ||
} | ||
if (typeof options.componentType !== "undefined") { | ||
if (typeof options.componentType !== "number") throw new TypeError("The componentType must be a number") | ||
if (options.componentType < 1 || options.componentType > 8) throw new TypeError("Invalid componentType for the collector") | ||
} | ||
if (typeof options.filter !== "undefined") { | ||
if (typeof options.filter !== "function") throw new TypeError("The filter must be a filter function for the collector, example : 'filter: (collected) => collected.author.id === message.author.id'") | ||
} | ||
let identifier = Date.now() | ||
this.client.collectorCache[identifier] = new Collector(this.client, this.client.guilds.get(this.guildId) || this.guild, null, this, options) | ||
this.client.collectorCache[identifier]?.on('end', () => { | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
this.client.collectorCache[identifier]?.on('collected', collected => { | ||
resolve(collected) | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
}) | ||
} | ||
} |
@@ -14,2 +14,9 @@ const Utils = require('../util') | ||
const Member = require('./Member') | ||
const Role = require('./Role') | ||
const Permissions = require('../util/Permissions/Permissions') | ||
const Constants = require('../util/Constants') | ||
const AuditLogs = require('./AuditLogs') | ||
const Ban = require('./Ban') | ||
const Invite = require('./Invite') | ||
const Integration = require('./Integration') | ||
@@ -59,3 +66,8 @@ module.exports = class Guild { | ||
this.roles = new Store() | ||
this.invites = new Store() | ||
this.data_is_available = true | ||
if(this.icon) { | ||
this.icon = `https://cdn.discordapp.com/icons/${this.id}/${this.icon}${this.icon.startsWith('a_') ? '.gif' : '.png'}?size=512` | ||
} | ||
} | ||
@@ -581,2 +593,270 @@ /** | ||
} | ||
async fetchRoles() { | ||
return new Promise(async (resolve, reject) => { | ||
this.client.rest.get(this.client._ENDPOINTS.ROLES(this.id)).then(res => { | ||
let collect = new Store() | ||
res.map(role => collect.set(role.id, new Role(this.client, this.client.guilds.get(this.id) || this, role))) | ||
resolve(collect) | ||
if (typeof this.client.options.rolesLifeTime === "number" && this.client.options.rolesLifeTime > 0) { | ||
collect.map(role => { | ||
role.cachedAt = Date.now() | ||
role.expireAt = Date.now() + this.client.options.rolesLifeTime | ||
this.roles.set(role.id, role) | ||
}) | ||
} | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async createRole(options = {}) { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof options !== "object") return reject(new TypeError("Create role options must be a object")) | ||
if (typeof options.name !== "undefined") { | ||
if (typeof options.name !== "string") return reject(new TypeError("Create role options name must be a string")) | ||
if (options.name.length > 100) return reject(new TypeError("Create role options must be less than 100 caracters")) | ||
} | ||
if (typeof options.permissions !== "undefined") { | ||
if (options.permissions instanceof Permissions) options.permissions = options.permissions.bitfield.toString() | ||
else options.permissions = new Permissions(options.permissions).bitfield.toString() | ||
} | ||
if (typeof options.color !== "undefined") { | ||
if (typeof options.color === "string") options.color = Utils.resolveColor(options.color) | ||
if (typeof options.color !== "number") return reject(new TypeError("Create role options color must be a number")) | ||
} | ||
if (typeof options.hoist !== "undefined") { | ||
if (typeof options.hoist !== "boolean") return reject(new TypeError("Create role options hoist must be a boolean")) | ||
} | ||
if (typeof options.unicode_emoji !== "undefined") { | ||
if (options.unicode_emoji instanceof Emoji) { | ||
options.unicode_emoji = options.unicode_emoji.pack() | ||
options.unicode_emoji = options.unicode_emoji.id ? `${options.unicode_emoji.name}` : `<${options.unicode_emoji.animated ? "a" : ""}:${options.unicode_emoji.name}:${options.unicode_emoji.id}>` | ||
} | ||
if (typeof options.unicode_emoji !== "string") return reject(new TypeError("Create role options unicode_emoji must be a string")) | ||
} | ||
if (typeof options.mentionable !== "undefined") { | ||
if (typeof options.mentionable !== "boolean") return reject(new TypeError("Create role options mentionable must be a boolean")) | ||
} | ||
if (typeof options.reason !== "undefined" && typeof options.reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
this.client.rest.post(this.client._ENDPOINTS.ROLES(this.id), options).then(res => { | ||
let role = new Role(this.client, this.client.guilds.get(this.id) || this, res) | ||
resolve(role) | ||
if (typeof this.client.options.rolesLifeTime === "number" && this.client.options.rolesLifeTime > 0) { | ||
role.cachedAt = Date.now() | ||
role.expireAt = Date.now() + this.client.options.rolesLifeTime | ||
this.roles.set(role.id, role) | ||
} | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
get premiumSubscriberRole() { | ||
return this.roles.find(role => role.tags?.premiumSubscriberRole) ?? null | ||
} | ||
get everyoneRole() { | ||
return this.roles.get(this.id) || null | ||
} | ||
get highestRole() { | ||
let all = this.roles.toJSON() | ||
return all.reduce((prev, role) => (role.comparePositions(prev) > 0 ? role : prev), this.roles.first()) | ||
} | ||
async fetchLogs(options = {}) { | ||
return new Promise(async (resolve, reject) => { | ||
if (options.type && typeof options.type === "number") options.type = Constants.logsTypeFromIndex[options.type] | ||
var query = { | ||
type: options.type ? Constants.logsType[options.type.toUpperCase()] : null, | ||
limit: options.limit || null, | ||
user_id: options.user_id || null | ||
} | ||
let typeQuery = query.type ? `action_type=${query.type}` : null | ||
let limitQuery = query.limit ? `&limit=${query.limit}` : null | ||
let userIdQuery = query.user_id ? `&user_id=${query.user_id}` : null | ||
this.client.rest.get(`${this.client._ENDPOINTS.SERVERS(this.id)}/audit-logs?${typeQuery ? typeQuery : ''}${limitQuery ? limitQuery : ''}${userIdQuery ? userIdQuery : ''}`).then(auditResult => { | ||
auditResult.guild = this | ||
let audit = new AuditLogs(this.client, auditResult) | ||
return resolve(audit) | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async leave() { | ||
return new Promise(async (resolve, reject) => { | ||
this.client.rest.delete(this.client._ENDPOINTS.SERVERS(this.id)).then(() => { | ||
resolve() | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async kickMember(user, reason) { | ||
return new Promise(async (resolve, reject) => { | ||
if (user instanceof User) user = user.id | ||
if (user instanceof Member) user = user.id | ||
if (typeof user !== "string") return reject(new TypeError("The user must be a valid User or Member instance or a valid Id")) | ||
if (typeof reason !== "undefined" && typeof reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
let member = this.members.get(user) || null | ||
this.client.rest.delete(this.client._ENDPOINTS.MEMBERS(this.id, user), { | ||
reason: reason | ||
}).then(() => { | ||
resolve(member) | ||
this.members.delete(user) | ||
if (typeof this.client.options.guildsLifeTime === "number" && this.client.options.guildsLifeTime > 0) { | ||
this.cachedAt = Date.now() | ||
this.expireAt = Date.now() + this.client.options.guildsLifeTime | ||
this.client.guilds.set(this.id, this) | ||
} | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async banMember(user, delete_message_seconds, reason) { | ||
return new Promise(async (resolve, reject) => { | ||
if (user instanceof User) user = user.id | ||
if (user instanceof Member) user = user.id | ||
if (typeof user !== "string") return reject(new TypeError("The user must be a valid User or Member instance or a valid Id")) | ||
if (typeof reason !== "undefined" && typeof reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
let member = this.members.get(user) || null | ||
if (typeof delete_message_seconds !== "undefined" && typeof delete_message_seconds !== "number") return reject(new TypeError("delete_message_seconds must be a number")) | ||
this.client.rest.put(this.client._ENDPOINTS.BANS(this.id, user), { | ||
delete_message_seconds: delete_message_seconds, | ||
reason: reason | ||
}).then(() => { | ||
resolve(member) | ||
this.members.delete(user) | ||
if (typeof this.client.options.guildsLifeTime === "number" && this.client.options.guildsLifeTime > 0) { | ||
this.cachedAt = Date.now() | ||
this.expireAt = Date.now() + this.client.options.guildsLifeTime | ||
this.client.guilds.set(this.id, this) | ||
} | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async unbanMember(user, reason) { | ||
return new Promise(async (resolve, reject) => { | ||
if (user instanceof User) user = user.id | ||
if (user instanceof Member) user = user.id | ||
if (typeof user !== "string") return reject(new TypeError("The user must be a valid User or Member instance or a valid Id")) | ||
if (typeof reason !== "undefined" && typeof reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
this.client.rest.delete(this.client._ENDPOINTS.BANS(this.id, user), { | ||
reason: reason | ||
}).then(() => { | ||
resolve(true) | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async fetchBans() { | ||
return new Promise(async (resolve, reject) => { | ||
this.client.rest.get(this.client._ENDPOINTS.BANS(this.id)).then(res => { | ||
let collect = new Store() | ||
res.map(b => collect.set(b.user.id, new Ban(this.client, b))) | ||
return resolve(collect) | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async fetchBan(user) { | ||
return new Promise(async (resolve, reject) => { | ||
if (user instanceof User) user = user.id | ||
if (user instanceof Member) user = user.id | ||
if (typeof user !== "string") return reject(new TypeError("The user must be a valid User or Member instance or a valid Id")) | ||
this.client.rest.get(this.client._ENDPOINTS.BANS(this.id, user)).then(res => { | ||
return resolve(new Ban(this.client, res)) | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async prune(options = {}) { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof options !== "object") return reject(new TypeError("Prune options must be a object")) | ||
if (typeof options.days !== "undefined") { | ||
if (typeof options.days !== "number") return reject(new TypeError("Prune options days must be a number")) | ||
if (options.days < 1 || options.days > 30) return reject(new TypeError("Prune options days must be between 1 and 30")) | ||
} | ||
if (typeof options.compute_prune_count !== "undefined") { | ||
if (typeof options.compute_prune_count !== "boolean") return reject(new TypeError("Prune options compute_prune_count must be a boolean")) | ||
} | ||
if (typeof options.include_roles !== "undefined") { | ||
if (typeof options.include_roles !== "object") return reject(new TypeError("Prune options include_roles must be a array")) | ||
let a = [] | ||
options.include_roles.map(role => { | ||
if (role instanceof Role) a.push(role.id) | ||
else if (typeof role === "string") a.push(role) | ||
else return reject(new TypeError("Prune options include_roles must contains valid role Id or Role instance")) | ||
}) | ||
options.include_roles = a | ||
} | ||
if (typeof options.reason !== "undefined" && typeof options.reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
this.client.rest.post(this.client._ENDPOINTS.PRUNE(this.id), options).then(() => { | ||
return resolve(this) | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async fetchInvites() { | ||
return new Promise(async (resolve, reject) => { | ||
this.client.rest.get(this.client._ENDPOINTS.SERVER_INVITES(this.id)).then(res => { | ||
let collect = new Store() | ||
res.map(invite => collect.set(invite.code, new Invite(this.client, this.client.guilds.get(this.id) || this, invite))) | ||
resolve(collect) | ||
if (typeof this.client.options.invitesLifeTime === "number" && this.client.options.invitesLifeTime > 0) { | ||
collect.map(invite => { | ||
invite.cachedAt = Date.now() | ||
invite.expireAt = Date.now() + this.client.options.invitesLifeTime | ||
this.invites.set(invite.code, invite) | ||
this.client.guilds.set(this.id, this) | ||
}) | ||
} | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async fetchWebhooks() { | ||
return new Promise(async (resolve, reject) => { | ||
this.client.rest.get(this.client._ENDPOINTS.SERVER_WEBHOOKS(this.id)).then(res => { | ||
let collect = new Store() | ||
res.map(web => collect.set(web.id, new Webhook(this.client, this.client.guilds.get(this.id) || this, web))) | ||
resolve(collect) | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async fetchIntegrations(){ | ||
return new Promise(async(resolve, reject) => { | ||
this.client.rest.get(this.client._ENDPOINTS.INTEGRATIONS(this.id)).then(res => { | ||
let collect = new Store() | ||
res.map(i => collect.set(i.id, new Integration(this.client, this.client.guilds.get(this.id)||this, i))) | ||
resolve(collect) | ||
}).catch(e=>{ | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
} |
@@ -35,3 +35,3 @@ const Permissions = require("../util/Permissions/Permissions") | ||
if (this.options && this.options.length > 25) throw new TypeError("Command max options length is 25") | ||
if (this.options && this.type !== 1) throw new TypeError("Command options are available for CHAT_INPUT type only") | ||
if (this.options && this.options.length > 0 && this.type !== 1) throw new TypeError("Command options are available for CHAT_INPUT type only") | ||
else if (typeof this.options !== "object") this.options = undefined | ||
@@ -38,0 +38,0 @@ if (this.default_member_permissions && this.default_member_permissions instanceof Permissions) { |
@@ -27,2 +27,11 @@ const ClientUser = require('./ClientUser') | ||
const Role = require('./Role') | ||
const AuditLogs = require('./AuditLogs') | ||
const Log = require('./Log') | ||
const Invite = require('./Invite') | ||
const Webhook = require('./Webhook') | ||
const Integration = require('./Integration') | ||
const VoiceState = require('./VoiceState') | ||
const Interaction = require('./Interaction') | ||
const Modal = require('./Modal') | ||
const Collector = require('./Collector') | ||
module.exports = { | ||
@@ -55,2 +64,11 @@ ClientUser, | ||
Role, | ||
AuditLogs, | ||
Log, | ||
Invite, | ||
Webhook, | ||
Integration, | ||
VoiceState, | ||
Interaction, | ||
Modal, | ||
Collector, | ||
} |
@@ -0,1 +1,2 @@ | ||
const Permissions = require('../util/Permissions/Permissions') | ||
const Guild = require('./Guild') | ||
@@ -27,5 +28,20 @@ const Role = require('./Role') | ||
this.data_is_available = true | ||
this.user = this.client.users.get(data.user.id) || new User(client, data.user) | ||
const User = require('./User') | ||
this.user = data.user ? this.client.users.get(data.user.id) || new User(client, data.user) : null | ||
this.permissions = (this.id === this.guild.ownerId) ? new Permissions("ADMINISTRATOR") : this.roles.length > 0 && this.guild.roles.size > 0 ? new Permissions(this.roles.map(role_id => { | ||
return this.guild.roles.get(role_id)?.permissions.toArray() | ||
})) : new Permissions() | ||
} | ||
async send(options) { | ||
return new Promise(async (resolve, reject) => { | ||
this.user.send(options).then(res => resolve(res)).catch(e => reject(new Error(e))) | ||
}) | ||
} | ||
hasPermissions(permission) { | ||
if (this.id === this.guild.ownerId) return true | ||
else return this.permissions.has(permission, true) | ||
} | ||
async edit(data = {}) { | ||
@@ -63,3 +79,3 @@ return new Promise(async (resolve, reject) => { | ||
if (typeof data.communication_disabled_until !== "undefined") { | ||
if (typeof data.communication_disabled_until !== "number") return reject(new TypeError("The communication disabled until state must be a number")) | ||
if (data.communication_disabled_until !== null && typeof data.communication_disabled_until !== "number") return reject(new TypeError("The communication disabled until state must be a number")) | ||
} | ||
@@ -151,2 +167,50 @@ if (typeof data.flags !== "undefined") { | ||
} | ||
async fetchRoles() { | ||
return new Promise(async (resolve, reject) => { | ||
let collect = new Store() | ||
if (this.guild.roles.size > 0) { | ||
this.roles.map(async (r_id, n) => { | ||
if (this.guild.roles.get(r_id)) collect.set(r_id, this.guild.roles.get(r_id)) | ||
else { | ||
let res = await this.client.rest.get(this.client._ENDPOINTS.MEMBER_ROLES(this.guildId, this.id, r_id)).catch(e => { }) | ||
if (res) { | ||
collect.set(r_id, new Role(this.client, this.client.guilds.get(this.guildId) || this.guild, res)) | ||
} | ||
} | ||
if (n + 1 === this.roles.length) return resolve(collect) | ||
}) | ||
} else { | ||
let res = await this.client.rest.get(this.client._ENDPOINTS.ROLES(this.guildId)).catch(e => { return reject(new Error(e)) }) | ||
res.filter(r => this.roles.includes(r.id)).map(role => { | ||
collect.set(role.id, new Role(this.client, this.client.guilds.get(this.guildId) || this.guild, role)) | ||
}) | ||
return resolve(collect) | ||
} | ||
}) | ||
} | ||
async kick(reason) { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof reason !== "undefined" && typeof reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
this.guild.kickMember(this.id, reason).then(member => { | ||
return resolve(member) | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async ban(delete_message_seconds, reason) { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof delete_message_seconds !== "undefined" && typeof delete_message_seconds !== "number") return reject(new TypeError("delete_message_seconds must be a number")) | ||
if (typeof reason !== "undefined" && typeof reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
this.guild.banMember(this.id, delete_message_seconds, reason).then(member => { | ||
return resolve(member) | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
} |
const { parseEmoji } = require("../util") | ||
const Emoji = require('./Emoji') | ||
module.exports = class MentionableSelect { | ||
@@ -30,3 +30,3 @@ /** | ||
placeholder: this.placeholder, | ||
max_values: this.max_values || 1, | ||
max_values: this.max_values || this.min_values ? this.min_values : 1, | ||
min_values: this.min_values || 0, | ||
@@ -33,0 +33,0 @@ custom_id: this.custom_id || this.customId, |
@@ -16,2 +16,5 @@ const Client = require('../client/client') | ||
const ChannelSelect = require('./ChannelSelect') | ||
const Collector = require('./Collector') | ||
const Member = require('./Member') | ||
const Role = require('./Role') | ||
module.exports = class Message { | ||
@@ -47,3 +50,5 @@ /** | ||
this.embeds = [] | ||
this.mentions = [...data.mentions, ...data.mention_roles] | ||
this.memberMentions = new Store() | ||
this.roleMentions = new Store() | ||
this.channelMentions = new Store() | ||
this.pinned = data.pinned | ||
@@ -63,4 +68,34 @@ this.mentionEveryone = data.mention_everyone | ||
this.authorId = this.webhookId ? this.webhookId : data.author.id | ||
this.member = this.webhookId ? null : this.guildId ? this.guild.members.get(this.authorId) : null | ||
this.interaction = data.interaction | ||
this.data_is_available = true | ||
if(this.interaction && this.interaction.user){ | ||
this.interaction.user = this.client.users.get(this.interaction.user.id) || new User(this.client, this.interaction.user) | ||
} | ||
if(data.mentions) data.mentions.map(m => { | ||
if(m.member){ | ||
m.member.user = m | ||
this.memberMentions.set(m.id, new Member(this.client, this.client.guilds.get(this.guildId)||this.guild, m.member)) | ||
} else { | ||
this.memberMentions.set(m.id, new User(this.client, m)) | ||
} | ||
}) | ||
if(data.mention_roles) data.mention_roles.map(async r_id => { | ||
if(this.guild.roles.get(r_id)) this.roleMentions.set(r_id, this.guild.roles.get(r_id)) | ||
else { | ||
let res = await this.client.rest.get(this.client._ENDPOINTS.ROLES(this.guildId)).catch(e=>{}) | ||
if(!res) return | ||
let role = res.find(r => r.id === r_id) | ||
if(!role) return | ||
this.roleMentions.set(r_id, new Role(this.client, this.client.guilds.get(this.guildId)||this.guild, role)) | ||
} | ||
}) | ||
if(data.mention_channels) data.mention_channels.map(async channelraw => { | ||
if(this.client.textChannels.get(channelraw.id)) this.channelMentions.set(channelraw.id, this.textChannels.get(channelraw.id)) | ||
else { | ||
let res = await this.client.rest.get(this.client._ENDPOINTS.CHANNEL(channelraw.id)).catch(e=>{}) | ||
if(!res) return | ||
this.channelMentions.set(channelraw.id, new TextChannel(this.client, this.client.guilds.get(this.guildId)||this.guild, res)) | ||
} | ||
}) | ||
data.attachments.map(attach => this.attachments.set(attach.id, new Attachment(this.client, this, attach))) | ||
@@ -171,2 +206,3 @@ data.embeds.map(embed => this.embeds.push(new Embed(embed))) | ||
setTimeout(() => { | ||
if(this.deleted) return resolve(this) | ||
this.client.rest.delete(this.client._ENDPOINTS.MESSAGES(this.channelId, this.id)).then(() => { | ||
@@ -408,2 +444,26 @@ this.deleted = true | ||
} | ||
createComponentsCollector(options = {}){ | ||
if(typeof options !== "object") throw new TypeError("You must provide options for the collector") | ||
if(typeof options.count !== "undefined"){ | ||
if(typeof options.count !== "number") throw new TypeError("The count must be a number") | ||
} | ||
options.type = 'component' | ||
if(typeof options.time !== "undefined"){ | ||
if(typeof options.time !== "number") throw new TypeError("The time must be a number") | ||
} | ||
if(typeof options.componentType !== "undefined"){ | ||
if(typeof options.componentType !== "number") throw new TypeError("The componentType must be a number") | ||
if(options.componentType < 1 || options.componentType > 8) throw new TypeError("Invalid componentType for the collector") | ||
} | ||
if(typeof options.filter !== "undefined"){ | ||
if(typeof options.filter !== "function") throw new TypeError("The filter must be a filter function for the collector, example : 'filter: (collected) => collected.author.id === message.author.id'") | ||
} | ||
let identifier = Date.now() | ||
this.client.collectorCache[identifier] = new Collector(this.client, this.client.guilds.get(this.guildId)||this.guild, this, this.channel, options) | ||
this.client.collectorCache[identifier]?.on('end', () => { | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
return this.client.collectorCache[identifier] | ||
} | ||
} |
@@ -10,2 +10,3 @@ const Guild = require('./Guild') | ||
this.guild = guild | ||
this.guildId = guild.id | ||
this.id = data.id | ||
@@ -29,2 +30,92 @@ this.version = data.version | ||
} | ||
edit(options = {}) { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof options !== "object") return reject(new TypeError("Edit role options must be a object")) | ||
if (typeof options.name !== "undefined") { | ||
if (typeof options.name !== "string") return reject(new TypeError("Edit role options name must be a string")) | ||
if (options.name.length > 100) return reject(new TypeError("Edit role options must be less than 100 caracters")) | ||
} | ||
if (typeof options.permissions !== "undefined") { | ||
if (options.permissions instanceof Permissions) options.permissions = options.permissions.bitfield.toString() | ||
else options.permissions = new Permissions(options.permissions).bitfield.toString() | ||
} | ||
if (typeof options.color !== "undefined") { | ||
if (typeof options.color === "string") options.color = Utils.resolveColor(options.color) | ||
if (typeof options.color !== "number") return reject(new TypeError("Edit role options color must be a number")) | ||
} | ||
if (typeof options.hoist !== "undefined") { | ||
if (typeof options.hoist !== "boolean") return reject(new TypeError("Edit role options hoist must be a boolean")) | ||
} | ||
if (typeof options.unicode_emoji !== "undefined") { | ||
if (options.unicode_emoji instanceof Emoji) { | ||
options.unicode_emoji = options.unicode_emoji.pack() | ||
options.unicode_emoji = options.unicode_emoji.id ? `${options.unicode_emoji.name}` : `<${options.unicode_emoji.animated ? "a" : ""}:${options.unicode_emoji.name}:${options.unicode_emoji.id}>` | ||
} | ||
if (typeof options.unicode_emoji !== "string") return reject(new TypeError("Edit role options unicode_emoji must be a string")) | ||
} | ||
if (typeof options.mentionable !== "undefined") { | ||
if (typeof options.mentionable !== "boolean") return reject(new TypeError("Edit role options mentionable must be a boolean")) | ||
} | ||
if (typeof options.position !== "undefined") { | ||
if (typeof options.position !== "number") return reject(new TypeError("Edit role options position must be a number")) | ||
} | ||
if (typeof options.reason !== "undefined" && typeof options.reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
this.client.rest.patch(this.client._ENDPOINTS.ROLES(this.guildId, this.id), options).then(res => { | ||
let role = new Role(this.client, this.client.guilds.get(this.id) || this, res) | ||
resolve(role) | ||
Object.keys(role).map(k => this[k] = role[k]) | ||
if (typeof this.client.options.rolesLifeTime === "number" && this.client.options.rolesLifeTime > 0) { | ||
role.cachedAt = Date.now() | ||
role.expireAt = Date.now() + this.client.options.rolesLifeTime | ||
this.guild.roles.set(role.id, role) | ||
} | ||
if (typeof options.position === "number") { | ||
this.client.rest.patch(this.client._ENDPOINTS.ROLE(this.guildId), { | ||
id: this.id, | ||
position: options.position, | ||
reason: options.reason | ||
}).then(res => { | ||
let role = new Role(this.client, this.client.guilds.get(this.id) || this, res) | ||
Object.keys(role).map(k => this[k] = role[k]) | ||
if (typeof this.client.options.rolesLifeTime === "number" && this.client.options.rolesLifeTime > 0) { | ||
role.cachedAt = Date.now() | ||
role.expireAt = Date.now() + this.client.options.rolesLifeTime | ||
this.guild.roles.set(role.id, role) | ||
} | ||
}).catch(e => { console.error(`Can't update the role position of ${role.name} in ${role.guild.name} for the next reason : ${e}`) }) | ||
} | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async delete(reason){ | ||
return new Promise(async(resolve, reject) => { | ||
if (typeof reason !== "undefined" && typeof reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
this.client.rest.delete(this.client._ENDPOINTS.ROLES(this.guildId, this.id), { | ||
reason: reason | ||
}).then(()=>{ | ||
resolve(this) | ||
this.guild.roles.delete(this.id) | ||
}).catch(e=>{ | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
get hexColor() { | ||
return `#${this.color.toString(16).padStart(6, '0')}`; | ||
} | ||
comparePositions(role){ | ||
const resolvedRole1 = this | ||
const resolvedRole2 = role instanceof Role ? role : this.guild.roles.get(role) | ||
if(!resolvedRole1 || !resolvedRole2) throw new TypeError("One of the two roles is undefined.") | ||
if(resolvedRole1.position === resolvedRole2.position){ | ||
return Number(BigInt(resolvedRole2.id) - BigInt(resolvedRole1.id)) | ||
} | ||
return resolvedRole1.position - resolvedRole2.position | ||
} | ||
} |
const { parseEmoji } = require("../util") | ||
const Emoji = require('./Emoji') | ||
module.exports = class RoleSelect { | ||
@@ -30,3 +30,3 @@ /** | ||
placeholder: this.placeholder, | ||
max_values: this.max_values || 1, | ||
max_values: this.max_values || this.min_values ? this.min_values : 1, | ||
min_values: this.min_values || 0, | ||
@@ -33,0 +33,0 @@ custom_id: this.custom_id || this.customId, |
@@ -44,3 +44,3 @@ const Client = require('../client/client') | ||
this.data_is_available = true | ||
data.permission_overwrites.map(perm => { | ||
data.permission_overwrites?.map(perm => { | ||
this.permission_overwrites.push({ | ||
@@ -47,0 +47,0 @@ id: perm.id, |
@@ -95,3 +95,3 @@ const { parseEmoji } = require("../util") | ||
placeholder: this.placeholder, | ||
max_values: this.max_values || this.options.length, | ||
max_values: this.max_values || this.min_values ? this.min_values : 1, | ||
min_values: this.min_values || 0, | ||
@@ -98,0 +98,0 @@ custom_id: this.custom_id || this.customId, |
@@ -10,2 +10,4 @@ const Client = require('../client/client') | ||
const ForumTag = require('./ForumTag') | ||
const Webhook = require('./Webhook') | ||
const Collector = require('./Collector') | ||
module.exports = class TextChannel { | ||
@@ -43,3 +45,3 @@ /** | ||
this.data_is_available = true | ||
data.permission_overwrites.map(perm => { | ||
data.permission_overwrites?.map(perm => { | ||
this.permission_overwrites.push({ | ||
@@ -100,3 +102,3 @@ id: perm.id, | ||
}) | ||
this.client.rest.post(this.client._ENDPOINTS.MESSAGES(this.channelId), data).then(messageData => { | ||
this.client.rest.post(this.client._ENDPOINTS.MESSAGES(this.id), data).then(messageData => { | ||
return resolve(new Message(this.client, this.guild, this, messageData)) | ||
@@ -239,3 +241,3 @@ }).catch(e => { | ||
if (typeof options.parent_id !== "undefined") { | ||
if(options.parent_id instanceof CategoryChannel){ | ||
if (options.parent_id instanceof CategoryChannel) { | ||
options.parent_id = options.parent_id.id | ||
@@ -306,3 +308,3 @@ } | ||
} | ||
if(typeof reason !== "undefined" && typeof reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
if (typeof reason !== "undefined" && typeof reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
options["reason"] = reason | ||
@@ -364,3 +366,3 @@ this.client.rest.patch(this.client._ENDPOINTS.CHANNEL(this.id), options).then(res => { | ||
}), | ||
parent_id: this.parentId||this.parent_id, | ||
parent_id: this.parentId || this.parent_id, | ||
nsfw: this.nsfw, | ||
@@ -390,3 +392,3 @@ rtc_region: this.rtcRegion, | ||
if (position < 0) return reject(new TypeError("The channel position must be more than 0")) | ||
this.client.rest.patch(this.client._ENDPOINTS.CHANNEL(this.id), {position: position}).then(res => { | ||
this.client.rest.patch(this.client._ENDPOINTS.CHANNEL(this.id), { position: position }).then(res => { | ||
let newChannel = new TextChannel(this.client, this.client.guilds.get(res.guild_id) || this.guild, res) | ||
@@ -438,11 +440,11 @@ Object.keys(newChannel).map(k => this[k] = newChannel[k]) | ||
async getPinnedMessages(){ | ||
return new Promise(async(resolve, reject) => { | ||
this.client.rest.get(this.client._ENDPOINTS.CHANNEL(this.id)+'/pins').then(messages => { | ||
async getPinnedMessages() { | ||
return new Promise(async (resolve, reject) => { | ||
this.client.rest.get(this.client._ENDPOINTS.CHANNEL(this.id) + '/pins').then(messages => { | ||
let collect = new Store() | ||
messages.map(msg => { | ||
collect.set(msg.id, new Message(this.client, this.client.guilds.get(this.guildId)||this.guild, this.client.textChannels.get(this.id)||this,msg)) | ||
collect.set(msg.id, new Message(this.client, this.client.guilds.get(this.guildId) || this.guild, this.client.textChannels.get(this.id) || this, msg)) | ||
}) | ||
return resolve(collect) | ||
}).catch(e=>{ | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
@@ -452,2 +454,84 @@ }) | ||
} | ||
async createWebhook(options = {}) { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof options !== "object") return reject(new TypeError("Create webhook options must be a object")) | ||
if (typeof options.name !== "string") return reject(new TypeError("Create webhook options name must be provided (string)")) | ||
if (options.name.length < 1 || options.name.length > 80) return reject(new TypeError("Create webhook options name must have a length between 1 and 80")) | ||
if (typeof options.reason !== "undefined" && typeof options.reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
this.client.rest.post(this.client._ENDPOINTS.CHANNEL_WEBHOOKS(this.id), options).then(res => { | ||
resolve(new Webhook(this.client, this.client.guilds.get(this.guildId) || this.guild, res)) | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
async fetchWebhooks() { | ||
return new Promise(async (resolve, reject) => { | ||
this.client.rest.get(this.client._ENDPOINTS.CHANNEL_WEBHOOKS(this.id)).then(res => { | ||
let collect = new Store() | ||
res.map(web => collect.set(web.id, new Webhook(this.client, this.client.guilds.get(this.guildId) || this.guild, web))) | ||
resolve(collect) | ||
}).catch(e => { | ||
return reject(new Error(e)) | ||
}) | ||
}) | ||
} | ||
createCollector(options = {}) { | ||
if (typeof options !== "object") throw new TypeError("You must provide options for the collector") | ||
if (typeof options.count !== "undefined") { | ||
if (typeof options.count !== "number") throw new TypeError("The count must be a number") | ||
} | ||
if (typeof options.type !== "undefined") { | ||
if (typeof options.type !== "string") throw new TypeError("The type must be a string") | ||
options.type = options.type.toLowerCase() | ||
if (!["message", "component"].includes(options.type)) throw new TypeError("Invalid collector type (message or component)") | ||
} | ||
if (typeof options.time !== "undefined") { | ||
if (typeof options.time !== "number") throw new TypeError("The time must be a number") | ||
} | ||
if (typeof options.componentType !== "undefined") { | ||
if (typeof options.componentType !== "number") throw new TypeError("The componentType must be a number") | ||
if (options.componentType < 1 || options.componentType > 8) throw new TypeError("Invalid componentType for the collector") | ||
} | ||
if (typeof options.filter !== "undefined") { | ||
if (typeof options.filter !== "function") throw new TypeError("The filter must be a filter function for the collector, example : 'filter: (collected) => collected.author.id === message.author.id'") | ||
} | ||
let identifier = Date.now() | ||
this.client.collectorCache[identifier] = new Collector(this.client, this.client.guilds.get(this.guildId) || this.guild, null, this.channel, options) | ||
this.client.collectorCache[identifier]?.on('end', () => { | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
return this.client.collectorCache[identifier] | ||
} | ||
awaitMessages(options = {}) { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof options !== "object") throw new TypeError("You must provide options for the collector") | ||
if (typeof options.count !== "undefined") { | ||
if (typeof options.count !== "number") throw new TypeError("The count must be a number") | ||
} | ||
options.type = "await_message" | ||
if (typeof options.time !== "undefined") { | ||
if (typeof options.time !== "number") throw new TypeError("The time must be a number") | ||
} | ||
if (typeof options.componentType !== "undefined") { | ||
if (typeof options.componentType !== "number") throw new TypeError("The componentType must be a number") | ||
if (options.componentType < 1 || options.componentType > 8) throw new TypeError("Invalid componentType for the collector") | ||
} | ||
if (typeof options.filter !== "undefined") { | ||
if (typeof options.filter !== "function") throw new TypeError("The filter must be a filter function for the collector, example : 'filter: (collected) => collected.author.id === message.author.id'") | ||
} | ||
let identifier = Date.now() | ||
this.client.collectorCache[identifier] = new Collector(this.client, this.client.guilds.get(this.guildId) || this.guild, null, this, options) | ||
this.client.collectorCache[identifier]?.on('end', () => { | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
this.client.collectorCache[identifier]?.on('collected', collected => { | ||
resolve(collected) | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
}) | ||
} | ||
} |
@@ -427,2 +427,59 @@ const Client = require('../client/client') | ||
} | ||
createCollector(options = {}){ | ||
if(typeof options !== "object") throw new TypeError("You must provide options for the collector") | ||
if(typeof options.count !== "undefined"){ | ||
if(typeof options.count !== "number") throw new TypeError("The count must be a number") | ||
} | ||
if(typeof options.type !== "undefined"){ | ||
if(typeof options.type !== "string") throw new TypeError("The type must be a string") | ||
options.type = options.type.toLowerCase() | ||
if(!["message", "component"].includes(options.type)) throw new TypeError("Invalid collector type (message or component)") | ||
} | ||
if(typeof options.time !== "undefined"){ | ||
if(typeof options.time !== "number") throw new TypeError("The time must be a number") | ||
} | ||
if(typeof options.componentType !== "undefined"){ | ||
if(typeof options.componentType !== "number") throw new TypeError("The componentType must be a number") | ||
if(options.componentType < 1 || options.componentType > 8) throw new TypeError("Invalid componentType for the collector") | ||
} | ||
if(typeof options.filter !== "undefined"){ | ||
if(typeof options.filter !== "function") throw new TypeError("The filter must be a filter function for the collector, example : 'filter: (collected) => collected.author.id === message.author.id'") | ||
} | ||
let identifier = Date.now() | ||
this.client.collectorCache[identifier] = new Collector(this.client, this.client.guilds.get(this.guildId)||this.guild, null, this.channel, options) | ||
this.client.collectorCache[identifier]?.on('end', () => { | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
return this.client.collectorCache[identifier] | ||
} | ||
awaitMessages(options = {}) { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof options !== "object") throw new TypeError("You must provide options for the collector") | ||
if (typeof options.count !== "undefined") { | ||
if (typeof options.count !== "number") throw new TypeError("The count must be a number") | ||
} | ||
options.type = "await_message" | ||
if (typeof options.time !== "undefined") { | ||
if (typeof options.time !== "number") throw new TypeError("The time must be a number") | ||
} | ||
if (typeof options.componentType !== "undefined") { | ||
if (typeof options.componentType !== "number") throw new TypeError("The componentType must be a number") | ||
if (options.componentType < 1 || options.componentType > 8) throw new TypeError("Invalid componentType for the collector") | ||
} | ||
if (typeof options.filter !== "undefined") { | ||
if (typeof options.filter !== "function") throw new TypeError("The filter must be a filter function for the collector, example : 'filter: (collected) => collected.author.id === message.author.id'") | ||
} | ||
let identifier = Date.now() | ||
this.client.collectorCache[identifier] = new Collector(this.client, this.client.guilds.get(this.guildId) || this.guild, null, this, options) | ||
this.client.collectorCache[identifier]?.on('end', () => { | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
this.client.collectorCache[identifier]?.on('collected', collected => { | ||
resolve(collected) | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
}) | ||
} | ||
} |
@@ -31,2 +31,6 @@ const Utils = require('../util') | ||
this.createdAt = new Date(this.createdTimestamp) | ||
if(this.avatar){ | ||
this.avatar = `https://cdn.discordapp.com/avatars/${this.id}/${this.avatar}${this.avatar.startsWith('a_') ? '.gif' : '.png'}?size=512` | ||
} | ||
} | ||
@@ -193,2 +197,11 @@ | ||
} | ||
async fetchBanner(size){ | ||
return new Promise(async(resolve, reject) => { | ||
if(typeof size !== "number") size = 1024 | ||
let user = await this.client.rest.get(this.client._ENDPOINTS.USER(this.id)).catch(e=>{return reject(new Error(e))}) | ||
if(!user.banner) return resolve(null) | ||
else return resolve(`https://cdn.discordapp.com/banners/${this.id}/${user.banner}${banner.startsWith('a_')?'.gif':'.png'}?size=${size}`) | ||
}) | ||
} | ||
} |
const { parseEmoji } = require("../util") | ||
const Emoji = require('./Emoji') | ||
module.exports = class UserSelect { | ||
@@ -30,3 +30,3 @@ /** | ||
placeholder: this.placeholder, | ||
max_values: this.max_values || 1, | ||
max_values: this.max_values || this.min_values ? this.min_values : 1, | ||
min_values: this.min_values || 0, | ||
@@ -33,0 +33,0 @@ custom_id: this.custom_id || this.customId, |
@@ -44,3 +44,3 @@ const Client = require('../client/client') | ||
this.data_is_available = true | ||
data.permission_overwrites.map(perm => { | ||
data.permission_overwrites?.map(perm => { | ||
this.permission_overwrites.push({ | ||
@@ -101,3 +101,3 @@ id: perm.id, | ||
}) | ||
this.client.rest.post(this.client._ENDPOINTS.MESSAGES(this.channelId), data).then(messageData => { | ||
this.client.rest.post(this.client._ENDPOINTS.MESSAGES(this.id), data).then(messageData => { | ||
return resolve(new Message(this.client, this.guild, this, messageData)) | ||
@@ -240,3 +240,3 @@ }).catch(e => { | ||
if (typeof options.parent_id !== "undefined") { | ||
if(options.parent_id instanceof CategoryChannel){ | ||
if (options.parent_id instanceof CategoryChannel) { | ||
options.parent_id = options.parent_id.id | ||
@@ -307,3 +307,3 @@ } | ||
} | ||
if(typeof reason !== "undefined" && typeof reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
if (typeof reason !== "undefined" && typeof reason !== "string") return reject(new TypeError("The reason must be a string or a undefined value")) | ||
options["reason"] = reason | ||
@@ -365,3 +365,3 @@ this.client.rest.patch(this.client._ENDPOINTS.CHANNEL(this.id), options).then(res => { | ||
}), | ||
parent_id: this.parentId||this.parent_id, | ||
parent_id: this.parentId || this.parent_id, | ||
nsfw: this.nsfw, | ||
@@ -391,3 +391,3 @@ rtc_region: this.rtcRegion, | ||
if (position < 0) return reject(new TypeError("The channel position must be more than 0")) | ||
this.client.rest.patch(this.client._ENDPOINTS.CHANNEL(this.id), {position: position}).then(res => { | ||
this.client.rest.patch(this.client._ENDPOINTS.CHANNEL(this.id), { position: position }).then(res => { | ||
let newChannel = new VoiceChannel(this.client, this.client.guilds.get(res.guild_id) || this.guild, res) | ||
@@ -438,2 +438,84 @@ Object.keys(newChannel).map(k => this[k] = newChannel[k]) | ||
} | ||
join(mute, deaf) { | ||
if (typeof mute === "undefined") mute = false | ||
if (typeof deaf === "undefined") deaf = false | ||
if (typeof mute !== "boolean") throw new TypeError("Mute state must be a boolean") | ||
if (typeof deaf !== "boolean") throw new TypeError("Deaf state must be a boolean") | ||
this.client.ws.socket.send(JSON.stringify({ | ||
op: 4, | ||
d: { | ||
guild_id: this.guildId, | ||
channel_id: this.id, | ||
self_mute: mute, | ||
self_deaf: deaf | ||
} | ||
})) | ||
} | ||
leave() { | ||
this.client.ws.socket.send(JSON.stringify({ | ||
op: 4, | ||
d: { | ||
guild_id: this.guildId, | ||
channel_id: null, | ||
} | ||
})) | ||
} | ||
createCollector(options = {}){ | ||
if(typeof options !== "object") throw new TypeError("You must provide options for the collector") | ||
if(typeof options.count !== "undefined"){ | ||
if(typeof options.count !== "number") throw new TypeError("The count must be a number") | ||
} | ||
if(typeof options.type !== "undefined"){ | ||
if(typeof options.type !== "string") throw new TypeError("The type must be a string") | ||
options.type = options.type.toLowerCase() | ||
if(!["message", "component"].includes(options.type)) throw new TypeError("Invalid collector type (message or component)") | ||
} | ||
if(typeof options.time !== "undefined"){ | ||
if(typeof options.time !== "number") throw new TypeError("The time must be a number") | ||
} | ||
if(typeof options.componentType !== "undefined"){ | ||
if(typeof options.componentType !== "number") throw new TypeError("The componentType must be a number") | ||
if(options.componentType < 1 || options.componentType > 8) throw new TypeError("Invalid componentType for the collector") | ||
} | ||
if(typeof options.filter !== "undefined"){ | ||
if(typeof options.filter !== "function") throw new TypeError("The filter must be a filter function for the collector, example : 'filter: (collected) => collected.author.id === message.author.id'") | ||
} | ||
let identifier = Date.now() | ||
this.client.collectorCache[identifier] = new Collector(this.client, this.client.guilds.get(this.guildId)||this.guild, null, this.channel, options) | ||
this.client.collectorCache[identifier]?.on('end', () => { | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
return this.client.collectorCache[identifier] | ||
} | ||
awaitMessages(options = {}) { | ||
return new Promise(async (resolve, reject) => { | ||
if (typeof options !== "object") throw new TypeError("You must provide options for the collector") | ||
if (typeof options.count !== "undefined") { | ||
if (typeof options.count !== "number") throw new TypeError("The count must be a number") | ||
} | ||
options.type = "await_message" | ||
if (typeof options.time !== "undefined") { | ||
if (typeof options.time !== "number") throw new TypeError("The time must be a number") | ||
} | ||
if (typeof options.componentType !== "undefined") { | ||
if (typeof options.componentType !== "number") throw new TypeError("The componentType must be a number") | ||
if (options.componentType < 1 || options.componentType > 8) throw new TypeError("Invalid componentType for the collector") | ||
} | ||
if (typeof options.filter !== "undefined") { | ||
if (typeof options.filter !== "function") throw new TypeError("The filter must be a filter function for the collector, example : 'filter: (collected) => collected.author.id === message.author.id'") | ||
} | ||
let identifier = Date.now() | ||
this.client.collectorCache[identifier] = new Collector(this.client, this.client.guilds.get(this.guildId) || this.guild, null, this, options) | ||
this.client.collectorCache[identifier]?.on('end', () => { | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
this.client.collectorCache[identifier]?.on('collected', collected => { | ||
resolve(collected) | ||
delete this.client.collectorCache[identifier] | ||
}) | ||
}) | ||
} | ||
} |
@@ -61,3 +61,3 @@ const got = require('got'); | ||
if (this.data) callOptions.body = this.data; | ||
callOptions.headers['content-type'] = `multipart/form-data; boundary=----------------------------dicksword`; | ||
callOptions.headers['content-type'] = `multipart/form-data; boundary=----------------------------devland`; | ||
} | ||
@@ -64,0 +64,0 @@ this.client.emit('debug', '~~~~sending~~~~'); |
@@ -10,2 +10,3 @@ module.exports = { | ||
'MESSAGE_REACTION_REMOVE_ALL': 'messageReactionAllRemove', | ||
'MESSAGE_REACTION_REMOVE_EMOJI': 'messageReactionRemoveEmoji', | ||
'CHANNEL_CREATE': 'channelCreate', | ||
@@ -18,4 +19,4 @@ 'CHANNEL_UPDATE': 'channelUpdate', | ||
'GUILD_DELETE': 'guildDelete', | ||
'GUILD_BAN_ADD': 'guildBanCreate', | ||
'GUILD_BAN_REMOVE': 'guildBanDelete', | ||
'GUILD_BAN_ADD': 'guildBanAdd', | ||
'GUILD_BAN_REMOVE': 'guildBanRemove', | ||
'GUILD_EMOJIS_UPDATE': 'guildEmojisUpdate', | ||
@@ -26,5 +27,5 @@ 'GUILD_INTEGRATIONS_UPDATE': 'guildIntegrationsUpdate', | ||
'GUILD_ROLE_DELETE': 'roleDelete', | ||
'GUILD_MEMBER_ADD': 'guildMemberJoin', | ||
'GUILD_MEMBER_ADD': 'guildMemberAdd', | ||
'GUILD_MEMBER_UPDATE': 'guildMemberUpdate', | ||
'GUILD_MEMBER_REMOVE': 'guildMemberLeave', | ||
'GUILD_MEMBER_REMOVE': 'guildMemberRemove', | ||
'GUILD_MEMBER_CHUNK': 'guildMemberChunk', | ||
@@ -44,5 +45,13 @@ 'PRESENCE_UPDATE': 'presenceUpdate', | ||
'THREAD_DELETE': 'threadDelete', | ||
'THREAD_MEMBER_UPDATE': 'threadMemberUpdate', | ||
'THREAD_MEMBERS_UPDATE': 'threadMembersUpdate', | ||
'STAGE_INSTANCE_CREATE': 'stageInstanceCreate', | ||
'STAGE_INSTANCE_UPDATE': 'stageInstanceUpdate', | ||
'STAGE_INSTANCE_DELETE': 'stageInstanceDelete', | ||
'GUILD_AUDIT_LOG_ENTRY_CREATE': 'guildAuditLogEntryCreate', | ||
'INTEGRATION_CREATE': 'integrationCreate', | ||
'INTEGRATION_UPDATE': 'integrationUpdate', | ||
'INTEGRATION_DELETE': 'integrationDelete', | ||
'WEBHOOKS_UPDATE': 'webhooksUpdate', | ||
'INTERACTION_CREATE': 'interactionCreate' | ||
} |
@@ -9,3 +9,3 @@ const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k); | ||
} else if (given[key] === Object(given[key])) { | ||
given[key] = Util.mergeDefault(def[key], given[key]); | ||
given[key] = this.mergeDefault(def[key], given[key]); | ||
} | ||
@@ -20,2 +20,3 @@ } | ||
presence: { | ||
activities: [], | ||
status: 'online', | ||
@@ -49,2 +50,4 @@ afk: false | ||
rolesLifeTimeResetAfterEvents: true, | ||
invitesLifeTime: null, | ||
invitesLifeTimeResetAfterEvents: true, | ||
token: null, | ||
@@ -57,3 +60,5 @@ } | ||
module.exports.getTimestampFrom = (snowflake) => { | ||
try{ | ||
return Number(BigInt(snowflake) >> 22n) + EPOCH | ||
}catch(e){return 0} | ||
} | ||
@@ -60,0 +65,0 @@ |
@@ -148,3 +148,2 @@ const BitField = require('./BitField'); | ||
MANAGE_THREADS: 1n << 34n, | ||
// TODO: Remove deprecated USE_*_THREADS flags in v14 | ||
USE_PUBLIC_THREADS: 1n << 35n, | ||
@@ -158,2 +157,4 @@ CREATE_PUBLIC_THREADS: 1n << 35n, | ||
MODERATE_MEMBERS: 1n << 40n, | ||
VIEW_CREATOR_MONETIZATION_ANALYTICS: 1n << 41n, | ||
USE_SOUNDBOARD: 1n << 42n, | ||
}; | ||
@@ -160,0 +161,0 @@ |
@@ -0,1 +1,4 @@ | ||
// Source : discord.js | ||
export interface StoreConstructor { | ||
@@ -2,0 +5,0 @@ new (): Store<unknown, unknown>; |
Sorry, the diff of this file is too big to display
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
715968
106
12587
0
1
1
18
5
+ Addedtslib@^2.4.1
+ Addedtslib@2.8.1(transitive)