-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Separate the first statistic stuff * Update the method of getting the bot start time * Add missing module to active modules * Fix a load of stuff * Update CHANGELOG * Update strings
- Loading branch information
Showing
14 changed files
with
229 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using AzzyBot.ExceptionHandling; | ||
using AzzyBot.Settings; | ||
using AzzyBot.Strings.Core; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace AzzyBot.Modules.Core; | ||
|
||
/// <summary> | ||
/// Contains methods for getting general information of the bot. | ||
/// </summary> | ||
internal static class CoreAzzyStatsGeneral | ||
{ | ||
/// <summary> | ||
/// Gets the disk usage of the server. | ||
/// </summary> | ||
/// <returns>A string representing the disk usage in GB.</returns> | ||
internal static string GetDiskUsage() | ||
{ | ||
try | ||
{ | ||
string diskUsage = string.Empty; | ||
|
||
foreach (DriveInfo drive in DriveInfo.GetDrives()) | ||
{ | ||
if (drive.IsReady && drive.Name == "/") | ||
{ | ||
double totalSizeGB = drive.TotalSize / (1024.0 * 1024.0 * 1024.0); | ||
double freeSpaceGB = drive.TotalFreeSpace / (1024.0 * 1024.0 * 1024.0); | ||
double usedSpaceGB = totalSizeGB - freeSpaceGB; | ||
|
||
return CoreStringBuilder.GetEmbedAzzyStatsDiskUsageDesc(Math.Round(usedSpaceGB, 2), Math.Round(totalSizeGB, 2)); | ||
} | ||
} | ||
|
||
return diskUsage; | ||
} | ||
catch (DriveNotFoundException) | ||
{ | ||
ExceptionHandler.LogMessage(LogLevel.Error, "Main drive not found"); | ||
throw; | ||
} | ||
} | ||
|
||
internal static long GetSystemUptime() | ||
{ | ||
TimeSpan uptime = new(Environment.TickCount64); | ||
DateTime dateTime = DateTime.Now.AddMinutes(-uptime.Minutes); | ||
|
||
return CoreMisc.ConvertToUnixTime(dateTime); | ||
} | ||
|
||
internal static string GetActivatedModules() | ||
{ | ||
string text = "- Core"; | ||
|
||
if (BaseSettings.ActivateAzuraCast) | ||
text += "\n- AzuraCast"; | ||
|
||
if (BaseSettings.ActivateClubManagement) | ||
text += "\n- ClubManagement"; | ||
|
||
if (BaseSettings.ActivateMusicStreaming) | ||
text += "\n- MusicStreaming"; | ||
|
||
return text; | ||
} | ||
|
||
internal static string GetBotName => Assembly.GetExecutingAssembly().GetName().Name ?? "Bot name not found"; | ||
|
||
/// <summary> | ||
/// Gets the memory usage only of the bot itself. | ||
/// </summary> | ||
/// <returns>The memory usage of the bot in GB.</returns> | ||
internal static double GetBotMemoryUsage() | ||
{ | ||
Process? process = Process.GetCurrentProcess(); | ||
double usedMemoryGB = process.WorkingSet64 / (1024.0 * 1024.0 * 1024.0); | ||
|
||
process.Dispose(); | ||
|
||
return Math.Round(usedMemoryGB, 2); | ||
} | ||
|
||
internal static string GetBotUptime() | ||
{ | ||
using Process azzy = Process.GetCurrentProcess(); | ||
|
||
return $"<t:{CoreMisc.ConvertToUnixTime(azzy.StartTime)}>"; | ||
} | ||
|
||
internal static string GetBotEnvironment => (Program.GetDiscordClientId == 1217214768159653978) ? "Development" : "Production"; | ||
internal static string GetBotVersion => Assembly.GetExecutingAssembly().GetName().Version?.ToString(3) ?? "Azzy version not found"; | ||
|
||
internal static async Task<string> GetBotCommitAsync() | ||
{ | ||
if (CoreModule.CommitLock is null) | ||
return "Commit not found"; | ||
|
||
string commit = await CoreModule.CommitLock.GetFileContentAsync(); | ||
if (string.IsNullOrWhiteSpace(commit)) | ||
commit = "Commit not found"; | ||
|
||
return commit; | ||
} | ||
|
||
internal static async Task<string> GetBotCompileDateAsync() | ||
{ | ||
if (CoreModule.BuildTimeLock is null) | ||
return "CompileDate not found"; | ||
|
||
if (!DateTime.TryParse(await CoreModule.BuildTimeLock.GetFileContentAsync(), out DateTime dateTime)) | ||
return "CompileDate not found"; | ||
|
||
return $"<t:{CoreMisc.ConvertToUnixTime(dateTime)}>"; | ||
} | ||
|
||
internal static string GetDotNetVersion => Environment.Version.ToString() ?? ".NET version not found"; | ||
internal static string GetDSharpNetVersion => Program.GetDiscordClientVersion; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.