Skip to content

Commit 376026f

Browse files
authored
Dev/Add info embed (#82)
* Add basic info command * Add real stats * Adjust actions, dockerfile and workflow to new name scheme * Give EmbedBuilder more responsibility * Stuff cleanup and style
1 parent bbd2b00 commit 376026f

File tree

13 files changed

+91
-70
lines changed

13 files changed

+91
-70
lines changed

.github/workflows/docker.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ jobs:
7474
exclude_dir: "AzzyBot"
7575
include_lang: "C#,MSBuild script"
7676

77-
# - name: Calculate Lines of JSON Code
78-
# id: loc_json
79-
# uses: PavanMudigonda/lines-of-code-reporter@v1.6
80-
# with:
81-
# directory: "/home/runner/work/AzzyBot/AzzyBot/AzzyBot/Customization"
82-
# include_lang: "JSON"
83-
8477
- name: Docker meta
8578
id: meta
8679
uses: docker/metadata-action@v5
@@ -112,7 +105,6 @@ jobs:
112105
COMMIT=${{ github.sha }}
113106
TIMESTAMP=${{ steps.dateTime.outputs.time }}
114107
LOC_CS=${{ steps.loc_cs.outputs.total_lines }}
115-
LOC_JSON=0
116108
context: .
117109
file: ${{ steps.runtime.outputs.runtime }}
118110
labels: ${{ steps.meta.outputs.labels }}
@@ -188,13 +180,6 @@ jobs:
188180
exclude_dir: "AzzyBot"
189181
include_lang: "C#,MSBuild script"
190182

191-
# - name: Calculate Lines of JSON Code
192-
# id: loc_json
193-
# uses: PavanMudigonda/lines-of-code-reporter@v1.6
194-
# with:
195-
# directory: "/home/runner/actions-runner/_work/AzzyBot/AzzyBot/AzzyBot/Customization"
196-
# include_lang: "JSON"
197-
198183
- name: Docker meta
199184
id: meta
200185
uses: docker/metadata-action@v5
@@ -226,7 +211,6 @@ jobs:
226211
COMMIT=${{ github.sha }}
227212
TIMESTAMP=${{ steps.dateTime.outputs.time }}
228213
LOC_CS=${{ steps.loc_cs.outputs.total_lines }}
229-
LOC_JSON=0
230214
context: .
231215
file: ${{ steps.runtime.outputs.runtime }}
232216
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/dotnet-release-publish.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ jobs:
6161
with:
6262
exclude_dir: "AzzyBot"
6363
include_lang: "C#,MSBuild script"
64-
65-
- name: Calculate Lines of JSON Code
66-
id: loc_json
67-
uses: PavanMudigonda/lines-of-code-reporter@v1.6
68-
with:
69-
directory: "/home/runner/work/AzzyBot/AzzyBot/AzzyBot/Customization"
70-
include_lang: "JSON"
7164

7265
- name: Get Date and Time
7366
id: dateTime
@@ -78,9 +71,8 @@ jobs:
7871
- name: Add some basic information
7972
run: |
8073
sed -i 's\Commit not found\${{ github.sha }}\g' ./artifacts/publish/AzzyBot/release_${{ matrix.os }}-${{ matrix.arch }}/Modules/Core/Files/AzzyBot.json
81-
sed -i 's\Compile date not found\${{ steps.dateTime.outputs.time }}\g' ./artifacts/publish/AzzyBot/release_${{ matrix.os }}-${{ matrix.arch }}/Modules/Core/Files/AzzyBot.json
74+
sed -i 's\Compilation date not found\${{ steps.dateTime.outputs.time }}\g' ./artifacts/publish/AzzyBot/release_${{ matrix.os }}-${{ matrix.arch }}/Modules/Core/Files/AzzyBot.json
8275
sed -i 's\Lines of source code not found\${{ steps.loc_cs.outputs.total_lines }}\g' ./artifacts/publish/AzzyBot/release_${{ matrix.os }}-${{ matrix.arch }}/Modules/Core/Files/AzzyBot.json
83-
sed -i 's\Lines of JSON code not found\${{ steps.loc_json.outputs.total_lines }}\g' ./artifacts/publish/AzzyBot/release_${{ matrix.os }}-${{ matrix.arch }}/Modules/Core/Files/AzzyBot.json
8476
env:
8577
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8678

.github/workflows/dotnet.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ jobs:
6060
with:
6161
exclude_dir: "AzzyBot"
6262
include_lang: "C#,MSBuild script"
63-
64-
# - name: Calculate Lines of JSON Code
65-
# id: loc_json
66-
# uses: PavanMudigonda/lines-of-code-reporter@v1.6
67-
# with:
68-
# directory: "/home/runner/work/AzzyBot/AzzyBot/AzzyBot/Customization"
69-
# include_lang: "JSON"
7063

7164
- name: Get Date and Time
7265
id: dateTime
@@ -77,9 +70,8 @@ jobs:
7770
- name: Add some basic information
7871
run: |
7972
sed -i 's\Commit not found\${{ github.sha }}\g' ./artifacts/publish/AzzyBot-Next/debug_${{ matrix.os }}-${{ matrix.arch }}/Modules/Core/Files/AzzyBotStats.json
80-
sed -i 's\Compile date not found\${{ steps.dateTime.outputs.time }}\g' ./artifacts/publish/AzzyBot-Next/debug_${{ matrix.os }}-${{ matrix.arch }}/Modules/Core/Files/AzzyBotStats.json
73+
sed -i 's\Compilation date not found\${{ steps.dateTime.outputs.time }}\g' ./artifacts/publish/AzzyBot-Next/debug_${{ matrix.os }}-${{ matrix.arch }}/Modules/Core/Files/AzzyBotStats.json
8174
sed -i 's\Lines of source code not found\${{ steps.loc_cs.outputs.total_lines }}\g' ./artifacts/publish/AzzyBot-Next/debug_${{ matrix.os }}-${{ matrix.arch }}/Modules/Core/Files/AzzyBotStats.json
82-
sed -i 's\Lines of JSON code not found\0\g' ./artifacts/publish/AzzyBot-Next/debug_${{ matrix.os }}-${{ matrix.arch }}/Modules/Core/Files/AzzyBotStats.json
8375
env:
8476
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8577

AzzyBot-Next/Commands/AdminCommands.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public async ValueTask CoreChangeStatusAsync
4343
_logger.CommandRequested(nameof(CoreChangeStatusAsync), context.User.GlobalName);
4444

4545
await context.DeferResponseAsync();
46+
4647
await _botServiceHost.SetBotStatusAsync(status, activity, doing, url, reset);
48+
4749
await context.EditResponseAsync("Bot status has been updated!");
4850
}
4951

AzzyBot-Next/Commands/ConfigCommands.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public async ValueTask ConfigSetAzuraCastAsync
3838
await context.DeferResponseAsync();
3939

4040
ulong guildId = context.Guild?.Id ?? throw new InvalidOperationException("Guild is null");
41-
4241
await _db.SetAzuraCastEntityAsync(guildId, apiKey, apiUrl, stationId, requestsChannel?.Id ?? 0, outagesChannel?.Id ?? 0, showPlaylistInNowPlaying);
4342
await _db.SetGuildEntityAsync(guildId);
4443

@@ -68,7 +67,6 @@ public async ValueTask ConfigSetAzuraCastChecksAsync
6867
await context.DeferResponseAsync();
6968

7069
ulong guildId = context.Guild?.Id ?? throw new InvalidOperationException("Guild is null");
71-
7270
await _db.SetAzuraCastChecksEntityAsync(guildId, fileChanges, serverStatus, updates, updatesChangelog);
7371

7472
await context.EditResponseAsync("Your settings were saved successfully.");
@@ -82,7 +80,6 @@ public async ValueTask ConfigSetCoreAsync(CommandContext context, [Description("
8280
await context.DeferResponseAsync();
8381

8482
ulong guildId = context.Guild?.Id ?? throw new InvalidOperationException("Guild is null");
85-
8683
await _db.SetGuildEntityAsync(guildId, errorChannel?.Id ?? 0);
8784

8885
await context.EditResponseAsync("Your settings were saved successfully.");
@@ -123,7 +120,6 @@ public async ValueTask ConfigResetSettingsAsync(CommandContext context)
123120
await context.DeferResponseAsync();
124121

125122
ulong guildId = context.Guild?.Id ?? throw new InvalidOperationException("Guild is null");
126-
127123
await _db.RemoveGuildEntityAsync(guildId);
128124
await _db.AddGuildEntityAsync(guildId);
129125

AzzyBot-Next/Commands/CoreCommands.cs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ namespace AzzyBot.Commands;
2121
internal sealed class CoreCommands
2222
{
2323
[Command("core"), RequireGuild]
24-
internal sealed class Core(AzzyBotSettingsRecord settings, DbActions dbActions, ILogger<Core> logger)
24+
internal sealed class Core(AzzyBotSettingsRecord settings, AzzyBotStatsRecord stats, DbActions dbActions, ILogger<Core> logger)
2525
{
2626
private readonly AzzyBotSettingsRecord _settings = settings;
27+
private readonly AzzyBotStatsRecord _stats = stats;
2728
private readonly DbActions _dbActions = dbActions;
2829
private readonly ILogger<Core> _logger = logger;
2930

@@ -51,7 +52,6 @@ public async ValueTask CoreHelpAsync
5152
}
5253

5354
bool approvedDebug = guild.IsDebugAllowed || guildId == _settings.ServerId;
54-
5555
List<DiscordEmbed> embeds = [];
5656

5757
if (string.IsNullOrWhiteSpace(command))
@@ -74,34 +74,32 @@ public async ValueTask CoreHelpAsync
7474
await context.EditResponseAsync(messageBuilder);
7575
}
7676

77-
[Command("hardware-stats")]
77+
[Command("hardware-stats"), Description("Shows information about the hardware side of the bot.")]
7878
public async ValueTask CoreHardwareStatsAsync(CommandContext context)
7979
{
8080
_logger.CommandRequested(nameof(CoreHardwareStatsAsync), context.User.GlobalName);
8181

8282
await context.DeferResponseAsync();
8383

8484
Uri avaUrl = new(context.Client.CurrentUser.AvatarUrl);
85-
string os = AzzyStatsHardware.GetSystemOs;
86-
string osArch = AzzyStatsHardware.GetSystemOsArch;
87-
string isDocker = AzzyStatsHardware.CheckIfDocker.ToString();
88-
long uptime = Converter.ConvertToUnixTime(AzzyStatsHardware.GetSystemUptime());
89-
Dictionary<int, double> cpuUsage = await AzzyStatsHardware.GetSystemCpusAsync();
90-
CpuLoadRecord cpuLoads = await AzzyStatsHardware.GetSystemCpuLoadAsync();
91-
MemoryUsageRecord memory = await AzzyStatsHardware.GetSystemMemoryUsageAsync();
92-
DiskUsageRecord disk = AzzyStatsHardware.GetSystemDiskUsage();
93-
Dictionary<string, NetworkSpeedRecord> networkUsage = await AzzyStatsHardware.GetSystemNetworkUsageAsync();
94-
95-
DiscordEmbed embed = EmbedBuilder.BuildAzzyHardwareStatsEmbed(avaUrl, os, osArch, isDocker, uptime, cpuUsage, cpuLoads, memory, disk, networkUsage);
85+
DiscordEmbed embed = await EmbedBuilder.BuildAzzyHardwareStatsEmbedAsync(avaUrl);
9686

9787
await context.EditResponseAsync(embed);
9888
}
9989

100-
//[Command("info")]
101-
//public static async ValueTask CoreInfoAsync(CommandContext context)
102-
//{
103-
// await context.DeferResponseAsync();
104-
//}
90+
[Command("info-stats"), Description("Shows information about the bot and it's components.")]
91+
public async ValueTask CoreInfoStatsAsync(CommandContext context)
92+
{
93+
_logger.CommandRequested(nameof(CoreInfoStatsAsync), context.User.GlobalName);
94+
95+
await context.DeferResponseAsync();
96+
97+
Uri avaUrl = new(context.Client.CurrentUser.AvatarUrl);
98+
string dspVersion = context.Client.VersionString.Split('+')[0];
99+
DiscordEmbed embed = EmbedBuilder.BuildAzzyInfoStatsEmbed(avaUrl, dspVersion, _stats.Commit, _stats.CompilationDate, _stats.LocCs);
100+
101+
await context.EditResponseAsync(embed);
102+
}
105103

106104
[Command("ping"), Description("Ping the bot and get the latency to discord.")]
107105
public async ValueTask CorePingAsync(CommandContext context)

AzzyBot-Next/Commands/DebugCommands.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public async ValueTask DebugWebServiceTestsAsync(CommandContext context, [Descri
6161
_logger.CommandRequested(nameof(DebugWebServiceTestsAsync), context.User.GlobalName);
6262

6363
await context.DeferResponseAsync();
64+
6465
await _webRequestService.GetWebAsync(url);
66+
6567
await context.EditResponseAsync($"Web service test for *{url}* was successful!");
6668
}
6769
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"Commit": "Commit not found",
3-
"CompileDate": "Compile date not found",
4-
"LoC_CS": "Lines of source code not found",
5-
"LoC_JSON": "Lines of JSON code not found"
3+
"CompilationDate": "Compilation date not found",
4+
"LocCS": "Lines of source code not found"
65
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
using System;
2+
using System.Text.Json.Serialization;
23

34
namespace AzzyBot.Settings;
45

56
internal sealed record AzzyBotStatsRecord
67
{
8+
[JsonPropertyName(nameof(Commit))]
79
public required string Commit { get; init; }
10+
11+
[JsonPropertyName(nameof(CompilationDate))]
812
public required DateTime CompilationDate { get; init; }
13+
14+
[JsonPropertyName(nameof(LocCs))]
915
public required int LocCs { get; init; }
10-
public required int LocJson { get; init; }
1116
}

AzzyBot-Next/Utilities/AzzyStatsSoftware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal static double GetBotMemoryUsage()
1717
{
1818
using Process? process = Process.GetCurrentProcess();
1919

20-
return process.WorkingSet64 / (1024.0 * 1024.0 * 1024.0);
20+
return Math.Round(process.WorkingSet64 / (1024.0 * 1024.0 * 1024.0), 2);
2121
}
2222

2323
internal static DateTime GetBotUptime()

AzzyBot-Next/Utilities/EmbedBuilder.cs

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Globalization;
44
using System.Text;
5+
using System.Threading.Tasks;
56
using AzzyBot.Database.Entities;
67
using AzzyBot.Utilities.Records;
78
using DSharpPlus.Entities;
@@ -45,17 +46,26 @@ private static DiscordEmbedBuilder CreateBasicEmbed(string title, string? descri
4546
return builder;
4647
}
4748

48-
internal static DiscordEmbed BuildAzzyHardwareStatsEmbed(Uri avaUrl, string os, string osArch, string isDocker, long sysUptime, Dictionary<int, double> cpuUsage, CpuLoadRecord cpuLoads, MemoryUsageRecord memory, DiskUsageRecord disk, Dictionary<string, NetworkSpeedRecord> networkUsage)
49+
internal static async Task<DiscordEmbed> BuildAzzyHardwareStatsEmbedAsync(Uri avaUrl)
4950
{
5051
const string title = "AzzyBot Hardware Stats";
5152
const string notLinux = "To display more information you need to have a linux os.";
53+
string os = AzzyStatsHardware.GetSystemOs;
54+
string osArch = AzzyStatsHardware.GetSystemOsArch;
55+
string isDocker = AzzyStatsHardware.CheckIfDocker.ToString();
56+
long uptime = Converter.ConvertToUnixTime(AzzyStatsHardware.GetSystemUptime());
57+
Dictionary<int, double> cpuUsage = await AzzyStatsHardware.GetSystemCpusAsync();
58+
CpuLoadRecord cpuLoads = await AzzyStatsHardware.GetSystemCpuLoadAsync();
59+
MemoryUsageRecord memory = await AzzyStatsHardware.GetSystemMemoryUsageAsync();
60+
DiskUsageRecord disk = AzzyStatsHardware.GetSystemDiskUsage();
61+
Dictionary<string, NetworkSpeedRecord> networkUsage = await AzzyStatsHardware.GetSystemNetworkUsageAsync();
5262

5363
Dictionary<string, DiscordEmbedRecord> fields = new()
5464
{
5565
["Operating System"] = new(os, true),
5666
["Architecture"] = new(osArch, true),
5767
["Is Dockerized"] = new(isDocker, true),
58-
["System Uptime"] = new($"<t:{sysUptime}>", false)
68+
["System Uptime"] = new($"<t:{uptime}>", false)
5969
};
6070

6171
if (!AzzyStatsHardware.CheckIfLinuxOs)
@@ -127,6 +137,51 @@ internal static DiscordEmbed BuildAzzyHelpEmbed(List<AzzyHelpRecord> commands)
127137
return CreateBasicEmbed(title, null, DiscordColor.Blurple, null, null, null, fields);
128138
}
129139

140+
internal static DiscordEmbed BuildAzzyInfoStatsEmbed(Uri avaUrl, string dspVersion, string commit, in DateTime compileDate, int loc)
141+
{
142+
const string title = "AzzyBot Informational Stats";
143+
const string githubUrl = "https://github.com/Sella-GH";
144+
const string botUrl = $"{githubUrl}/AzzyBot";
145+
const string commitUrl = $"{botUrl}/commit";
146+
const string contribUrl = $"{botUrl}/graphs/contributors";
147+
string[] authors = AzzyStatsSoftware.GetBotAuthors.Split(',');
148+
string sourceCode = $"{loc} lines";
149+
string formattedAuthors = $"- [{authors[0].Trim()}]({githubUrl})\n- [{authors[1].Trim()}]({contribUrl})";
150+
string formattedCommit = $"[{commit}]({commitUrl}/{commit})";
151+
152+
Dictionary<string, DiscordEmbedRecord> fields = new()
153+
{
154+
// Row 1
155+
["Name"] = new(AzzyStatsSoftware.GetBotName, true),
156+
157+
// Row 2
158+
["Uptime"] = new($"<t:{Converter.ConvertToUnixTime(AzzyStatsSoftware.GetBotUptime())}>", false),
159+
160+
// Row 3
161+
["Bot Version"] = new(AzzyStatsSoftware.GetBotVersion, true),
162+
[".NET Version"] = new(AzzyStatsSoftware.GetBotDotNetVersion, true),
163+
["D#+ Version"] = new(dspVersion, true),
164+
165+
// Row 4
166+
["Authors"] = new(formattedAuthors, true),
167+
["Repository"] = new($"[GitHub]({botUrl})", true),
168+
["Environment"] = new(AzzyStatsSoftware.GetBotEnvironment, true),
169+
170+
// Row 5
171+
["Language"] = new("C# 12.0", true),
172+
["Source Code"] = new(sourceCode, true),
173+
["Memory Usage"] = new($"{AzzyStatsSoftware.GetBotMemoryUsage()} GB", true),
174+
175+
// Row 6
176+
["Compilation Date"] = new($"<t:{Converter.ConvertToUnixTime(compileDate)}>", false),
177+
178+
// Row 7
179+
["AzzyBot GitHub Commit"] = new(formattedCommit, false)
180+
};
181+
182+
return CreateBasicEmbed(title, null, DiscordColor.Orange, avaUrl, null, null, fields);
183+
}
184+
130185
internal static DiscordEmbed BuildAzzyUpdatesAvailableEmbed(Version version, in DateTime updateDate, Uri url)
131186
{
132187
const string title = "Azzy Updates Available";

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ COPY --from=build /src/out .
2626
ARG COMMIT
2727
ARG TIMESTAMP
2828
ARG LOC_CS
29-
ARG LOC_JSON
3029
RUN sed -i "s\Commit not found\\$COMMIT\g" /app/Modules/Core/Files/AzzyBotStats.json
31-
RUN sed -i "s\Compile date not found\\$TIMESTAMP\g" /app/Modules/Core/Files/AzzyBotStats.json
30+
RUN sed -i "s\Compilation date not found\\$TIMESTAMP\g" /app/Modules/Core/Files/AzzyBotStats.json
3231
RUN sed -i "s\Lines of source code not found\\$LOC_CS\g" /app/Modules/Core/Files/AzzyBotStats.json
33-
RUN sed -i "s\Lines of JSON code not found\\$LOC_JSON\g" /app/Modules/Core/Files/AzzyBotStats.json
3432

3533
# Add new user
3634
RUN groupadd azzy

dev.Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ COPY --from=build /src/out .
2626
ARG COMMIT
2727
ARG TIMESTAMP
2828
ARG LOC_CS
29-
ARG LOC_JSON
3029
RUN sed -i "s\Commit not found\\$COMMIT\g" /app/Modules/Core/Files/AzzyBotStats.json
31-
RUN sed -i "s\Compile date not found\\$TIMESTAMP\g" /app/Modules/Core/Files/AzzyBotStats.json
30+
RUN sed -i "s\Compilation date not found\\$TIMESTAMP\g" /app/Modules/Core/Files/AzzyBotStats.json
3231
RUN sed -i "s\Lines of source code not found\\$LOC_CS\g" /app/Modules/Core/Files/AzzyBotStats.json
33-
RUN sed -i "s\Lines of JSON code not found\\$LOC_JSON\g" /app/Modules/Core/Files/AzzyBotStats.json
3432

3533
# Add new user
3634
RUN groupadd azzy

0 commit comments

Comments
 (0)