This repository has been archived by the owner on Jul 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.cs
52 lines (46 loc) · 1.75 KB
/
Utilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using Color = Discord.Color;
using System.Threading.Tasks;
using SixLabors.ImageSharp.PixelFormats;
namespace TimeBot
{
public static class Utilities
{
// Common Colors used
public static readonly Color Blue = new(127, 166, 208);
public static readonly Color Red = new(231, 76, 60);
public static readonly Color Green = new(31, 139, 76);
/// <summary>
/// Invite link to the support server
/// </summary>
public static string SupportServer = "https://discord.gg/FjgCFYRZAw";
// Http Client
public static HttpClient HttpClient = new();
/// <summary>
/// Get the average color for a user's profile picture
/// </summary>
public static async Task<Color> GetImageColor(string avatarURL)
{
try
{
using (var ms = new MemoryStream(await HttpClient.GetByteArrayAsync(avatarURL)))
{
var palette = DominantColorFinder.GetPalette((SixLabors.ImageSharp.Image<Rgba32>)SixLabors.ImageSharp.Image.Load(ms));
return new Color(Convert.ToInt16(palette.Average(a => a.Color.R)), Convert.ToInt16(palette.Average(a => a.Color.G)), Convert.ToInt16(palette.Average(a => a.Color.B)));
}
}
catch
{
// Just return this color
return new Color(32, 34, 37);
}
}
/// <summary>
/// Return the "a minute ago" discord text
/// </summary>
public static string GetRefreshedTimeText() => $"Last refreshed <t:{((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)}:R>";
}
}