style: run format:apply and misc lint changes
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import { CommandCategoryInfo } from '../../commands';
|
import { CommandCategoryInfo } from '../../commands';
|
||||||
|
|
||||||
const info: CommandCategoryInfo = {
|
const info: CommandCategoryInfo = {
|
||||||
name: 'Bot',
|
name: 'Bot',
|
||||||
description: 'Bot management commands'
|
description: 'Bot management commands'
|
||||||
};
|
};
|
||||||
|
|
||||||
export default info;
|
export default info;
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import { DataTypes } from 'sequelize';
|
|||||||
import { config } from '../../utils/config';
|
import { config } from '../../utils/config';
|
||||||
import { DatabaseManager } from '../../modules/db';
|
import { DatabaseManager } from '../../modules/db';
|
||||||
|
|
||||||
import * as fs from 'fs';
|
|
||||||
|
|
||||||
const URL_REGEX = /(?:https?|ftp):\/\/[\n\S]+/g;
|
const URL_REGEX = /(?:https?|ftp):\/\/[\n\S]+/g;
|
||||||
const DISCORD_REGEX = /<(?::\w+:|@!*&*|#)[0-9]+>/g; // from: https://www.reddit.com/r/discordapp/comments/iibxms/if_anyone_needs_regex_to_match_an_emote_mention/
|
const DISCORD_REGEX = /<(?::\w+:|@!*&*|#)[0-9]+>/g; // from: https://www.reddit.com/r/discordapp/comments/iibxms/if_anyone_needs_regex_to_match_an_emote_mention/
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,9 @@ import * as https from 'https';
|
|||||||
|
|
||||||
const ELEVENLABS_API_ENDPOINT = 'api.elevenlabs.io';
|
const ELEVENLABS_API_ENDPOINT = 'api.elevenlabs.io';
|
||||||
|
|
||||||
const FIREBASE_API_KEY = "AIzaSyBSsRE_1Os04-bxpd5JTLIniy3UK4OqKys";
|
const FIREBASE_API_KEY = 'AIzaSyBSsRE_1Os04-bxpd5JTLIniy3UK4OqKys';
|
||||||
const FIREBASE_URL = `https://securetoken.googleapis.com/v1/token?key=${FIREBASE_API_KEY}`;
|
const FIREBASE_URL = `https://securetoken.googleapis.com/v1/token?key=${FIREBASE_API_KEY}`;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TO-DO: Implement previous text
|
TO-DO: Implement previous text
|
||||||
*/
|
*/
|
||||||
@@ -74,8 +73,7 @@ export class ElevenLabsTTS implements TTSModule {
|
|||||||
this.settings = ElevenLabsTTS.DEFAULT_SETTINGS;
|
this.settings = ElevenLabsTTS.DEFAULT_SETTINGS;
|
||||||
this.modelId = 'eleven_flash_v2_5';
|
this.modelId = 'eleven_flash_v2_5';
|
||||||
|
|
||||||
if (this.canBeUsed())
|
if (this.canBeUsed()) this.initializationPromise = this.init();
|
||||||
this.initializationPromise = this.init();
|
|
||||||
|
|
||||||
this.setSettings = this.setSettings.bind(this);
|
this.setSettings = this.setSettings.bind(this);
|
||||||
this.setModel = this.setModel.bind(this);
|
this.setModel = this.setModel.bind(this);
|
||||||
@@ -84,10 +82,7 @@ export class ElevenLabsTTS implements TTSModule {
|
|||||||
|
|
||||||
private async init(): Promise<void> {
|
private async init(): Promise<void> {
|
||||||
await this.ensureSession();
|
await this.ensureSession();
|
||||||
await Promise.all([
|
await Promise.all([this.fetchVoices(), this.fetchModels()]);
|
||||||
this.fetchVoices(),
|
|
||||||
this.fetchModels()
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -153,7 +148,10 @@ export class ElevenLabsTTS implements TTSModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
canBeUsed(): boolean {
|
canBeUsed(): boolean {
|
||||||
return config.tts_elevenlabs_refreshtoken != undefined && config.tts_elevenlabs_key != undefined;
|
return (
|
||||||
|
config.tts_elevenlabs_refreshtoken != undefined &&
|
||||||
|
config.tts_elevenlabs_key != undefined
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -244,31 +242,32 @@ export class ElevenLabsTTS implements TTSModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async ensureSession(): Promise<void> {
|
private async ensureSession(): Promise<void> {
|
||||||
if (this.session && Date.now() < this.session.expiresAt - 300000)
|
if (this.session && Date.now() < this.session.expiresAt - 300000) return;
|
||||||
return;
|
|
||||||
|
|
||||||
const refreshToken = this.session?.refreshToken || config.tts_elevenlabs_refreshtoken;
|
const refreshToken =
|
||||||
if (!refreshToken) throw new Error("No refresh token available");
|
this.session?.refreshToken || config.tts_elevenlabs_refreshtoken;
|
||||||
|
if (!refreshToken) throw new Error('No refresh token available');
|
||||||
|
|
||||||
const response = await fetch(FIREBASE_URL, {
|
const response = await fetch(FIREBASE_URL, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
'Referer': 'https://elevenlabs.io/',
|
Referer: 'https://elevenlabs.io/',
|
||||||
'Origin': 'https://elevenlabs.io'
|
Origin: 'https://elevenlabs.io'
|
||||||
},
|
},
|
||||||
body: new URLSearchParams({
|
body: new URLSearchParams({
|
||||||
grant_type: 'refresh_token',
|
grant_type: 'refresh_token',
|
||||||
refresh_token: refreshToken,
|
refresh_token: refreshToken
|
||||||
}),
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) throw new Error(`Auth Refresh Failed: ${await response.text()}`);
|
if (!response.ok)
|
||||||
|
throw new Error(`Auth Refresh Failed: ${await response.text()}`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
this.session = {
|
this.session = {
|
||||||
idToken: data.id_token,
|
idToken: data.id_token,
|
||||||
refreshToken: data.refresh_token,
|
refreshToken: data.refresh_token,
|
||||||
expiresAt: Date.now() + (parseInt(data.expires_in) * 1000)
|
expiresAt: Date.now() + parseInt(data.expires_in) * 1000
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user