chore(release): version

This commit is contained in:
Cinnamon
2022-06-26 13:40:26 +07:00
parent c097deeab4
commit 736238f3df
11 changed files with 78 additions and 29 deletions

View File

@@ -388,6 +388,20 @@ class Client extends BaseClient {
this.token = null;
}
/**
* Logs out, terminates the connection to Discord, destroys the client and destroys the token.
* @returns {Promise<void>}
*/
async logout() {
await this.api.auth.logout.post({
data: {
provider: null,
voip_provider: null,
},
});
this.destroy();
}
/**
* Options used when fetching an invite from Discord.
* @typedef {Object} ClientFetchInviteOptions

View File

@@ -48,6 +48,7 @@ const Messages = {
EMBED_DESCRIPTION: 'MessageEmbed description must be a string.',
EMBED_AUTHOR_NAME: 'MessageEmbed author name must be a string.',
/* Add */
MISSING_PERMISSIONS: (...permission) => `You can't do this action [Missing Permission(s): ${permission.join(', ')}]`,
EMBED_PROVIDER_NAME: 'MessageEmbed provider name must be a string.',
BUTTON_LABEL: 'MessageButton label must be a string',

View File

@@ -2,7 +2,6 @@
const Team = require('./Team');
const Application = require('./interfaces/Application');
const { Error } = require('../errors/DJSError');
const ApplicationCommandManager = require('../managers/ApplicationCommandManager');
const ApplicationFlags = require('../util/ApplicationFlags');
const Permissions = require('../util/Permissions');
@@ -18,14 +17,14 @@ const Permissions = require('../util/Permissions');
* @extends {Application}
*/
class ClientApplication extends Application {
constructor(client, data) {
constructor(client, data, user) {
super(client, data);
/**
* The application command manager for this application
* @type {ApplicationCommandManager}
*/
this.commands = new ApplicationCommandManager(this.client);
this.commands = new ApplicationCommandManager(this.client, undefined, user);
}
_patch(data) {
@@ -133,10 +132,14 @@ class ClientApplication extends Application {
* @returns {Promise<ClientApplication>}
*/
async fetch() {
// if (!this.client.user.bot) throw new Error('INVALID_USER_METHOD');
const app = await this.client.api.oauth2.applications(this.id).get();
console.log(app);
this._patch(app);
const app = await this.client.api.oauth2.authorize.get({
query: {
client_id: this.id,
scope: 'bot',
},
});
this.client.users._add(app.bot);
this._patch(app.application);
return this;
}
}

View File

@@ -659,7 +659,7 @@ class Guild extends AnonymousGuild {
resolve(
this.client.users.cache
.get(botId)
?.applications?.cache?.find(
?.application?.commands?.cache?.find(
c => (c.name === query && c.type == type) || c.type == ApplicationCommandTypes[type],
),
);
@@ -1510,6 +1510,37 @@ class Guild extends AnonymousGuild {
}
}
/**
* Add Integrations to the guild
* @param {Snowflake} applicationId Application (ID) target
* @returns {Promise<void>}
*/
async addIntegration(applicationId) {
if (!this.me.permissions.has('MANAGE_WEBHOOKS')) {
throw new Error('MISSING_PERMISSIONS', 'MANAGE_WEBHOOKS');
}
if (!this.me.permissions.has('MANAGE_GUILD')) {
throw new Error('MISSING_PERMISSIONS', 'MANAGE_GUILD');
}
if (!applicationId || typeof applicationId !== 'string') throw new TypeError('INVALID_APPLICATION_ID');
// Check permission
await this.client.api.oauth2.authorize.post({
query: {
client_id: applicationId,
scope: 'applications.commands',
},
data: {
guild_id: this.id,
permissions: '0',
authorize: true,
},
});
}
addBot() {
console.log('Test only (Addbot)');
}
toJSON() {
const json = super.toJSON({
available: false,

View File

@@ -1081,7 +1081,7 @@ class Message extends Base {
async contextMenu(botId, commandName) {
if (!botId) throw new Error('Bot ID is required');
const user = await this.client.users.fetch(botId).catch(() => {});
if (!user || !user.bot || !user.applications) {
if (!user || !user.bot || !user.application) {
throw new Error('BotID is not a bot or does not have an application slash command');
}
if (!commandName || typeof commandName !== 'string') {

View File

@@ -94,7 +94,8 @@ class User extends Base {
*/
this.bot = Boolean(data.bot);
if (this.bot === true) {
this.application = new ClientApplication(this.client, { id: this.id });
this.application = new ClientApplication(this.client, { id: this.id }, this);
this.botInGuildsCount = null;
}
} else if (!this.partial && typeof this.bot !== 'boolean') {
this.bot = false;
@@ -159,6 +160,14 @@ class User extends Base {
*/
this.flags = new UserFlags(data.public_flags);
}
if ('approximate_guild_count' in data) {
/**
* Check how many guilds the bot is in (Probably only approximate) (application.fetch() first)
* @type {?number}
*/
this.botInGuildsCount = data.approximate_guild_count;
}
}
/**
@@ -487,18 +496,6 @@ class User extends Base {
return data;
}
async fetchBotInfo() {
if (this.client.user.bot) throw new Error('INVALID_BOT_METHOD');
if (!this.bot) throw new Error('BOT_ONLY');
const result = await this.client.api.oauth2.authorize.get({
query: {
client_id: this.id,
scope: 'bot',
},
});
console.log(result);
}
// These are here only for documentation purposes - they are implemented by TextBasedChannel
/* eslint-disable no-empty-function */
send() {}

View File

@@ -402,7 +402,7 @@ class TextBasedChannel {
if (!botId) throw new Error('Bot ID is required');
// ? maybe ...
const user = await this.client.users.fetch(botId).catch(() => {});
if (!user || !user.bot || !user.applications) {
if (!user || !user.bot || !user.application) {
throw new Error('botId is not a bot or does not have an application slash command');
}
if (!commandName || typeof commandName !== 'string') throw new Error('Command name is required');
@@ -425,7 +425,7 @@ class TextBasedChannel {
if (command.name == commandName) commandTarget = c;
} else {
const tempUser = this.client.users.cache.get(command.application_id);
if (tempUser && tempUser.bot && tempUser.applications) {
if (tempUser && tempUser.bot && tempUser.application) {
tempUser.application?.commands?._add(command, true);
}
}