feat: **BETA** ClydeAI

**BETA**
This commit is contained in:
Elysia 2023-04-02 13:18:35 +07:00
parent d1d842098a
commit dcb9d087de
3 changed files with 54 additions and 3 deletions

View File

@ -65,6 +65,7 @@
"form-data": "^4.0.0",
"json-bigint": "^1.0.0",
"lodash.permutations": "^1.0.0",
"murmurhash": "^2.0.1",
"node-fetch": "^2.6.9",
"safe-base64": "^2.0.1-0",
"set-cookie-parser": "^2.6.0",

View File

@ -2,6 +2,7 @@
const process = require('node:process');
const { Collection } = require('@discordjs/collection');
const { v3 } = require('murmurhash');
const AnonymousGuild = require('./AnonymousGuild');
const GuildAuditLogs = require('./GuildAuditLogs');
const GuildPreview = require('./GuildPreview');
@ -228,6 +229,8 @@ class Guild extends AnonymousGuild {
* * ANIMATED_ICON
* * AUTO_MODERATION
* * BANNER
* * CLYDE_ENABLED
* <warn> `CLYDE_ENABLED` is now an experimental feature of Discord</warn>
* * COMMERCE
* * COMMUNITY
* * CREATOR_MONETIZABLE_PROVISIONAL
@ -577,6 +580,26 @@ class Guild extends AnonymousGuild {
return this.members.fetch({ ...options, user: this.ownerId });
}
/**
* Check out the guild that can activate ClydeAI
* <info>**BETA** - This feature is currently in beta and may be changed or removed at any time.</info>
* @type {boolean}
* @readonly
* @deprecated
*/
get clydeSupport() {
// **BETA** - This feature is currently in beta and may be changed or removed at any time.
// Cannot be enabled on guilds with more than 100 members
if (
v3(`2023-03_clyde_ai:${this.id}`) % 10e3 > 100 ||
this.memberCount > 100 ||
this.features.includes('COMMUNITY')
) {
return false;
}
return true;
}
/**
* AFK voice channel for this guild.
* @type {?VoiceChannel}
@ -1453,6 +1476,23 @@ class Guild extends AnonymousGuild {
return this.edit({ features });
}
/**
* Enables or disables Clyde AI for this guild.
* <info>This feature is currently in beta and may be changed or removed at any time.</info>
* @param {boolean} [enabled=true] Whether the guild is enabled for Clyde AI
* @returns {Promise<Guild>}
* @deprecated
*/
enableClydeAI(enabled = true) {
if (!this.clydeSupport) return Promise.resolve(this);
if (enabled) {
if (this.features.includes('CLYDE_ENABLED')) return Promise.resolve(this);
return this.edit({ features: [...this.features, 'CLYDE_ENABLED'] });
} else {
return this.edit({ features: this.features.filter(f => f !== 'CLYDE_ENABLED') });
}
}
/**
* Leaves the guild.
* @returns {Promise<Guild>}
@ -1481,6 +1521,7 @@ class Guild extends AnonymousGuild {
/**
* Deletes the guild.
* @param {string} [mfaCode] The MFA code for the guild owner
* @returns {Promise<Guild>}
* @example
* // Delete a guild
@ -1488,8 +1529,11 @@ class Guild extends AnonymousGuild {
* .then(guild => console.log(`Deleted the guild ${guild.name}`))
* .catch(console.error);
*/
async delete() {
await this.client.api.guilds(this.id).delete();
async delete(mfaCode) {
if ((!mfaCode || typeof mfaCode !== 'string' || mfaCode.length !== 6) && this.client.user.mfaEnabled) {
throw new Error('MFA_INVALID');
}
await this.client.api.guilds(this.id).delete({ data: mfaCode ? { code: mfaCode } : undefined });
return this.client.actions.GuildDelete.handle({ id: this.id }).guild;
}

8
typings/index.d.ts vendored
View File

@ -1414,7 +1414,7 @@ export class Guild extends AnonymousGuild {
public widgetEnabled: boolean | null;
public readonly maximumBitrate: number;
public createTemplate(name: string, description?: string): Promise<GuildTemplate>;
public delete(): Promise<Guild>;
public delete(mfaCode?: string): Promise<Guild>;
public read(): Promise<undefined>;
public discoverySplashURL(options?: StaticImageURLOptions): string | null;
public edit(data: GuildEditData, reason?: string): Promise<Guild>;
@ -1476,6 +1476,11 @@ export class Guild extends AnonymousGuild {
public setWidgetSettings(settings: GuildWidgetSettingsData, reason?: string): Promise<Guild>;
public setVanityCode(code?: string): Promise<Vanity>;
public toJSON(): unknown;
// Added
/** @deprecated */
public readonly clydeSupport: boolean;
/** @deprecated */
public enableClydeAI(enabled?: boolean): Promise<Guild>;
}
export class GuildAuditLogs<T extends GuildAuditLogsResolvable = 'ALL'> {
@ -6313,6 +6318,7 @@ export type GuildFeatures =
| 'ANIMATED_ICON'
| 'AUTO_MODERATION'
| 'BANNER'
| 'CLYDE_ENABLED'
| 'COMMERCE'
| 'COMMUNITY'
| 'CREATOR_MONETIZABLE_PROVISIONAL'