dev(test) Test only

This commit is contained in:
Cinnamon 2022-06-26 11:53:37 +07:00
parent 05a0d122b4
commit c097deeab4
8 changed files with 28 additions and 51 deletions

View File

@ -5,31 +5,6 @@
## Interaction ## Interaction
<details open> <details open>
<summary>Fetch Commands data</summary>
```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
}
);
```
</details>
<details open>
<summary>Button Click</summary> <summary>Button Click</summary>
```js ```js

View File

@ -5,7 +5,7 @@ module.exports = (client, { d: data }) => {
for (const command of data.application_commands) { for (const command of data.application_commands) {
const user = client.users.cache.get(command.application_id); const user = client.users.cache.get(command.application_id);
if (!user || !user.bot) continue; if (!user || !user.bot) continue;
user.applications._add(command, true); user.application?.commands?._add(command, true);
} }
client.emit(Events.GUILD_APPLICATION_COMMANDS_UPDATE, data); client.emit(Events.GUILD_APPLICATION_COMMANDS_UPDATE, data);
}; };

View File

@ -165,6 +165,8 @@ const Messages = {
INVALID_BOT_METHOD: 'Bot accounts cannot use this method', INVALID_BOT_METHOD: 'Bot accounts cannot use this method',
INVALID_USER_METHOD: 'User 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}`, INTERACTION_SEND_FAILURE: msg => `${msg}`,

View File

@ -576,12 +576,6 @@ class ApplicationCommand extends Base {
* @param {Message} message Discord Message * @param {Message} message Discord Message
* @param {Array<string>} options The options to Slash Command * @param {Array<string>} options The options to Slash Command
* @returns {Promise<Snowflake>} Nonce (Discord Timestamp) when command was sent * @returns {Promise<Snowflake>} 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 = []) { async sendSlashCommand(message, options = []) {
// Check Options // Check Options
@ -739,12 +733,6 @@ class ApplicationCommand extends Base {
* @param {Message} message Discord Message * @param {Message} message Discord Message
* @param {boolean} sendFromMessage nothing .-. not used * @param {boolean} sendFromMessage nothing .-. not used
* @returns {Promise<Snowflake>} Nonce (Discord Timestamp) when command was sent * @returns {Promise<Snowflake>} 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) { async sendContextMenu(message, sendFromMessage = false) {
if (!sendFromMessage && !(message instanceof Message())) { if (!sendFromMessage && !(message instanceof Message())) {

View File

@ -133,8 +133,9 @@ class ClientApplication extends Application {
* @returns {Promise<ClientApplication>} * @returns {Promise<ClientApplication>}
*/ */
async fetch() { async fetch() {
if (!this.client.user.bot) throw new Error('INVALID_USER_METHOD'); // if (!this.client.user.bot) throw new Error('INVALID_USER_METHOD');
const app = await this.client.api.oauth2.applications('@me').get(); const app = await this.client.api.oauth2.applications(this.id).get();
console.log(app);
this._patch(app); this._patch(app);
return this; return this;
} }

View File

@ -1100,13 +1100,13 @@ class Message extends Base {
}, },
}); });
for (const command of data.application_commands) { 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) { if (!contextCMD) {
throw new Error( throw new Error(
'INTERACTION_SEND_FAILURE', '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') .filter(a => a.type == 'MESSAGE')
.map(a => a.name) .map(a => a.name)
.join(', ')}`, .join(', ')}`,

View File

@ -2,9 +2,9 @@
const { default: Collection } = require('@discordjs/collection'); const { default: Collection } = require('@discordjs/collection');
const Base = require('./Base'); const Base = require('./Base');
const ClientApplication = require('./ClientApplication');
const TextBasedChannel = require('./interfaces/TextBasedChannel'); const TextBasedChannel = require('./interfaces/TextBasedChannel');
const { Error } = require('../errors'); const { Error } = require('../errors');
const ApplicationCommandManager = require('../managers/ApplicationCommandManager');
const { RelationshipTypes } = require('../util/Constants'); const { RelationshipTypes } = require('../util/Constants');
const SnowflakeUtil = require('../util/SnowflakeUtil'); const SnowflakeUtil = require('../util/SnowflakeUtil');
const UserFlags = require('../util/UserFlags'); const UserFlags = require('../util/UserFlags');
@ -17,7 +17,6 @@ const UserFlags = require('../util/UserFlags');
class User extends Base { class User extends Base {
constructor(client, data) { constructor(client, data) {
super(client); super(client);
/** /**
* The user's id * The user's id
* @type {Snowflake} * @type {Snowflake}
@ -70,10 +69,10 @@ class User extends Base {
this.mutualGuilds = new Collection(); this.mutualGuilds = new Collection();
/** /**
* [Bot] Interaction command manager * [Bot] Interaction command manager
* @type {?ApplicationCommandManager} * @type {?ClientApplication}
* @readonly * @readonly
*/ */
this.applications = null; this.application = null;
this._patch(data); this._patch(data);
} }
@ -95,7 +94,7 @@ class User extends Base {
*/ */
this.bot = Boolean(data.bot); this.bot = Boolean(data.bot);
if (this.bot === true) { 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') { } else if (!this.partial && typeof this.bot !== 'boolean') {
this.bot = false; this.bot = false;
@ -488,6 +487,18 @@ class User extends Base {
return data; 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 // These are here only for documentation purposes - they are implemented by TextBasedChannel
/* eslint-disable no-empty-function */ /* eslint-disable no-empty-function */
send() {} send() {}

View File

@ -421,18 +421,18 @@ class TextBasedChannel {
}); });
for (const command of data.application_commands) { for (const command of data.application_commands) {
if (user.id == command.application_id) { 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; if (command.name == commandName) commandTarget = c;
} else { } else {
const tempUser = this.client.users.cache.get(command.application_id); const tempUser = this.client.users.cache.get(command.application_id);
if (tempUser && tempUser.bot && tempUser.applications) { if (tempUser && tempUser.bot && tempUser.applications) {
tempUser.applications._add(command, true); tempUser.application?.commands?._add(command, true);
} }
} }
} }
// Remove // Remove
commandTarget = 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) { if (!commandTarget) {
throw new Error( throw new Error(
'INTERACTION_SEND_FAILURE', 'INTERACTION_SEND_FAILURE',