aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authormegumin <megumin.bakaretsurie@gmail.com>2022-10-09 17:18:18 +0100
committerGitHub <noreply@github.com>2022-10-09 17:18:18 +0100
commitd3c581eb4e099e3dd368b8e9880752c1ba2a0849 (patch)
tree0ea24955f5b9fde001d3cdc05800195a3deb3477 /src/plugins
parent151f2eef8a72faa57608185e4d09005404b251bf (diff)
downloadVencord-d3c581eb4e099e3dd368b8e9880752c1ba2a0849.tar.gz
Vencord-d3c581eb4e099e3dd368b8e9880752c1ba2a0849.tar.bz2
Vencord-d3c581eb4e099e3dd368b8e9880752c1ba2a0849.zip
🗿🗿🗿 (#75)
🗿🗿🗿
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/moyai.ts82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/plugins/moyai.ts b/src/plugins/moyai.ts
new file mode 100644
index 0000000..7e629fc
--- /dev/null
+++ b/src/plugins/moyai.ts
@@ -0,0 +1,82 @@
+import definePlugin from "../utils/types";
+import { Devs } from "../utils/constants";
+import { Message } from "discord-types/general";
+
+interface IMessageCreate {
+ type: "MESSAGE_CREATE";
+ channelId: string;
+ isPushNotification: boolean;
+ optimistic: boolean;
+ message: Message;
+}
+
+const MOYAI_URL =
+ "https://github.com/MeguminSama/VencordPlugins/raw/main/plugins/moyai/moyai.mp3";
+
+export default definePlugin({
+ name: "Moyai",
+ authors: [Devs.Megu],
+ description: "🗿🗿🗿🗿🗿🗿🗿🗿",
+ execute: async (event: IMessageCreate) => {
+ if (event?.type !== "MESSAGE_CREATE") return;
+ if (!event.message?.content) return;
+ if (event.message.state === "SENDING") return;
+ if (event.optimistic) return;
+
+ const isInGuildChannel =
+ window.location.pathname.startsWith("/channels/");
+ if (!isInGuildChannel) return;
+
+ const channelId = window.location.pathname.split("/")[3];
+ if (!channelId || channelId !== event.channelId) return;
+
+ const moyaiCount = messageContainsMoyai(event.message.content);
+ if (!moyaiCount) return;
+
+ for (let i = 0; i < moyaiCount; i++) {
+ const audioElement = document.createElement("audio");
+ audioElement.src = MOYAI_URL;
+ audioElement.play();
+ await new Promise(resolve => setTimeout(resolve, 300));
+ }
+ },
+ patches: [
+ {
+ find: "MESSAGE_CREATE:function(",
+ replacement: [
+ {
+ match: /MESSAGE_CREATE:function\((\w+)\){/,
+ replace:
+ "MESSAGE_CREATE:function($1){Vencord.Plugins.plugins.Moyai.execute($1);",
+ },
+ ],
+ },
+ ],
+});
+
+const EMOJI_NAME_REGEX = /<a?:(\w+):\d+>/g;
+
+function messageContainsMoyai(message: string): number {
+ // get number of 🗿 in a string
+ let moyaiCount = (message.match(/🗿/g) || []).length;
+
+ // get number of emojis in message that are called "moyai" or "moai"
+ const emojiNames = message.matchAll(EMOJI_NAME_REGEX);
+
+ if (emojiNames) {
+ for (const emojiName of emojiNames) {
+ if (!emojiName[1]) continue;
+ let name = emojiName[1];
+
+ // If emoji starts or ends with (moyai|moai)
+ if (/^(moyai|moai)/i.test(name) || /(moyai|moai)$/i.test(name)) {
+ moyaiCount++;
+ }
+ }
+ }
+
+ // Maximum moyai...
+ if (moyaiCount > 10) moyaiCount = 10;
+
+ return moyaiCount;
+}