Cleaned code up. Added OBS & 7tv ws support. Added dependency injection. App loads from yml file.
This commit is contained in:
9
Hermes/Account.cs
Normal file
9
Hermes/Account.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
[Serializable]
|
||||
public class Account {
|
||||
[AllowNull]
|
||||
public string Id { get; set; }
|
||||
[AllowNull]
|
||||
public string Username { get; set; }
|
||||
}
|
77
Hermes/HermesClient.cs
Normal file
77
Hermes/HermesClient.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using TwitchChatTTS.Helpers;
|
||||
using TwitchChatTTS;
|
||||
using TwitchChatTTS.Hermes;
|
||||
using System.Text.Json;
|
||||
|
||||
public class HermesClient {
|
||||
private Account? account;
|
||||
private WebClientWrap _web;
|
||||
private Configuration Configuration { get; }
|
||||
|
||||
public string? Id { get => account?.Id; }
|
||||
public string? Username { get => account?.Username; }
|
||||
|
||||
|
||||
public HermesClient(Configuration configuration) {
|
||||
Configuration = configuration;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Configuration.Hermes?.Token)) {
|
||||
throw new Exception("Ensure you have written your API key in \".token\" file, in the same folder as this application.");
|
||||
}
|
||||
|
||||
_web = new WebClientWrap(new JsonSerializerOptions() {
|
||||
PropertyNameCaseInsensitive = false,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
||||
});
|
||||
_web.AddHeader("x-api-key", Configuration.Hermes.Token);
|
||||
}
|
||||
|
||||
public async Task FetchHermesAccountDetails() {
|
||||
account = await _web.GetJson<Account>("https://hermes.goblincaves.com/api/account");
|
||||
}
|
||||
|
||||
public async Task<TwitchBotToken> FetchTwitchBotToken() {
|
||||
var token = await _web.GetJson<TwitchBotToken>("https://hermes.goblincaves.com/api/token/bot");
|
||||
if (token == null) {
|
||||
throw new Exception("Failed to fetch Twitch API token from Hermes.");
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public async Task<string?> FetchTTSDefaultVoice() {
|
||||
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.");
|
||||
}
|
||||
|
||||
return data.Label;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
5
Hermes/TTSUsernameFilter.cs
Normal file
5
Hermes/TTSUsernameFilter.cs
Normal file
@ -0,0 +1,5 @@
|
||||
public class TTSUsernameFilter {
|
||||
public string? Username { get; set; }
|
||||
public string? Tag { get; set; }
|
||||
public string? UserId { get; set; }
|
||||
}
|
6
Hermes/TTSVoice.cs
Normal file
6
Hermes/TTSVoice.cs
Normal file
@ -0,0 +1,6 @@
|
||||
public class TTSVoice {
|
||||
public string? Label { get; set; }
|
||||
public int Value { get; set; }
|
||||
public string? Gender { get; set; }
|
||||
public string? Language { get; set; }
|
||||
}
|
22
Hermes/TTSWordFilter.cs
Normal file
22
Hermes/TTSWordFilter.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TwitchChatTTS.Hermes
|
||||
{
|
||||
public class TTSWordFilter
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Search { get; set; }
|
||||
public string? Replace { get; set; }
|
||||
public string? UserId { get; set; }
|
||||
|
||||
public bool IsRegex { get; set; }
|
||||
|
||||
|
||||
public TTSWordFilter() {
|
||||
IsRegex = true;
|
||||
}
|
||||
}
|
||||
}
|
7
Hermes/TwitchBotAuth.cs
Normal file
7
Hermes/TwitchBotAuth.cs
Normal file
@ -0,0 +1,7 @@
|
||||
[Serializable]
|
||||
public class TwitchBotAuth {
|
||||
public string? UserId { get; set; }
|
||||
public string? AccessToken { get; set; }
|
||||
public string? RefreshToken { get; set; }
|
||||
public string? BroadcasterId { get; set; }
|
||||
}
|
8
Hermes/TwitchBotToken.cs
Normal file
8
Hermes/TwitchBotToken.cs
Normal file
@ -0,0 +1,8 @@
|
||||
[Serializable]
|
||||
public class TwitchBotToken {
|
||||
public string? ClientId { get; set; }
|
||||
public string? ClientSecret { get; set; }
|
||||
public string? AccessToken { get; set; }
|
||||
public string? RefreshToken { get; set; }
|
||||
public string? BroadcasterId { get; set; }
|
||||
}
|
8
Hermes/TwitchConnection.cs
Normal file
8
Hermes/TwitchConnection.cs
Normal file
@ -0,0 +1,8 @@
|
||||
[Serializable]
|
||||
public class TwitchConnection {
|
||||
public string? Id { get; set; }
|
||||
public string? Secret { get; set; }
|
||||
public string? BroadcasterId { get; set; }
|
||||
public string? Username { get; set; }
|
||||
public string? UserId { get; set; }
|
||||
}
|
Reference in New Issue
Block a user