Move creds.yml to data/creds.yml, update versions from v5 to v6 everywhere
This commit is contained in:
parent
0ea185f769
commit
acdb707a31
6 changed files with 34 additions and 62 deletions
.gitignore
src/EllieBot
Bot.csProgram.cs
Modules
Administration/Self
Searches/_common/StreamNotifications/Providers
_common/Impl
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -7,18 +7,12 @@ src/EllieBot/data/marmalades/
|
|||
|
||||
# other
|
||||
|
||||
command_errors*.txt
|
||||
output/
|
||||
src/EllieBot/output
|
||||
src/EllieBot/creds.yml
|
||||
|
||||
src/EllieBot/data/creds.yml
|
||||
src/EllieBot/Command Errors*.txt
|
||||
|
||||
src/EllieBot/creds.yml
|
||||
# credentials file before and after v3
|
||||
src/EllieBot/credentials.json
|
||||
src/EllieBot/old_credentials.json
|
||||
src/EllieBot/credentials.json.bak
|
||||
src/EllieBot/data/EllieBot.db
|
||||
# scripts
|
||||
ellie-menu.ps1
|
||||
|
|
|
@ -17,7 +17,7 @@ public sealed class Bot : IBot
|
|||
private IContainer Services { get; set; }
|
||||
|
||||
public bool IsReady { get; private set; }
|
||||
public int ShardId { get; set; }
|
||||
public int ShardId { get; }
|
||||
|
||||
private readonly IBotCreds _creds;
|
||||
private readonly CommandService _commandService;
|
||||
|
@ -28,12 +28,12 @@ public sealed class Bot : IBot
|
|||
private readonly Assembly[] _loadedAssemblies;
|
||||
// private readonly InteractionService _interactionService;
|
||||
|
||||
public Bot(int shardId, int? totalShards, string credPath = null)
|
||||
public Bot(int shardId, int? totalShards)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(shardId, 0);
|
||||
|
||||
ShardId = shardId;
|
||||
_credsProvider = new BotCredsProvider(totalShards, credPath);
|
||||
_credsProvider = new BotCredsProvider(totalShards);
|
||||
_creds = _credsProvider.GetCreds();
|
||||
|
||||
LogSetup.SetupLogger(shardId, _creds);
|
||||
|
@ -286,7 +286,7 @@ public sealed class Bot : IBot
|
|||
|
||||
Log.Information("Initializing Owner Id...");
|
||||
var info = await Client.GetApplicationInfoAsync();
|
||||
_credsProvider.ModifyCredsFile(x => x.OwnerIds = new[] { info.Owner.Id });
|
||||
_credsProvider.ModifyCredsFile(x => x.OwnerIds = [info.Owner.Id]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -10,47 +10,33 @@ public sealed class ToastielabReleaseModel
|
|||
[JsonPropertyName("tag_name")]
|
||||
public required string TagName { get; init; }
|
||||
}
|
||||
public sealed class CheckForUpdatesService : IEService, IReadyExecutor
|
||||
|
||||
public sealed class CheckForUpdatesService(
|
||||
BotConfigService bcs,
|
||||
IBotCredsProvider bcp,
|
||||
IHttpClientFactory httpFactory,
|
||||
DiscordSocketClient client,
|
||||
IMessageSenderService sender)
|
||||
: IEService, IReadyExecutor
|
||||
{
|
||||
private readonly BotConfigService _bcs;
|
||||
private readonly IBotCredsProvider _bcp;
|
||||
private readonly IHttpClientFactory _httpFactory;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly IMessageSenderService _sender;
|
||||
|
||||
|
||||
private const string RELEASES_URL = "https://toastielab.dev/api/v1/repos/EllieBotDevs/elliebot/releases";
|
||||
|
||||
public CheckForUpdatesService(
|
||||
BotConfigService bcs,
|
||||
IBotCredsProvider bcp,
|
||||
IHttpClientFactory httpFactory,
|
||||
DiscordSocketClient client,
|
||||
IMessageSenderService sender)
|
||||
{
|
||||
_bcs = bcs;
|
||||
_bcp = bcp;
|
||||
_httpFactory = httpFactory;
|
||||
_client = client;
|
||||
_sender = sender;
|
||||
}
|
||||
|
||||
public async Task OnReadyAsync()
|
||||
{
|
||||
if (_client.ShardId != 0)
|
||||
if (client.ShardId != 0)
|
||||
return;
|
||||
|
||||
using var timer = new PeriodicTimer(TimeSpan.FromHours(1));
|
||||
while (await timer.WaitForNextTickAsync())
|
||||
{
|
||||
var conf = _bcs.Data;
|
||||
var conf = bcs.Data;
|
||||
|
||||
if (!conf.CheckForUpdates)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
using var http = _httpFactory.CreateClient();
|
||||
using var http = httpFactory.CreateClient();
|
||||
var toastielabRelease = (await http.GetFromJsonAsync<ToastielabReleaseModel[]>(RELEASES_URL))
|
||||
?.FirstOrDefault();
|
||||
|
||||
|
@ -72,7 +58,7 @@ public sealed class CheckForUpdatesService : IEService, IReadyExecutor
|
|||
UpdateLastKnownVersion(latestVersion);
|
||||
|
||||
// pull changelog
|
||||
var changelog = await http.GetStringAsync("https://toastielab.dev/EllieBotDevs/elliebot/raw/branch/v5/CHANGELOG.md");
|
||||
var changelog = await http.GetStringAsync("https://toastielab.dev/EllieBotDevs/elliebot/raw/branch/v6/CHANGELOG.md");
|
||||
|
||||
var thisVersionChangelog = GetVersionChangelog(latestVersion, changelog);
|
||||
|
||||
|
@ -83,24 +69,24 @@ public sealed class CheckForUpdatesService : IEService, IReadyExecutor
|
|||
continue;
|
||||
}
|
||||
|
||||
var creds = _bcp.GetCreds();
|
||||
var creds = bcp.GetCreds();
|
||||
await creds.OwnerIds
|
||||
.Select(async x =>
|
||||
{
|
||||
var user = await _client.GetUserAsync(x);
|
||||
var user = await client.GetUserAsync(x);
|
||||
if (user is null)
|
||||
return;
|
||||
|
||||
var eb = _sender.CreateEmbed()
|
||||
var eb = sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithAuthor($"EllieBot v{latest} Released!")
|
||||
.WithTitle("Changelog")
|
||||
.WithUrl("https://toastielab.dev/EllieBotDevs/elliebot/src/branch/v5/CHANGELOG.md")
|
||||
.WithUrl("https://toastielab.dev/EllieBotDevs/elliebot/src/branch/v6/CHANGELOG.md")
|
||||
.WithDescription(thisVersionChangelog.TrimTo(4096))
|
||||
.WithFooter(
|
||||
"You may disable these messages by typing '.conf bot checkforupdates false'");
|
||||
|
||||
await _sender.Response(user).Embed(eb).SendAsync();
|
||||
await sender.Response(user).Embed(eb).SendAsync();
|
||||
})
|
||||
.WhenAll();
|
||||
}
|
||||
|
@ -152,7 +138,7 @@ public sealed class CheckForUpdatesService : IEService, IReadyExecutor
|
|||
|
||||
private const string LAST_KNOWN_VERSION_PATH = "data/last_known_version.txt";
|
||||
|
||||
private Version? GetLastKnownVersion()
|
||||
private static Version? GetLastKnownVersion()
|
||||
{
|
||||
if (!File.Exists(LAST_KNOWN_VERSION_PATH))
|
||||
return null;
|
||||
|
@ -162,8 +148,8 @@ public sealed class CheckForUpdatesService : IEService, IReadyExecutor
|
|||
: null;
|
||||
}
|
||||
|
||||
private void UpdateLastKnownVersion(Version version)
|
||||
private static void UpdateLastKnownVersion(Version version)
|
||||
{
|
||||
File.WriteAllText("data/last_known_version.txt", version.ToString());
|
||||
File.WriteAllText(LAST_KNOWN_VERSION_PATH, version.ToString());
|
||||
}
|
||||
}
|
|
@ -124,7 +124,7 @@ public sealed class TwitchHelixProvider : Provider
|
|||
|
||||
if (token is null)
|
||||
{
|
||||
Log.Warning("Twitch client id and client secret key are not added to creds.yml or incorrect");
|
||||
Log.Warning("Twitch client id and client secret key are not added to data/creds.yml or incorrect");
|
||||
return Array.Empty<StreamData>();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,4 +21,4 @@ if (args.Length > 0 && args[0] != "run")
|
|||
}
|
||||
|
||||
|
||||
await new Bot(shardId, totalShards, Environment.GetEnvironmentVariable("EllieBot__creds")).RunAndBlockAsync();
|
||||
await new Bot(shardId, totalShards).RunAndBlockAsync();
|
|
@ -6,8 +6,8 @@ namespace EllieBot.Services;
|
|||
|
||||
public sealed class BotCredsProvider : IBotCredsProvider
|
||||
{
|
||||
private const string CREDS_FILE_NAME = "creds.yml";
|
||||
private const string CREDS_EXAMPLE_FILE_NAME = "creds_example.yml";
|
||||
private const string CREDS_FILE_NAME = "data/creds.yml";
|
||||
private const string CREDS_EXAMPLE_FILE_NAME = "data/creds_example.yml";
|
||||
|
||||
private string CredsPath { get; }
|
||||
|
||||
|
@ -22,20 +22,12 @@ public sealed class BotCredsProvider : IBotCredsProvider
|
|||
|
||||
private readonly object _reloadLock = new();
|
||||
|
||||
public BotCredsProvider(int? totalShards = null, string credPath = null)
|
||||
public BotCredsProvider(int? totalShards = null)
|
||||
{
|
||||
_totalShards = totalShards;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(credPath))
|
||||
{
|
||||
CredsPath = credPath;
|
||||
CredsExamplePath = Path.Combine(Path.GetDirectoryName(credPath), CREDS_EXAMPLE_FILE_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
CredsPath = Path.Combine(Directory.GetCurrentDirectory(), CREDS_FILE_NAME);
|
||||
CredsExamplePath = Path.Combine(Directory.GetCurrentDirectory(), CREDS_EXAMPLE_FILE_NAME);
|
||||
}
|
||||
CredsPath = Path.Combine(Directory.GetCurrentDirectory(), CREDS_FILE_NAME);
|
||||
CredsExamplePath = Path.Combine(Directory.GetCurrentDirectory(), CREDS_EXAMPLE_FILE_NAME);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -61,8 +53,8 @@ public sealed class BotCredsProvider : IBotCredsProvider
|
|||
}
|
||||
|
||||
_config = new ConfigurationBuilder().AddYamlFile(CredsPath, false, true)
|
||||
.AddEnvironmentVariables("EllieBot_")
|
||||
.Build();
|
||||
.AddEnvironmentVariables("EllieBot_")
|
||||
.Build();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue