mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Nuked humanizer. Some of the strings might look worse but the output directory will no longer look terrible. Added stats for todo list command
This commit is contained in:
@@ -29,7 +29,17 @@ public static class StringExtensions
|
||||
=> Regex.Replace(input, "<.*?>", string.Empty);
|
||||
|
||||
public static string? TrimTo(this string? str, int maxLength, bool hideDots = false)
|
||||
=> hideDots ? str?.Truncate(maxLength, string.Empty) : str?.Truncate(maxLength);
|
||||
{
|
||||
if (hideDots)
|
||||
{
|
||||
return str?.Substring(0, maxLength);
|
||||
}
|
||||
|
||||
if (str is null || str.Length <= maxLength)
|
||||
return str;
|
||||
|
||||
return string.Concat(str.AsSpan(0, maxLength - 1), "…");
|
||||
}
|
||||
|
||||
public static string ToTitleCase(this string str)
|
||||
{
|
||||
|
@@ -9,7 +9,13 @@ public static class PatronExtensions
|
||||
};
|
||||
|
||||
public static string ToFullName(this QuotaPer per)
|
||||
=> per.Humanize(LetterCasing.LowerCase);
|
||||
=> per switch
|
||||
{
|
||||
QuotaPer.PerDay => "per day",
|
||||
QuotaPer.PerHour => "per hour",
|
||||
QuotaPer.PerMonth => "per month",
|
||||
_ => "Unknown",
|
||||
};
|
||||
|
||||
public static DateTime DayOfNextMonth(this DateTime date, int day)
|
||||
{
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#nullable disable
|
||||
using Humanizer.Localisation;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using System.Diagnostics;
|
||||
|
||||
@@ -178,13 +177,23 @@ public sealed class StatsService : IStatsService, IReadyExecutor, INService
|
||||
public string GetUptimeString(string separator = ", ")
|
||||
{
|
||||
var time = GetUptime();
|
||||
return time.Humanize(3, maxUnit: TimeUnit.Day, minUnit: TimeUnit.Minute);
|
||||
|
||||
if (time.Days > 0)
|
||||
return $"{time.Days}d {time.Hours}h {time.Minutes}m";
|
||||
|
||||
if (time.Hours > 0)
|
||||
return $"{time.Hours}h {time.Minutes}m";
|
||||
|
||||
if (time.Minutes > 0)
|
||||
return $"{time.Minutes}m {time.Seconds}s";
|
||||
|
||||
return $"{time.Seconds}s";
|
||||
}
|
||||
|
||||
|
||||
public double GetPrivateMemoryMegabytes()
|
||||
{
|
||||
_currentProcess.Refresh();
|
||||
return _currentProcess.PrivateMemorySize64 / 1.Megabytes().Bytes;
|
||||
return _currentProcess.PrivateMemorySize64 / 1.Megabytes();
|
||||
}
|
||||
|
||||
public GuildInfo GetGuildInfo(string name)
|
||||
|
@@ -1,4 +1,3 @@
|
||||
using Humanizer.Localisation;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
@@ -11,7 +10,7 @@ public static class Extensions
|
||||
{
|
||||
private static readonly Regex _urlRegex =
|
||||
new(@"^(https?|ftp)://(?<path>[^\s/$.?#].[^\s]*)$", RegexOptions.Compiled);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Converts <see cref="DateTime"/> to <see cref="DateOnly"/>
|
||||
/// </summary>
|
||||
@@ -51,7 +50,7 @@ public static class Extensions
|
||||
|
||||
public static ulong[] GetGuildIds(this DiscordSocketClient client)
|
||||
=> client.Guilds
|
||||
.Map(x => x.Id);
|
||||
.Map(x => x.Id);
|
||||
|
||||
/// <summary>
|
||||
/// Generates a string in the format HHH:mm if timespan is >= 2m.
|
||||
@@ -60,7 +59,30 @@ public static class Extensions
|
||||
/// <param name="span">Timespan to convert to string</param>
|
||||
/// <returns>Formatted duration string</returns>
|
||||
public static string ToPrettyStringHm(this TimeSpan span)
|
||||
=> span.Humanize(2, minUnit: TimeUnit.Second);
|
||||
{
|
||||
if(span > TimeSpan.FromHours(24))
|
||||
return $"{span.Days:00}d:{span.Hours:00}h";
|
||||
|
||||
if (span > TimeSpan.FromMinutes(2))
|
||||
return $"{span.Hours:00}h:{span.Minutes:00}m";
|
||||
|
||||
return $"{span.Minutes:00}m:{span.Seconds:00}s";
|
||||
}
|
||||
|
||||
public static double Megabytes(this int mb)
|
||||
=> mb * 1024d * 1024;
|
||||
|
||||
public static TimeSpan Hours(this int hours)
|
||||
=> TimeSpan.FromHours(hours);
|
||||
|
||||
public static TimeSpan Minutes(this int minutes)
|
||||
=> TimeSpan.FromMinutes(minutes);
|
||||
|
||||
public static TimeSpan Days(this int days)
|
||||
=> TimeSpan.FromDays(days);
|
||||
|
||||
public static TimeSpan Seconds(this int seconds)
|
||||
=> TimeSpan.FromSeconds(seconds);
|
||||
|
||||
public static bool TryGetUrlPath(this string input, out string path)
|
||||
{
|
||||
|
Reference in New Issue
Block a user