Skip to content

Commit

Permalink
Merge pull request #100 from xjuanfxx/master
Browse files Browse the repository at this point in the history
  • Loading branch information
moonstar-x authored Nov 6, 2024
2 parents 57937ab + 91fd1f5 commit 65d79aa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-tts-bot",
"version": "4.1.2",
"version": "4.1.3",
"description": "A simple Discord TTS Bot that uses the Google Translate TTS API.",
"main": "./src/app.js",
"scripts": {
Expand Down
26 changes: 25 additions & 1 deletion src/classes/tts/TTSPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ class TTSPlayer {
}

async say(sentence, providerName, extras = {}) {
// URL Detector
const urlRegex = /(https?:\/\/[^\s]+)/g;

// Replace URL with SUS
const sanitizedSentence = sentence.replace(urlRegex, 'ඞ');

const provider = this.providerManager.getProvider(providerName);
const payload = await provider.createPayload(sentence, extras);
const payload = await provider.createPayload(sanitizedSentence, extras);

if (Array.isArray(payload)) {
payload.forEach((p) => this.queue.enqueue(p));
Expand Down Expand Up @@ -75,6 +81,24 @@ class TTSPlayer {
}));
}

skip() {
this.stopDisconnectScheduler();

if (this.queue.length > 0) {
this.queue.shift();
}

this.speaking = false;
this.voice.player.stop(true);

if (this.queue.length > 0) {
const nextMessage = this.queue[0];
this.say(nextMessage.text, nextMessage.provider, nextMessage.extras);
} else {
this.voice.disconnect();
}
}

stop() {
const { channel } = this.guild.me.voice;

Expand Down

0 comments on commit 65d79aa

Please sign in to comment.