2024-03-12 14:05:27 -04:00
|
|
|
using TwitchChatTTS.Helpers;
|
|
|
|
using TwitchChatTTS;
|
2024-01-05 05:07:41 -05:00
|
|
|
using TwitchChatTTS.Hermes;
|
2024-03-12 14:05:27 -04:00
|
|
|
using System.Text.Json;
|
2023-12-30 04:27:31 -05:00
|
|
|
|
|
|
|
public class HermesClient {
|
2024-03-12 14:05:27 -04:00
|
|
|
private Account? account;
|
|
|
|
private WebClientWrap _web;
|
|
|
|
private Configuration Configuration { get; }
|
2023-12-30 04:27:31 -05:00
|
|
|
|
2024-03-12 14:05:27 -04:00
|
|
|
public string? Id { get => account?.Id; }
|
|
|
|
public string? Username { get => account?.Username; }
|
2023-12-30 04:27:31 -05:00
|
|
|
|
|
|
|
|
2024-03-12 14:05:27 -04:00
|
|
|
public HermesClient(Configuration configuration) {
|
|
|
|
Configuration = configuration;
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(Configuration.Hermes?.Token)) {
|
2023-12-30 04:27:31 -05:00
|
|
|
throw new Exception("Ensure you have written your API key in \".token\" file, in the same folder as this application.");
|
|
|
|
}
|
|
|
|
|
2024-03-12 14:05:27 -04:00
|
|
|
_web = new WebClientWrap(new JsonSerializerOptions() {
|
|
|
|
PropertyNameCaseInsensitive = false,
|
|
|
|
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
|
|
|
});
|
|
|
|
_web.AddHeader("x-api-key", Configuration.Hermes.Token);
|
2023-12-30 04:27:31 -05:00
|
|
|
}
|
|
|
|
|
2024-03-12 14:05:27 -04:00
|
|
|
public async Task FetchHermesAccountDetails() {
|
2024-01-05 05:07:41 -05:00
|
|
|
account = await _web.GetJson<Account>("https://hermes.goblincaves.com/api/account");
|
2023-12-30 04:27:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<TwitchBotToken> FetchTwitchBotToken() {
|
2024-01-05 05:07:41 -05:00
|
|
|
var token = await _web.GetJson<TwitchBotToken>("https://hermes.goblincaves.com/api/token/bot");
|
2023-12-30 04:27:31 -05:00
|
|
|
if (token == null) {
|
|
|
|
throw new Exception("Failed to fetch Twitch API token from Hermes.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return token;
|
|
|
|
}
|
2024-01-05 05:07:41 -05:00
|
|
|
|
|
|
|
public async Task<IEnumerable<TTSUsernameFilter>> FetchTTSUsernameFilters() {
|
|
|
|
var filters = await _web.GetJson<IEnumerable<TTSUsernameFilter>>("https://hermes.goblincaves.com/api/settings/tts/filter/users");
|
|
|
|
if (filters == null) {
|
|
|
|
throw new Exception("Failed to fetch TTS username filters from Hermes.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return filters;
|
|
|
|
}
|
|
|
|
|
2024-03-12 14:05:27 -04:00
|
|
|
public async Task<string?> FetchTTSDefaultVoice() {
|
2024-01-05 05:07:41 -05:00
|
|
|
var data = await _web.GetJson<TTSVoice>("https://hermes.goblincaves.com/api/settings/tts/default");
|
|
|
|
if (data == null) {
|
|
|
|
throw new Exception("Failed to fetch TTS default voice from Hermes.");
|
|
|
|
}
|
|
|
|
|
2024-03-12 14:05:27 -04:00
|
|
|
return data.Label;
|
2024-01-05 05:07:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<IEnumerable<TTSVoice>> FetchTTSEnabledVoices() {
|
|
|
|
var voices = await _web.GetJson<IEnumerable<TTSVoice>>("https://hermes.goblincaves.com/api/settings/tts");
|
|
|
|
if (voices == null) {
|
|
|
|
throw new Exception("Failed to fetch TTS enabled voices from Hermes.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return voices;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<IEnumerable<TTSWordFilter>> FetchTTSWordFilters() {
|
|
|
|
var filters = await _web.GetJson<IEnumerable<TTSWordFilter>>("https://hermes.goblincaves.com/api/settings/tts/filter/words");
|
|
|
|
if (filters == null) {
|
|
|
|
throw new Exception("Failed to fetch TTS word filters from Hermes.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return filters;
|
|
|
|
}
|
2023-12-30 04:27:31 -05:00
|
|
|
}
|