From dcb9d087def52ece87de258ef8711ed5784228c8 Mon Sep 17 00:00:00 2001
From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com>
Date: Sun, 2 Apr 2023 13:18:35 +0700
Subject: [PATCH] feat: **BETA** ClydeAI
**BETA**
---
package.json | 1 +
src/structures/Guild.js | 48 +++++++++++++++++++++++++++++++++++++++--
typings/index.d.ts | 8 ++++++-
3 files changed, 54 insertions(+), 3 deletions(-)
diff --git a/package.json b/package.json
index d5d205d..483918b 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/src/structures/Guild.js b/src/structures/Guild.js
index bd9f827..3124e6a 100644
--- a/src/structures/Guild.js
+++ b/src/structures/Guild.js
@@ -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
+ * `CLYDE_ENABLED` is now an experimental feature of Discord
* * 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
+ * **BETA** - This feature is currently in beta and may be changed or removed at any time.
+ * @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.
+ * This feature is currently in beta and may be changed or removed at any time.
+ * @param {boolean} [enabled=true] Whether the guild is enabled for Clyde AI
+ * @returns {Promise}
+ * @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}
@@ -1481,6 +1521,7 @@ class Guild extends AnonymousGuild {
/**
* Deletes the guild.
+ * @param {string} [mfaCode] The MFA code for the guild owner
* @returns {Promise}
* @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;
}
diff --git a/typings/index.d.ts b/typings/index.d.ts
index 8192c5c..0b6e2f7 100644
--- a/typings/index.d.ts
+++ b/typings/index.d.ts
@@ -1414,7 +1414,7 @@ export class Guild extends AnonymousGuild {
public widgetEnabled: boolean | null;
public readonly maximumBitrate: number;
public createTemplate(name: string, description?: string): Promise;
- public delete(): Promise;
+ public delete(mfaCode?: string): Promise;
public read(): Promise;
public discoverySplashURL(options?: StaticImageURLOptions): string | null;
public edit(data: GuildEditData, reason?: string): Promise;
@@ -1476,6 +1476,11 @@ export class Guild extends AnonymousGuild {
public setWidgetSettings(settings: GuildWidgetSettingsData, reason?: string): Promise;
public setVanityCode(code?: string): Promise;
public toJSON(): unknown;
+ // Added
+ /** @deprecated */
+ public readonly clydeSupport: boolean;
+ /** @deprecated */
+ public enableClydeAI(enabled?: boolean): Promise;
}
export class GuildAuditLogs {
@@ -6313,6 +6318,7 @@ export type GuildFeatures =
| 'ANIMATED_ICON'
| 'AUTO_MODERATION'
| 'BANNER'
+ | 'CLYDE_ENABLED'
| 'COMMERCE'
| 'COMMUNITY'
| 'CREATOR_MONETIZABLE_PROVISIONAL'