Skip to content

Commit e4d9993

Browse files
committed
Adds logging to debug active chain roles
1 parent 0eb1498 commit e4d9993

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

Framework/DiscordRewards/EventsAndErrors.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ public bool HasAny()
1111
return
1212
Errors.Length > 0 ||
1313
EventsOverview.Length > 0 ||
14-
ActiveChainAddresses.Hosts.Length > 0 ||
15-
ActiveChainAddresses.Clients.Length > 0;
14+
ActiveChainAddresses.HasAny();
1615
}
1716
}
1817

@@ -26,5 +25,15 @@ public class ActiveChainAddresses
2625
{
2726
public string[] Hosts { get; set; } = Array.Empty<string>();
2827
public string[] Clients { get; set; } = Array.Empty<string>();
28+
29+
public bool HasAny()
30+
{
31+
return Hosts.Length > 0 || Clients.Length > 0;
32+
}
33+
34+
public override string ToString()
35+
{
36+
return "Hosts:" + string.Join(",", Hosts) + "Clients:" + string.Join(",", Clients);
37+
}
2938
}
3039
}

Tools/BiblioTech/Rewards/ChainActivityHandler.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,24 @@ public ChainActivityHandler(ILog log, UserRepo repo)
1818

1919
public async Task Process(ActiveChainAddresses activeChainAddresses)
2020
{
21+
if (!activeChainAddresses.HasAny())
22+
{
23+
Log("Received empty activeChainAddresses.");
24+
return;
25+
}
26+
2127
var activeUserIds = ConvertToUserIds(activeChainAddresses);
22-
if (!activeUserIds.HasAny()) return;
28+
if (!activeUserIds.HasAny())
29+
{
30+
Log("Empty userIds after lookup of addresses: " + activeChainAddresses);
31+
return;
32+
}
2333

24-
if (!HasChanged(activeUserIds)) return;
34+
if (!HasChanged(activeUserIds))
35+
{
36+
Log("Active userIds has not changed: " + activeUserIds);
37+
return;
38+
}
2539

2640
await GiveAndRemoveRoles(activeUserIds);
2741
}
@@ -116,6 +130,11 @@ private ulong[] Map(string[] ethAddresses)
116130
return result.Order().ToArray();
117131
}
118132

133+
private void Log(string msg)
134+
{
135+
log.Log(msg);
136+
}
137+
119138
private class ActiveUserIds
120139
{
121140
public ActiveUserIds(IEnumerable<ulong> hosts, IEnumerable<ulong> clients)
@@ -131,6 +150,11 @@ public bool HasAny()
131150
{
132151
return Hosts.Any() || Clients.Any();
133152
}
153+
154+
public override string ToString()
155+
{
156+
return "Hosts:" + string.Join(",", Hosts) + "Clients:" + string.Join(",", Clients);
157+
}
134158
}
135159
}
136160
}

Tools/BiblioTech/Rewards/RoleModifyContext.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public async Task Initialize()
3333

3434
public async Task GiveRole(ulong userId, ulong roleId)
3535
{
36+
Log($"Giving role {roleId} to user {userId}");
3637
var role = GetRole(roleId);
3738
var guildUser = GetUser(userId);
3839
if (role == null) return;
@@ -46,6 +47,7 @@ public async Task GiveRole(ulong userId, ulong roleId)
4647

4748
public async Task RemoveRole(ulong userId, ulong roleId)
4849
{
50+
Log($"Removing role {roleId} from user {userId}");
4951
var role = GetRole(roleId);
5052
var guildUser = GetUser(userId);
5153
if (role == null) return;
@@ -67,6 +69,11 @@ public async Task RemoveRole(ulong userId, ulong roleId)
6769
return null;
6870
}
6971

72+
private void Log(string msg)
73+
{
74+
log.Log(msg);
75+
}
76+
7077
private async Task<Dictionary<ulong, IGuildUser>> LoadAllUsers(SocketGuild guild)
7178
{
7279
log.Log("Loading all users..");

Tools/TestNetRewarder/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public async Task MainAsync()
4545

4646
Log.Log("Starting TestNet Rewarder...");
4747
var segmenter = new TimeSegmenter(Log, Config.Interval, Config.HistoryStartUtc, processor);
48+
await EnsureBotOnline();
4849
await processor.Initialize();
4950

5051
while (!CancellationToken.IsCancellationRequested)

0 commit comments

Comments
 (0)