Adds logging to debug active chain roles

This commit is contained in:
Ben 2025-04-17 13:53:21 +02:00
parent 0eb14988d0
commit e4d99932dd
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
4 changed files with 45 additions and 4 deletions

View File

@ -11,8 +11,7 @@
return
Errors.Length > 0 ||
EventsOverview.Length > 0 ||
ActiveChainAddresses.Hosts.Length > 0 ||
ActiveChainAddresses.Clients.Length > 0;
ActiveChainAddresses.HasAny();
}
}
@ -26,5 +25,15 @@
{
public string[] Hosts { get; set; } = Array.Empty<string>();
public string[] Clients { get; set; } = Array.Empty<string>();
public bool HasAny()
{
return Hosts.Length > 0 || Clients.Length > 0;
}
public override string ToString()
{
return "Hosts:" + string.Join(",", Hosts) + "Clients:" + string.Join(",", Clients);
}
}
}

View File

@ -18,10 +18,24 @@ namespace BiblioTech.Rewards
public async Task Process(ActiveChainAddresses activeChainAddresses)
{
if (!activeChainAddresses.HasAny())
{
Log("Received empty activeChainAddresses.");
return;
}
var activeUserIds = ConvertToUserIds(activeChainAddresses);
if (!activeUserIds.HasAny()) return;
if (!activeUserIds.HasAny())
{
Log("Empty userIds after lookup of addresses: " + activeChainAddresses);
return;
}
if (!HasChanged(activeUserIds)) return;
if (!HasChanged(activeUserIds))
{
Log("Active userIds has not changed: " + activeUserIds);
return;
}
await GiveAndRemoveRoles(activeUserIds);
}
@ -116,6 +130,11 @@ namespace BiblioTech.Rewards
return result.Order().ToArray();
}
private void Log(string msg)
{
log.Log(msg);
}
private class ActiveUserIds
{
public ActiveUserIds(IEnumerable<ulong> hosts, IEnumerable<ulong> clients)
@ -131,6 +150,11 @@ namespace BiblioTech.Rewards
{
return Hosts.Any() || Clients.Any();
}
public override string ToString()
{
return "Hosts:" + string.Join(",", Hosts) + "Clients:" + string.Join(",", Clients);
}
}
}
}

View File

@ -33,6 +33,7 @@ namespace BiblioTech.Rewards
public async Task GiveRole(ulong userId, ulong roleId)
{
Log($"Giving role {roleId} to user {userId}");
var role = GetRole(roleId);
var guildUser = GetUser(userId);
if (role == null) return;
@ -46,6 +47,7 @@ namespace BiblioTech.Rewards
public async Task RemoveRole(ulong userId, ulong roleId)
{
Log($"Removing role {roleId} from user {userId}");
var role = GetRole(roleId);
var guildUser = GetUser(userId);
if (role == null) return;
@ -67,6 +69,11 @@ namespace BiblioTech.Rewards
return null;
}
private void Log(string msg)
{
log.Log(msg);
}
private async Task<Dictionary<ulong, IGuildUser>> LoadAllUsers(SocketGuild guild)
{
log.Log("Loading all users..");

View File

@ -45,6 +45,7 @@ namespace TestNetRewarder
Log.Log("Starting TestNet Rewarder...");
var segmenter = new TimeSegmenter(Log, Config.Interval, Config.HistoryStartUtc, processor);
await EnsureBotOnline();
await processor.Initialize();
while (!CancellationToken.IsCancellationRequested)