Add API token commands
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.RegularExpressions;
|
||||
using NodaTime;
|
||||
using NodaTime.Text;
|
||||
@@ -24,6 +22,13 @@ namespace PluralKit
|
||||
return hid;
|
||||
}
|
||||
|
||||
public static string GenerateToken()
|
||||
{
|
||||
var buf = new byte[48]; // Results in a 64-byte Base64 string (no padding)
|
||||
new RNGCryptoServiceProvider().GetBytes(buf);
|
||||
return Convert.ToBase64String(buf);
|
||||
}
|
||||
|
||||
public static string Truncate(this string str, int maxLength, string ellipsis = "...") {
|
||||
if (str.Length < maxLength) return str;
|
||||
return str.Substring(0, maxLength - ellipsis.Length) + ellipsis;
|
||||
@@ -225,21 +230,19 @@ namespace PluralKit
|
||||
{
|
||||
public static IPattern<Instant> TimestampExportFormat = InstantPattern.CreateWithInvariantCulture("g");
|
||||
public static IPattern<LocalDate> DateExportFormat = LocalDatePattern.CreateWithInvariantCulture("yyyy-MM-dd");
|
||||
public static IPattern<Duration> DurationFormat;
|
||||
|
||||
// We create a composite pattern that only shows the two most significant things
|
||||
// eg. if we have something with nonzero day component, we show <x>d <x>h, but if it's
|
||||
// a smaller duration we may only bother with showing <x>h <x>m or <x>m <x>s
|
||||
public static IPattern<Duration> DurationFormat = new CompositePatternBuilder<Duration>
|
||||
{
|
||||
{DurationPattern.CreateWithInvariantCulture("D'd' h'h'"), d => d.Days > 0},
|
||||
{DurationPattern.CreateWithInvariantCulture("H'h' m'm'"), d => d.Hours > 0},
|
||||
{DurationPattern.CreateWithInvariantCulture("m'm' s's'"), d => d.Minutes > 0},
|
||||
{DurationPattern.CreateWithInvariantCulture("s's'"), d => true}
|
||||
}.Build();
|
||||
|
||||
public static IPattern<LocalDateTime> LocalDateTimeFormat = LocalDateTimePattern.CreateWithInvariantCulture("yyyy-MM-dd HH:mm:ss");
|
||||
public static IPattern<ZonedDateTime> ZonedDateTimeFormat = ZonedDateTimePattern.CreateWithInvariantCulture("yyyy-MM-dd HH:mm:ss x", DateTimeZoneProviders.Tzdb);
|
||||
|
||||
static Formats()
|
||||
{
|
||||
// We create a composite pattern that only shows the two most significant things
|
||||
// eg. if we have something with nonzero day component, we show <x>d <x>h, but if it's
|
||||
// a smaller duration we may only bother with showing <x>h <x>m or <x>m <x>s
|
||||
var compositeDuration = new CompositePatternBuilder<Duration>();
|
||||
compositeDuration.Add(DurationPattern.CreateWithInvariantCulture("D'd' h'h'"), d => d.Days > 0);
|
||||
compositeDuration.Add(DurationPattern.CreateWithInvariantCulture("H'h' m'm'"), d => d.Hours > 0);
|
||||
compositeDuration.Add(DurationPattern.CreateWithInvariantCulture("m'm' s's'"), d => d.Minutes > 0);
|
||||
compositeDuration.Add(DurationPattern.CreateWithInvariantCulture("s's'"), d => true);
|
||||
DurationFormat = compositeDuration.Build();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user