First commit with progress so far
This commit is contained in:
9
TwitchChatTTS/Hermes/Account.cs
Normal file
9
TwitchChatTTS/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; }
|
||||
}
|
37
TwitchChatTTS/Hermes/HermesClient.cs
Normal file
37
TwitchChatTTS/Hermes/HermesClient.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
public class HermesClient {
|
||||
private Account account;
|
||||
private string key;
|
||||
|
||||
public string Id { get => account?.id; }
|
||||
public string Username { get => account?.username; }
|
||||
|
||||
|
||||
public HermesClient() {
|
||||
// Read API Key from file.
|
||||
if (!File.Exists(".token")) {
|
||||
throw new Exception("Ensure you have written your API key in \".token\" file, in the same folder as this application.");
|
||||
}
|
||||
|
||||
key = File.ReadAllText(".token")?.Trim();
|
||||
WebHelper.AddHeader("x-api-key", key);
|
||||
}
|
||||
|
||||
public async Task UpdateHermesAccount() {
|
||||
account = await WebHelper.GetJson<Account>("https://hermes.goblincaves.com/api/account");
|
||||
}
|
||||
|
||||
public async Task<TwitchBotToken> FetchTwitchBotToken() {
|
||||
if (string.IsNullOrWhiteSpace(key)) {
|
||||
throw new InvalidOperationException("Hermes API key not provided.");
|
||||
}
|
||||
|
||||
var token = await WebHelper.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;
|
||||
}
|
||||
}
|
8
TwitchChatTTS/Hermes/TwitchBotToken.cs
Normal file
8
TwitchChatTTS/Hermes/TwitchBotToken.cs
Normal file
@ -0,0 +1,8 @@
|
||||
[Serializable]
|
||||
public class TwitchBotToken {
|
||||
public string client_id { get; set; }
|
||||
public string client_secret { get; set; }
|
||||
public string access_token { get; set; }
|
||||
public string refresh_token { get; set; }
|
||||
public string broadcaster_id { get; set; }
|
||||
}
|
8
TwitchChatTTS/Hermes/TwitchConnection.cs
Normal file
8
TwitchChatTTS/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