-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extensions.cs
72 lines (63 loc) · 2.99 KB
/
Extensions.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using Newtonsoft.Json;
using LLM.Rori.Discord.Data;
using LLM.Rori.Discord.Data.Starchild;
using LLM.Rori.Discord.Data.Bot;
namespace LLM.Rori.Discord.Extension
{
public static class Extensions
{
public static string GetNormalTime(this TimeSpan time) => time.ToString(@"dd\.hh\:mm\:ss");
public static void LogStatus(this string rawJson, string fileName = "")
{
bool isCorrupted = rawJson == null || rawJson.Length <= 0;
string corruptedMessage = $"[ERROR] Couldnt load {fileName}";
string successMessage = $"[SUCCESS] {fileName} loaded successfully";
if(isCorrupted)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(isCorrupted ? corruptedMessage : successMessage);
Console.ForegroundColor = ConsoleColor.Gray;
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(isCorrupted ? corruptedMessage : successMessage);
Console.ForegroundColor = ConsoleColor.Gray;
}
}
public static string GetCorrespondingQuery(this QueryElement element, MintyBarData user)
{
switch (element)
{
case QueryElement.Username: return $"`username`='{user.Username}'";
case QueryElement.Wallet: return $"`wallet`='{JsonConvert.SerializeObject(user.Wallet)}'";
case QueryElement.Stats: return $"`stats`='{JsonConvert.SerializeObject(user.Stats)}'";
case QueryElement.Inventory: return $"`inventory`='{JsonConvert.SerializeObject(user.Inventory)}'";
default: return $"`userid='{user.Id}',`username`='{user.Username}',`wallet`='{JsonConvert.SerializeObject(user.Wallet)}'," +
$"`stats`='{JsonConvert.SerializeObject(user.Stats)}',`inventory`='{JsonConvert.SerializeObject(user.Inventory)}'";
}
}
public static string GetCorrespondingQuery(this QueryElement element, User user)
{
switch (element)
{
case QueryElement.DiscordData: return $"`discord_data`='{JsonConvert.SerializeObject(user.DiscordData)}'";
case QueryElement.MintyBarData: return $"`minty_bar_data`='{JsonConvert.SerializeObject(user.MintyBarData)}'";
default:
return $"`userid='{user.Id}',`discord_data`='{JsonConvert.SerializeObject(user.DiscordData)}',`minty_bar_data`='{JsonConvert.SerializeObject(user.MintyBarData)}'";
}
}
public static bool IsValid(this MintyBarData user)
{
if (user == null) return false;
if (string.IsNullOrEmpty(user.Id)) return false;
return true;
}
public static bool IsValid(this User user)
{
if (user == null) return false;
if (string.IsNullOrEmpty(user.Id)) return false;
return true;
}
}
}