2024-03-12 14:05:27 -04:00
|
|
|
using TwitchChatTTS.Helpers;
|
|
|
|
using TwitchChatTTS;
|
|
|
|
using System.Text.Json;
|
2024-06-16 20:19:31 -04:00
|
|
|
using HermesSocketLibrary.Requests.Messages;
|
|
|
|
using TwitchChatTTS.Hermes;
|
2024-06-24 18:11:36 -04:00
|
|
|
using TwitchChatTTS.Twitch.Redemptions;
|
2023-12-30 04:27:31 -05:00
|
|
|
|
2024-06-16 20:19:31 -04:00
|
|
|
public class HermesApiClient
|
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
private readonly WebClientWrap _web;
|
2023-12-30 04:27:31 -05:00
|
|
|
|
2024-06-16 20:19:31 -04:00
|
|
|
public HermesApiClient(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-06-16 20:19:31 -04:00
|
|
|
_web = new WebClientWrap(new JsonSerializerOptions()
|
|
|
|
{
|
2024-03-12 14:05:27 -04:00
|
|
|
PropertyNameCaseInsensitive = false,
|
|
|
|
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
|
|
|
});
|
2024-03-15 08:27:35 -04:00
|
|
|
_web.AddHeader("x-api-key", configuration.Hermes.Token);
|
2023-12-30 04:27:31 -05:00
|
|
|
}
|
|
|
|
|
2024-06-16 20:19:31 -04:00
|
|
|
public async Task<TTSVersion> GetTTSVersion()
|
|
|
|
{
|
|
|
|
var version = await _web.GetJson<TTSVersion>("https://hermes.goblincaves.com/api/info/version");
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<Account> FetchHermesAccountDetails()
|
|
|
|
{
|
2024-03-15 08:27:35 -04:00
|
|
|
var account = await _web.GetJson<Account>("https://hermes.goblincaves.com/api/account");
|
|
|
|
if (account == null || account.Id == null || account.Username == null)
|
|
|
|
throw new NullReferenceException("Invalid value found while fetching for hermes account data.");
|
|
|
|
return account;
|
2023-12-30 04:27:31 -05:00
|
|
|
}
|
|
|
|
|
2024-06-16 20:19:31 -04: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");
|
2024-03-15 08:27:35 -04:00
|
|
|
if (token == null || token.ClientId == null || token.AccessToken == null || token.RefreshToken == null || token.ClientSecret == null)
|
2023-12-30 04:27:31 -05:00
|
|
|
throw new Exception("Failed to fetch Twitch API token from Hermes.");
|
|
|
|
|
|
|
|
return token;
|
|
|
|
}
|
2024-01-05 05:07:41 -05:00
|
|
|
|
2024-06-16 20:19:31 -04:00
|
|
|
public async Task<IEnumerable<TTSUsernameFilter>> FetchTTSUsernameFilters()
|
|
|
|
{
|
2024-01-05 05:07:41 -05:00
|
|
|
var filters = await _web.GetJson<IEnumerable<TTSUsernameFilter>>("https://hermes.goblincaves.com/api/settings/tts/filter/users");
|
2024-03-15 08:27:35 -04:00
|
|
|
if (filters == null)
|
2024-01-05 05:07:41 -05:00
|
|
|
throw new Exception("Failed to fetch TTS username filters from Hermes.");
|
|
|
|
|
|
|
|
return filters;
|
|
|
|
}
|
|
|
|
|
2024-06-16 20:19:31 -04:00
|
|
|
public async Task<string> FetchTTSDefaultVoice()
|
|
|
|
{
|
|
|
|
var data = await _web.GetJson<string>("https://hermes.goblincaves.com/api/settings/tts/default");
|
2024-03-15 08:27:35 -04:00
|
|
|
if (data == null)
|
2024-01-05 05:07:41 -05:00
|
|
|
throw new Exception("Failed to fetch TTS default voice from Hermes.");
|
|
|
|
|
2024-06-16 20:19:31 -04:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<IEnumerable<TTSChatterSelectedVoice>> FetchTTSChatterSelectedVoices()
|
|
|
|
{
|
|
|
|
var voices = await _web.GetJson<IEnumerable<TTSChatterSelectedVoice>>("https://hermes.goblincaves.com/api/settings/tts/selected");
|
|
|
|
if (voices == null)
|
|
|
|
throw new Exception("Failed to fetch TTS chatter selected voices from Hermes.");
|
|
|
|
|
|
|
|
return voices;
|
2024-01-05 05:07:41 -05:00
|
|
|
}
|
|
|
|
|
2024-06-16 20:19:31 -04:00
|
|
|
public async Task<IEnumerable<string>> FetchTTSEnabledVoices()
|
|
|
|
{
|
|
|
|
var voices = await _web.GetJson<IEnumerable<string>>("https://hermes.goblincaves.com/api/settings/tts");
|
2024-03-15 08:27:35 -04:00
|
|
|
if (voices == null)
|
2024-01-05 05:07:41 -05:00
|
|
|
throw new Exception("Failed to fetch TTS enabled voices from Hermes.");
|
|
|
|
|
|
|
|
return voices;
|
|
|
|
}
|
|
|
|
|
2024-06-16 20:19:31 -04:00
|
|
|
public async Task<IEnumerable<TTSWordFilter>> FetchTTSWordFilters()
|
|
|
|
{
|
2024-01-05 05:07:41 -05:00
|
|
|
var filters = await _web.GetJson<IEnumerable<TTSWordFilter>>("https://hermes.goblincaves.com/api/settings/tts/filter/words");
|
2024-03-15 08:27:35 -04:00
|
|
|
if (filters == null)
|
2024-01-05 05:07:41 -05:00
|
|
|
throw new Exception("Failed to fetch TTS word filters from Hermes.");
|
|
|
|
|
|
|
|
return filters;
|
|
|
|
}
|
2024-06-24 18:11:36 -04:00
|
|
|
|
|
|
|
public async Task<IEnumerable<Redemption>> FetchRedemptions()
|
|
|
|
{
|
|
|
|
var redemptions = await _web.GetJson<IEnumerable<Redemption>>("https://hermes.goblincaves.com/api/settings/redemptions", new JsonSerializerOptions()
|
|
|
|
{
|
|
|
|
PropertyNameCaseInsensitive = false,
|
|
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
|
|
|
});
|
|
|
|
if (redemptions == null)
|
|
|
|
throw new Exception("Failed to redemptions from Hermes.");
|
|
|
|
|
|
|
|
return redemptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<IEnumerable<RedeemableAction>> FetchRedeemableActions()
|
|
|
|
{
|
|
|
|
var actions = await _web.GetJson<IEnumerable<RedeemableAction>>("https://hermes.goblincaves.com/api/settings/redemptions/actions");
|
|
|
|
if (actions == null)
|
|
|
|
throw new Exception("Failed to fetch redeemable actions from Hermes.");
|
|
|
|
|
|
|
|
return actions;
|
|
|
|
}
|
2023-12-30 04:27:31 -05:00
|
|
|
}
|