From c097deeab4c4306b712d0648e1fd47445ef4edc4 Mon Sep 17 00:00:00 2001
From: Cinnamon <71698422+aiko-chan-ai@users.noreply.github.com>
Date: Sun, 26 Jun 2022 11:53:37 +0700
Subject: [PATCH] dev(test) Test only
---
Document/Message.md | 25 -------------------
.../GUILD_APPLICATION_COMMANDS_UPDATE.js | 2 +-
src/errors/Messages.js | 2 ++
src/structures/ApplicationCommand.js | 12 ---------
src/structures/ClientApplication.js | 5 ++--
src/structures/Message.js | 6 ++---
src/structures/User.js | 21 ++++++++++++----
src/structures/interfaces/TextBasedChannel.js | 6 ++---
8 files changed, 28 insertions(+), 51 deletions(-)
diff --git a/Document/Message.md b/Document/Message.md
index 2bbedcd..ac5c959 100644
--- a/Document/Message.md
+++ b/Document/Message.md
@@ -5,31 +5,6 @@
## Interaction
-Fetch Commands data
-
-```js
-/* Save to cache */
-// In guild (Opcode 24)
-const res = await guild.searchInteraction(
- {
- limit: 100, // default: 1
- query: 'ping', // optional
- type: 'CHAT_INPUT', // default: 'CHAT_INPUT'
- offset: 0, // default: 0
- botId: 'botid1'
- }
-);
-// With `type` && `BotId`: Return ApplicationCommand; else return undefined
-// Fetch all commands (1 bot) Shouldn't be used
-await bot.applications.fetch(
- {
- guildId: 'guild id to search', // optional
- force: false, // Using cache or createDMs to bot
- }
-);
-```
-
-
Button Click
```js
diff --git a/src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js b/src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js
index 009f6de..1a1865d 100644
--- a/src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js
+++ b/src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js
@@ -5,7 +5,7 @@ module.exports = (client, { d: data }) => {
for (const command of data.application_commands) {
const user = client.users.cache.get(command.application_id);
if (!user || !user.bot) continue;
- user.applications._add(command, true);
+ user.application?.commands?._add(command, true);
}
client.emit(Events.GUILD_APPLICATION_COMMANDS_UPDATE, data);
};
diff --git a/src/errors/Messages.js b/src/errors/Messages.js
index 617dcc2..314e00e 100644
--- a/src/errors/Messages.js
+++ b/src/errors/Messages.js
@@ -165,6 +165,8 @@ const Messages = {
INVALID_BOT_METHOD: 'Bot accounts cannot use this method',
INVALID_USER_METHOD: 'User accounts cannot use this method',
+ BOT_ONLY: 'This method only for bots',
+ USER_ONLY: 'This method only for users',
INTERACTION_SEND_FAILURE: msg => `${msg}`,
diff --git a/src/structures/ApplicationCommand.js b/src/structures/ApplicationCommand.js
index 8ae903a..fcb7813 100644
--- a/src/structures/ApplicationCommand.js
+++ b/src/structures/ApplicationCommand.js
@@ -576,12 +576,6 @@ class ApplicationCommand extends Base {
* @param {Message} message Discord Message
* @param {Array} options The options to Slash Command
* @returns {Promise} Nonce (Discord Timestamp) when command was sent
- * @example
- * const botID = '12345678987654321'
- * const user = await client.users.fetch(botID);
- * const application = await user.applications.fetch();
- * const command = application.commands.first();
- * await command.sendSlashCommand(messsage, ['option1', 'option2']);
*/
async sendSlashCommand(message, options = []) {
// Check Options
@@ -739,12 +733,6 @@ class ApplicationCommand extends Base {
* @param {Message} message Discord Message
* @param {boolean} sendFromMessage nothing .-. not used
* @returns {Promise} Nonce (Discord Timestamp) when command was sent
- * @example
- * const botID = '12345678987654321'
- * const user = await client.users.fetch(botID);
- * const application = await user.applications.fetch();
- * const command = application.commands.first();
- * await command.sendContextMenu(messsage);
*/
async sendContextMenu(message, sendFromMessage = false) {
if (!sendFromMessage && !(message instanceof Message())) {
diff --git a/src/structures/ClientApplication.js b/src/structures/ClientApplication.js
index dfcef30..3a043c6 100644
--- a/src/structures/ClientApplication.js
+++ b/src/structures/ClientApplication.js
@@ -133,8 +133,9 @@ class ClientApplication extends Application {
* @returns {Promise}
*/
async fetch() {
- if (!this.client.user.bot) throw new Error('INVALID_USER_METHOD');
- const app = await this.client.api.oauth2.applications('@me').get();
+ // 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);
return this;
}
diff --git a/src/structures/Message.js b/src/structures/Message.js
index c050abf..9fad6e5 100644
--- a/src/structures/Message.js
+++ b/src/structures/Message.js
@@ -1100,13 +1100,13 @@ class Message extends Base {
},
});
for (const command of data.application_commands) {
- user.applications._add(command, true);
+ user.application?.commands?._add(command, true);
}
- contextCMD = user.applications.cache.find(c => c.name == commandName && c.type === 'MESSAGE');
+ contextCMD = user.application?.commands?.cache.find(c => c.name == commandName && c.type === 'MESSAGE');
if (!contextCMD) {
throw new Error(
'INTERACTION_SEND_FAILURE',
- `Command ${commandName} is not found (with search)\nList command avalible: ${user.applications.cache
+ `Command ${commandName} is not found (with search)\nList command avalible: ${user.application?.commands?.cache
.filter(a => a.type == 'MESSAGE')
.map(a => a.name)
.join(', ')}`,
diff --git a/src/structures/User.js b/src/structures/User.js
index c4956d0..df8918c 100644
--- a/src/structures/User.js
+++ b/src/structures/User.js
@@ -2,9 +2,9 @@
const { default: Collection } = require('@discordjs/collection');
const Base = require('./Base');
+const ClientApplication = require('./ClientApplication');
const TextBasedChannel = require('./interfaces/TextBasedChannel');
const { Error } = require('../errors');
-const ApplicationCommandManager = require('../managers/ApplicationCommandManager');
const { RelationshipTypes } = require('../util/Constants');
const SnowflakeUtil = require('../util/SnowflakeUtil');
const UserFlags = require('../util/UserFlags');
@@ -17,7 +17,6 @@ const UserFlags = require('../util/UserFlags');
class User extends Base {
constructor(client, data) {
super(client);
-
/**
* The user's id
* @type {Snowflake}
@@ -70,10 +69,10 @@ class User extends Base {
this.mutualGuilds = new Collection();
/**
* [Bot] Interaction command manager
- * @type {?ApplicationCommandManager}
+ * @type {?ClientApplication}
* @readonly
*/
- this.applications = null;
+ this.application = null;
this._patch(data);
}
@@ -95,7 +94,7 @@ class User extends Base {
*/
this.bot = Boolean(data.bot);
if (this.bot === true) {
- this.applications = new ApplicationCommandManager(this.client, undefined, this);
+ this.application = new ClientApplication(this.client, { id: this.id });
}
} else if (!this.partial && typeof this.bot !== 'boolean') {
this.bot = false;
@@ -488,6 +487,18 @@ 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() {}
diff --git a/src/structures/interfaces/TextBasedChannel.js b/src/structures/interfaces/TextBasedChannel.js
index a3b9cbd..8946f2d 100644
--- a/src/structures/interfaces/TextBasedChannel.js
+++ b/src/structures/interfaces/TextBasedChannel.js
@@ -421,18 +421,18 @@ class TextBasedChannel {
});
for (const command of data.application_commands) {
if (user.id == command.application_id) {
- const c = user.applications._add(command, true);
+ const c = user.application?.commands?._add(command, true);
if (command.name == commandName) commandTarget = c;
} else {
const tempUser = this.client.users.cache.get(command.application_id);
if (tempUser && tempUser.bot && tempUser.applications) {
- tempUser.applications._add(command, true);
+ tempUser.application?.commands?._add(command, true);
}
}
}
// Remove
commandTarget =
- commandTarget || user.applications.cache.find(c => c.name === commandName && c.type === 'CHAT_INPUT');
+ commandTarget || user.application?.commands?.cache.find(c => c.name === commandName && c.type === 'CHAT_INPUT');
if (!commandTarget) {
throw new Error(
'INTERACTION_SEND_FAILURE',