Update index.ts
This commit is contained in:
parent
08a0f04922
commit
9d65780297
1 changed files with 78 additions and 53 deletions
|
|
@ -1,41 +1,18 @@
|
|||
import { defineCorePlugin } from "..";
|
||||
import { findByProps } from "@metro";
|
||||
import { after } from "@lib/api/patcher";
|
||||
import { logger } from "@lib/utils/logger";
|
||||
|
||||
const AUDIO_URL = "https://github.com/OTKUSteyler/GoonCord/raw/refs/heads/main/src/core/plugins/max%20verstappen/Max%20Verstappen.mp3";
|
||||
// Get DCDSoundManager the same way as enhancements plugin
|
||||
const { ReactNative } = window as any;
|
||||
const { DCDSoundManager } = ReactNative?.NativeModules || {};
|
||||
|
||||
const AUDIO_URL = "https://your-audio-link-here.mp3";
|
||||
const SOUND_ID = 6972; // different id from enhancements (6971)
|
||||
const TRIGGER_CHANCE = 0.33;
|
||||
const MAX_PATTERN = /\bmax\s*verstappen\b/i;
|
||||
|
||||
let audioInstance: any = null;
|
||||
|
||||
function playAudio() {
|
||||
try {
|
||||
const Sound = findByProps("play", "stop", "release");
|
||||
if (!Sound) {
|
||||
logger.error("[MaxVerstappen] Could not find audio module");
|
||||
return;
|
||||
}
|
||||
if (audioInstance) {
|
||||
audioInstance.stop();
|
||||
audioInstance.release();
|
||||
audioInstance = null;
|
||||
}
|
||||
audioInstance = new Sound(AUDIO_URL, null, (error: any) => {
|
||||
if (error) {
|
||||
logger.error("[MaxVerstappen] Failed to load audio", error);
|
||||
return;
|
||||
}
|
||||
audioInstance.play((success: boolean) => {
|
||||
if (!success) logger.error("[MaxVerstappen] Playback failed");
|
||||
audioInstance?.release();
|
||||
audioInstance = null;
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
logger.error("[MaxVerstappen] Audio error", e);
|
||||
}
|
||||
}
|
||||
let isPlaying = false;
|
||||
let timeoutId: NodeJS.Timeout | null = null;
|
||||
|
||||
function shouldTrigger(): boolean {
|
||||
return Math.random() < TRIGGER_CHANCE;
|
||||
|
|
@ -45,6 +22,42 @@ function checkText(text: string): boolean {
|
|||
return MAX_PATTERN.test(text) && shouldTrigger();
|
||||
}
|
||||
|
||||
async function playAudio() {
|
||||
if (!DCDSoundManager) {
|
||||
logger.error("[MaxVerstappen] DCDSoundManager not available");
|
||||
return;
|
||||
}
|
||||
|
||||
// Stop if already playing
|
||||
if (isPlaying) {
|
||||
if (timeoutId) clearTimeout(timeoutId);
|
||||
DCDSoundManager.stop(SOUND_ID);
|
||||
isPlaying = false;
|
||||
}
|
||||
|
||||
// Prepare then play
|
||||
DCDSoundManager.prepare(AUDIO_URL, "music", SOUND_ID, async (error: any, sound: any) => {
|
||||
if (error) {
|
||||
logger.error("[MaxVerstappen] Failed to prepare sound:", error);
|
||||
return;
|
||||
}
|
||||
|
||||
isPlaying = true;
|
||||
try {
|
||||
await DCDSoundManager.play(SOUND_ID);
|
||||
const duration = sound?.duration || 5000;
|
||||
timeoutId = setTimeout(() => {
|
||||
DCDSoundManager.stop(SOUND_ID);
|
||||
isPlaying = false;
|
||||
timeoutId = null;
|
||||
}, duration);
|
||||
} catch (e) {
|
||||
logger.error("[MaxVerstappen] Playback error:", e);
|
||||
isPlaying = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default defineCorePlugin({
|
||||
manifest: {
|
||||
id: "bunny.maxverstappen",
|
||||
|
|
@ -55,38 +68,50 @@ export default defineCorePlugin({
|
|||
display: {
|
||||
name: "Max Verstappen",
|
||||
description: "Plays audio when Max Verstappen is mentioned (33% chance)",
|
||||
authors: [{ name: "GoonCord Team" }],
|
||||
authors: [{ name: "your-name" }],
|
||||
},
|
||||
},
|
||||
|
||||
start() {
|
||||
const FluxDispatcher = findByProps("dispatch", "subscribe");
|
||||
if (FluxDispatcher) {
|
||||
FluxDispatcher.subscribe("MESSAGE_CREATE", ({ message }: any) => {
|
||||
if (!message?.content) return;
|
||||
if (checkText(message.content)) {
|
||||
logger.log("[MaxVerstappen] Triggered on received message!");
|
||||
playAudio();
|
||||
}
|
||||
});
|
||||
|
||||
FluxDispatcher.subscribe("MESSAGE_SEND", ({ message }: any) => {
|
||||
if (!message?.content) return;
|
||||
if (checkText(message.content)) {
|
||||
logger.log("[MaxVerstappen] Triggered on sent message!");
|
||||
playAudio();
|
||||
}
|
||||
});
|
||||
if (!DCDSoundManager) {
|
||||
logger.error("[MaxVerstappen] DCDSoundManager not found - plugin disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
const FluxDispatcher = findByProps("dispatch", "subscribe");
|
||||
if (!FluxDispatcher) {
|
||||
logger.error("[MaxVerstappen] FluxDispatcher not found");
|
||||
return;
|
||||
}
|
||||
|
||||
FluxDispatcher.subscribe("MESSAGE_CREATE", ({ message }: any) => {
|
||||
if (!message?.content) return;
|
||||
if (checkText(message.content)) {
|
||||
logger.log("[MaxVerstappen] Triggered!");
|
||||
playAudio();
|
||||
}
|
||||
});
|
||||
|
||||
FluxDispatcher.subscribe("MESSAGE_SEND", ({ message }: any) => {
|
||||
if (!message?.content) return;
|
||||
if (checkText(message.content)) {
|
||||
logger.log("[MaxVerstappen] Triggered on sent message!");
|
||||
playAudio();
|
||||
}
|
||||
});
|
||||
|
||||
logger.log("[MaxVerstappen] Enabled");
|
||||
},
|
||||
|
||||
stop() {
|
||||
if (audioInstance) {
|
||||
audioInstance.stop();
|
||||
audioInstance.release();
|
||||
audioInstance = null;
|
||||
if (DCDSoundManager && isPlaying) {
|
||||
DCDSoundManager.stop(SOUND_ID);
|
||||
isPlaying = false;
|
||||
}
|
||||
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = null;
|
||||
}
|
||||
|
||||
const FluxDispatcher = findByProps("dispatch", "subscribe");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue