2022-10-21 23:17:06 +00:00
|
|
|
/*
|
|
|
|
* Vencord, a modification for Discord's desktop app
|
|
|
|
* Copyright (c) 2022 Vendicated and contributors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-05-05 23:36:00 +00:00
|
|
|
import { definePluginSettings } from "@api/Settings";
|
2022-11-28 12:37:55 +00:00
|
|
|
import { makeRange } from "@components/PluginSettings/components/SettingSliderComponent";
|
|
|
|
import { Devs } from "@utils/constants";
|
|
|
|
import { sleep } from "@utils/misc";
|
|
|
|
import definePlugin, { OptionType } from "@utils/types";
|
2023-06-25 16:31:39 +00:00
|
|
|
import { RelationshipStore, SelectedChannelStore, UserStore } from "@webpack/common";
|
2022-10-09 17:48:22 +00:00
|
|
|
import { Message, ReactionEmoji } from "discord-types/general";
|
2022-10-19 19:57:27 +00:00
|
|
|
|
2022-10-09 16:18:18 +00:00
|
|
|
interface IMessageCreate {
|
|
|
|
type: "MESSAGE_CREATE";
|
|
|
|
optimistic: boolean;
|
2022-10-09 17:48:22 +00:00
|
|
|
isPushNotification: boolean;
|
|
|
|
channelId: string;
|
2022-10-09 16:18:18 +00:00
|
|
|
message: Message;
|
|
|
|
}
|
|
|
|
|
2022-10-09 17:48:22 +00:00
|
|
|
interface IReactionAdd {
|
|
|
|
type: "MESSAGE_REACTION_ADD";
|
|
|
|
optimistic: boolean;
|
|
|
|
channelId: string;
|
|
|
|
messageId: string;
|
2023-06-25 16:31:39 +00:00
|
|
|
messageAuthorId: string;
|
2022-10-09 17:48:22 +00:00
|
|
|
userId: "195136840355807232";
|
|
|
|
emoji: ReactionEmoji;
|
|
|
|
}
|
|
|
|
|
2022-11-10 13:04:06 +00:00
|
|
|
interface IVoiceChannelEffectSendEvent {
|
|
|
|
type: string;
|
|
|
|
emoji?: ReactionEmoji; // Just in case...
|
|
|
|
channelId: string;
|
|
|
|
userId: string;
|
|
|
|
animationType: number;
|
|
|
|
animationId: number;
|
|
|
|
}
|
|
|
|
|
2022-10-09 17:48:22 +00:00
|
|
|
const MOYAI = "🗿";
|
2022-10-09 16:18:18 +00:00
|
|
|
const MOYAI_URL =
|
2022-10-15 17:07:44 +00:00
|
|
|
"https://raw.githubusercontent.com/MeguminSama/VencordPlugins/main/plugins/moyai/moyai.mp3";
|
2022-10-09 16:18:18 +00:00
|
|
|
|
2023-03-08 03:11:59 +00:00
|
|
|
const settings = definePluginSettings({
|
|
|
|
volume: {
|
|
|
|
description: "Volume of the 🗿🗿🗿",
|
|
|
|
type: OptionType.SLIDER,
|
|
|
|
markers: makeRange(0, 1, 0.1),
|
|
|
|
default: 0.5,
|
|
|
|
stickToMarkers: false
|
|
|
|
},
|
|
|
|
triggerWhenUnfocused: {
|
|
|
|
description: "Trigger the 🗿 even when the window is unfocused",
|
|
|
|
type: OptionType.BOOLEAN,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
ignoreBots: {
|
|
|
|
description: "Ignore bots",
|
|
|
|
type: OptionType.BOOLEAN,
|
|
|
|
default: true
|
2023-06-25 16:31:39 +00:00
|
|
|
},
|
|
|
|
ignoreBlocked: {
|
|
|
|
description: "Ignore blocked users",
|
|
|
|
type: OptionType.BOOLEAN,
|
|
|
|
default: true
|
2023-03-08 03:11:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-10-09 16:18:18 +00:00
|
|
|
export default definePlugin({
|
|
|
|
name: "Moyai",
|
2022-10-20 05:48:46 +00:00
|
|
|
authors: [Devs.Megu, Devs.Nuckyz],
|
2022-10-09 16:18:18 +00:00
|
|
|
description: "🗿🗿🗿🗿🗿🗿🗿🗿",
|
2023-03-08 03:11:59 +00:00
|
|
|
settings,
|
2022-10-09 16:18:18 +00:00
|
|
|
|
2023-04-22 01:18:19 +00:00
|
|
|
flux: {
|
|
|
|
async MESSAGE_CREATE({ optimistic, type, message, channelId }: IMessageCreate) {
|
|
|
|
if (optimistic || type !== "MESSAGE_CREATE") return;
|
|
|
|
if (message.state === "SENDING") return;
|
|
|
|
if (settings.store.ignoreBots && message.author?.bot) return;
|
2023-06-25 16:31:39 +00:00
|
|
|
if (settings.store.ignoreBlocked && RelationshipStore.isBlocked(message.author?.id)) return;
|
2023-04-22 01:18:19 +00:00
|
|
|
if (!message.content) return;
|
|
|
|
if (channelId !== SelectedChannelStore.getChannelId()) return;
|
2022-10-09 16:18:18 +00:00
|
|
|
|
2023-04-22 01:18:19 +00:00
|
|
|
const moyaiCount = getMoyaiCount(message.content);
|
2022-10-09 16:18:18 +00:00
|
|
|
|
2023-04-22 01:18:19 +00:00
|
|
|
for (let i = 0; i < moyaiCount; i++) {
|
|
|
|
boom();
|
|
|
|
await sleep(300);
|
|
|
|
}
|
|
|
|
},
|
2022-10-09 17:48:22 +00:00
|
|
|
|
2023-06-25 16:31:39 +00:00
|
|
|
MESSAGE_REACTION_ADD({ optimistic, type, channelId, userId, messageAuthorId, emoji }: IReactionAdd) {
|
2023-04-22 01:18:19 +00:00
|
|
|
if (optimistic || type !== "MESSAGE_REACTION_ADD") return;
|
|
|
|
if (settings.store.ignoreBots && UserStore.getUser(userId)?.bot) return;
|
2023-06-25 16:31:39 +00:00
|
|
|
if (settings.store.ignoreBlocked && RelationshipStore.isBlocked(messageAuthorId)) return;
|
2023-04-22 01:18:19 +00:00
|
|
|
if (channelId !== SelectedChannelStore.getChannelId()) return;
|
2022-10-09 17:48:22 +00:00
|
|
|
|
2023-04-22 01:18:19 +00:00
|
|
|
const name = emoji.name.toLowerCase();
|
|
|
|
if (name !== MOYAI && !name.includes("moyai") && !name.includes("moai")) return;
|
2022-11-10 13:04:06 +00:00
|
|
|
|
2023-04-22 01:18:19 +00:00
|
|
|
boom();
|
|
|
|
},
|
2022-11-10 13:04:06 +00:00
|
|
|
|
2023-04-22 01:18:19 +00:00
|
|
|
VOICE_CHANNEL_EFFECT_SEND({ emoji }: IVoiceChannelEffectSendEvent) {
|
|
|
|
if (!emoji?.name) return;
|
|
|
|
const name = emoji.name.toLowerCase();
|
|
|
|
if (name !== MOYAI && !name.includes("moyai") && !name.includes("moai")) return;
|
2022-10-09 17:48:22 +00:00
|
|
|
|
2023-04-22 01:18:19 +00:00
|
|
|
boom();
|
|
|
|
}
|
2022-10-19 19:57:27 +00:00
|
|
|
}
|
2022-10-09 16:18:18 +00:00
|
|
|
});
|
|
|
|
|
2022-10-09 17:48:22 +00:00
|
|
|
function countOccurrences(sourceString: string, subString: string) {
|
|
|
|
let i = 0;
|
|
|
|
let lastIdx = 0;
|
|
|
|
while ((lastIdx = sourceString.indexOf(subString, lastIdx) + 1) !== 0)
|
|
|
|
i++;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
2022-10-09 16:18:18 +00:00
|
|
|
|
2022-10-09 17:48:22 +00:00
|
|
|
function countMatches(sourceString: string, pattern: RegExp) {
|
|
|
|
if (!pattern.global)
|
|
|
|
throw new Error("pattern must be global");
|
2022-10-09 16:18:18 +00:00
|
|
|
|
2022-10-09 17:48:22 +00:00
|
|
|
let i = 0;
|
|
|
|
while (pattern.test(sourceString))
|
|
|
|
i++;
|
2022-10-09 16:18:18 +00:00
|
|
|
|
2022-10-09 17:48:22 +00:00
|
|
|
return i;
|
|
|
|
}
|
2022-10-09 16:18:18 +00:00
|
|
|
|
2022-10-09 17:48:22 +00:00
|
|
|
const customMoyaiRe = /<a?:\w*moy?ai\w*:\d{17,20}>/gi;
|
|
|
|
|
|
|
|
function getMoyaiCount(message: string) {
|
2022-10-20 09:58:20 +00:00
|
|
|
const count = countOccurrences(message, MOYAI)
|
2022-10-09 17:48:22 +00:00
|
|
|
+ countMatches(message, customMoyaiRe);
|
|
|
|
|
|
|
|
return Math.min(count, 10);
|
|
|
|
}
|
2022-10-09 16:18:18 +00:00
|
|
|
|
2022-10-09 17:48:22 +00:00
|
|
|
function boom() {
|
2023-03-08 03:11:59 +00:00
|
|
|
if (!settings.store.triggerWhenUnfocused && !document.hasFocus()) return;
|
2022-10-09 17:48:22 +00:00
|
|
|
const audioElement = document.createElement("audio");
|
|
|
|
audioElement.src = MOYAI_URL;
|
2023-03-08 03:11:59 +00:00
|
|
|
audioElement.volume = settings.store.volume;
|
2022-10-09 17:48:22 +00:00
|
|
|
audioElement.play();
|
2022-10-09 16:18:18 +00:00
|
|
|
}
|