Merge branch 'aiko-chan-ai:main' into main

This commit is contained in:
TheDevYellowy
2022-08-01 07:56:23 -07:00
committed by GitHub
13 changed files with 1159 additions and 1433 deletions

View File

@@ -274,7 +274,7 @@ class GuildChannelManager extends CachedManager {
nsfw: data.nsfw,
bitrate: data.bitrate ?? channel.bitrate,
user_limit: data.userLimit ?? channel.userLimit,
rtc_region: data.rtcRegion ?? channel.rtcRegion,
rtc_region: 'rtcRegion' in data ? data.rtcRegion : channel.rtcRegion,
video_quality_mode:
typeof data.videoQualityMode === 'string' ? VideoQualityModes[data.videoQualityMode] : data.videoQualityMode,
parent_id: parent,

View File

@@ -592,6 +592,7 @@ class ApplicationCommand extends Base {
* @returns {Promise<InteractionResponseBody>}
*/
async sendSlashCommand(message, options = []) {
// Todo: Refactor
// Check Options
if (!(message instanceof Message())) {
throw new TypeError('The message must be a Discord.Message');
@@ -599,7 +600,7 @@ class ApplicationCommand extends Base {
if (!Array.isArray(options)) {
throw new TypeError('The options must be an array of strings');
}
if (this.type !== 'CHAT_INPUT') return false;
if (this.type !== 'CHAT_INPUT') throw new Error('This command is not a chat input [/]');
const optionFormat = [];
const attachments = [];
const attachmentsBuffer = [];
@@ -627,10 +628,10 @@ class ApplicationCommand extends Base {
option_[0] = {
type: ApplicationCommandOptionTypes[subCommand.type],
name: subCommand.name,
options: optionFormat,
options: optionFormat.filter(obj => obj.value !== undefined),
};
} else {
option_ = optionFormat;
option_ = optionFormat.filter(obj => obj.value !== undefined);
}
// Autoresponse
const getAutoResponse = async (options_, type, name, value) => {
@@ -702,7 +703,7 @@ class ApplicationCommand extends Base {
if (this.options[i].choices && this.options[i].choices.length > 0) {
choice =
this.options[i].choices.find(c => c.name == value) || this.options[i].choices.find(c => c.value == value);
if (!choice) {
if (!choice && value) {
throw new Error(
`Invalid option: ${value} is not a valid choice for this option\nList of choices:\n${this.options[
i
@@ -716,8 +717,9 @@ class ApplicationCommand extends Base {
type: ApplicationCommandOptionTypes[this.options[i].type],
name: this.options[i].name,
value:
choice?.value ||
(this.options[i].type == 'ATTACHMENT'
choice?.value || value == undefined
? value
: this.options[i].type == 'ATTACHMENT'
? await addDataFromAttachment(value)
: this.options[i].type == 'INTEGER'
? Number(value)
@@ -730,7 +732,7 @@ class ApplicationCommand extends Base {
this.options[i].name,
value,
)
: value),
: value,
};
optionFormat.push(data);
} else {
@@ -742,7 +744,7 @@ class ApplicationCommand extends Base {
choice =
subCommand.options[i].choices.find(c => c.name == value) ||
subCommand.options[i].choices.find(c => c.value == value);
if (!choice) {
if (!choice && value) {
throw new Error(
`Invalid option: ${value} is not a valid choice for this option\nList of choices: \n${subCommand.options[
i
@@ -756,8 +758,9 @@ class ApplicationCommand extends Base {
type: ApplicationCommandOptionTypes[subCommand.options[i].type],
name: subCommand.options[i].name,
value:
choice?.value ||
(subCommand.options[i].type == 'ATTACHMENT'
choice?.value || value == undefined
? value
: subCommand.options[i].type == 'ATTACHMENT'
? await addDataFromAttachment(value)
: subCommand.options[i].type == 'INTEGER'
? Number(value)
@@ -770,7 +773,7 @@ class ApplicationCommand extends Base {
subCommand.options[i].name,
value,
)
: value),
: value,
};
optionFormat.push(data);
}

View File

@@ -5,7 +5,7 @@ const Invite = require('./Invite');
const { Message } = require('./Message');
const User = require('./User');
const { Util } = require('..');
const { HypeSquadOptions, Opcodes, NitroType } = require('../util/Constants');
const { Opcodes, NitroType, HypeSquadType } = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const PurchasedFlags = require('../util/PurchasedFlags');
/**
@@ -43,7 +43,7 @@ class ClientUser extends User {
* Nitro type of the client user.
* @type {NitroType}
*/
this.nitroType = nitro ?? `UNKNOWN`;
this.nitroType = nitro ?? `UNKNOWN_${data.premium_type}`;
}
if ('purchased_flags' in data) {
/**
@@ -172,7 +172,7 @@ class ClientUser extends User {
* .catch(console.error);
*/
setBanner(banner) {
if (this.nitroType !== 2) {
if (this.nitroType !== 'NITRO_BOOST') {
throw new Error('You must be a Nitro Boosted User to change your banner.');
}
return this.edit({ banner });
@@ -180,7 +180,7 @@ class ClientUser extends User {
/**
* Set HyperSquad House
* @param {HypeSquadOptions<number|string>} type
* @param {HypeSquadType} type
* * `LEAVE`: 0
* * `HOUSE_BRAVERY`: 1
* * `HOUSE_BRILLIANCE`: 2
@@ -193,7 +193,7 @@ class ClientUser extends User {
* client.user.setHypeSquad(0);
*/
async setHypeSquad(type) {
const id = typeof type === 'string' ? HypeSquadOptions[type] : type;
const id = typeof type === 'string' ? HypeSquadType[type] : type;
if (!id && id !== 0) throw new Error('Invalid HypeSquad type.');
if (id !== 0) {
const data = await this.client.api.hypesquad.online.post({
@@ -222,7 +222,7 @@ class ClientUser extends User {
* @returns {Promise}
*/
setDiscriminator(discriminator, password) {
if (!this.nitro) throw new Error('You must be a Nitro User to change your discriminator.');
if (this.nitroType == 'NONE') throw new Error('You must be a Nitro User to change your discriminator.');
if (!password && !this.client.password) {
throw new Error('A password is required to change a discriminator.');
}

View File

@@ -93,6 +93,13 @@ class MessageMentions {
*/
this._channels = null;
/**
* Cached users for {@link MessageMentions#parsedUsers}
* @type {?Collection<Snowflake, User>}
* @private
*/
this._parsedUsers = null;
/**
* Crossposted channel data.
* @typedef {Object} CrosspostedChannel
@@ -168,6 +175,23 @@ class MessageMentions {
return this._channels;
}
/**
* Any user mentions that were included in the message content
* <info>Order as they appear first in the message content</info>
* @type {Collection<Snowflake, User>}
* @readonly
*/
get parsedUsers() {
if (this._parsedUsers) return this._parsedUsers;
this._parsedUsers = new Collection();
let matches;
while ((matches = this.constructor.USERS_PATTERN.exec(this._content)) !== null) {
const user = this.client.users.cache.get(matches[1]);
if (user) this._parsedUsers.set(user.id, user);
}
return this._parsedUsers;
}
/**
* Options used to check for a mention.
* @typedef {Object} MessageMentionsHasOptions
@@ -187,14 +211,20 @@ class MessageMentions {
*/
has(data, { ignoreDirect = false, ignoreRoles = false, ignoreRepliedUser = false, ignoreEveryone = false } = {}) {
const user = this.client.users.resolve(data);
const role = this.guild?.roles.resolve(data);
const channel = this.client.channels.resolve(data);
if (!ignoreEveryone && user && this.everyone) return true;
const userWasRepliedTo = user && this.repliedUser?.id === user.id;
if (!ignoreRepliedUser && userWasRepliedTo && this.users.has(user.id)) return true;
if (!ignoreRepliedUser && this.users.has(this.repliedUser?.id) && this.repliedUser?.id === user?.id) return true;
if (!ignoreDirect) {
if (this.users.has(user?.id)) return true;
if (this.roles.has(role?.id)) return true;
if (this.channels.has(channel?.id)) return true;
if (user && (!ignoreRepliedUser || this.parsedUsers.has(user.id)) && this.users.has(user.id)) return true;
const role = this.guild?.roles.resolve(data);
if (role && this.roles.has(role.id)) return true;
const channel = this.client.channels.resolve(data);
if (channel && this.channels.has(channel.id)) return true;
}
if (user && !ignoreEveryone && this.everyone) return true;
if (!ignoreRoles) {

View File

@@ -8,7 +8,7 @@ const getUUID = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, a => (a ^ ((Math.random() * 16) >> (a / 4))).toString(16));
// Function check url valid (ok copilot)
// eslint-disable-next-line
const checkUrl = url=> /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/.test(url);
const checkUrl = url => /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/.test(url);
class CustomStatus {
/**

View File

@@ -398,6 +398,15 @@ class TextBasedChannel {
* @param {string} commandName Command name
* @param {...?string|string[]} args Command arguments
* @returns {Promise<InteractionResponseBody>}
* @example
* // Send Slash to this channel
* // Demo:
* // + BotID: "123456789012345678"
* // + CommandName: "embed"
* // + Args: "title", "description", "author", 'color' (Optional)
* channel.sendSlash('123456789012345678', 'embed', 'title', 'description', 'author', '#00ff00')
* // Send embed with Title and Color:
* channel.sendSlash('123456789012345678', 'embed', 'title', undefined, undefined, '#00ff00')
*/
async sendSlash(botId, commandName, ...args) {
args = args.flat(2);

View File

@@ -59,6 +59,16 @@ exports.stickerAnimationMode = createEnum(['ALWAYS', 'INTERACTION', 'NEVER']);
*/
exports.NitroType = createEnum(['NONE', 'NITRO_CLASSIC', 'NITRO_BOOST']);
/**
* All available HypeSquad types:
* * `LEAVE` - None
* * `HOUSE_BRAVERY` - HypeSquad Bravery
* * `HOUSE_BRILLIANCE` - HypeSquad Brilliance
* * `HOUSE_BALANCE` - HypeSquad Balance
* @typedef {string} HypeSquadType
*/
exports.HypeSquadType = createEnum(['LEAVE', 'HOUSE_BRAVERY', 'HOUSE_BRILLIANCE', 'HOUSE_BALANCE']);
exports.localeObject = {
da: 'DANISH',
de: 'GERMAN',
@@ -1584,8 +1594,6 @@ exports.GuildScheduledEventEntityTypes = createEnum([null, 'STAGE_INSTANCE', 'VO
*/
exports.VideoQualityModes = createEnum([null, 'AUTO', 'FULL']);
exports.HypeSquadOptions = createEnum(['LEAVE', 'HOUSE_BRAVERY', 'HOUSE_BRILLIANCE', 'HOUSE_BALANCE']);
exports._cleanupSymbol = Symbol('djsCleanup');
function keyMirror(arr) {

File diff suppressed because it is too large Load Diff