mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 17:58:26 -04:00
Patreon Access and Refresh Tokens should now be automatically updated
This commit is contained in:
@@ -10,7 +10,14 @@ using Serilog;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
{
|
||||
public sealed class BotCredsProvider
|
||||
public interface IBotCredsProvider
|
||||
{
|
||||
public void Reload();
|
||||
public IBotCredentials GetCreds();
|
||||
public void ModifyCredsFile(Action<Creds> func);
|
||||
}
|
||||
|
||||
public sealed class BotCredsProvider : IBotCredsProvider
|
||||
{
|
||||
private readonly int? _totalShards;
|
||||
private const string _credsFileName = "creds.yml";
|
||||
@@ -27,7 +34,7 @@ namespace NadekoBot.Services
|
||||
|
||||
|
||||
private readonly object reloadLock = new object();
|
||||
private void Reload()
|
||||
public void Reload()
|
||||
{
|
||||
lock (reloadLock)
|
||||
{
|
||||
@@ -102,6 +109,19 @@ namespace NadekoBot.Services
|
||||
Reload();
|
||||
}
|
||||
|
||||
public void ModifyCredsFile(Action<Creds> func)
|
||||
{
|
||||
var ymlData = File.ReadAllText(_credsFileName);
|
||||
var creds = Yaml.Deserializer.Deserialize<Creds>(ymlData);
|
||||
|
||||
func(creds);
|
||||
|
||||
ymlData = Yaml.Serializer.Serialize(creds);
|
||||
File.WriteAllText(_credsFileName, ymlData);
|
||||
|
||||
Reload();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if there's a V2 credentials file present, loads it if it exists,
|
||||
/// converts it to new model, and saves it to YAML. Also backs up old credentials to credentials.json.bak
|
||||
@@ -157,6 +177,6 @@ namespace NadekoBot.Services
|
||||
|
||||
}
|
||||
|
||||
public Creds GetCreds() => _creds;
|
||||
public IBotCredentials GetCreds() => _creds;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user