From 7e6b369b48a5e65ca97eb9a8c99085e2b6012791 Mon Sep 17 00:00:00 2001 From: Adam R Grey Date: Fri, 14 Apr 2023 22:04:25 -0400 Subject: [PATCH] reload currency hourly, lots more converters --- Conversion/Converter.cs | 11 +- Conversion/ExchangePairs.cs | 2 +- Program.cs | 2 - assets/conversion.json | 205 +++++++++++++++++++++++++++++++++++- 4 files changed, 213 insertions(+), 7 deletions(-) diff --git a/Conversion/Converter.cs b/Conversion/Converter.cs index c3ec105..ab17d8d 100644 --- a/Conversion/Converter.cs +++ b/Conversion/Converter.cs @@ -55,10 +55,17 @@ namespace silverworker_discord.Conversion { AddLinearPair(lp.item1, lp.item2, lp.factor); } - loadCurrency(); + Task.Run(async () => { + while(true) + { + loadCurrency(); + await Task.Delay(TimeSpan.FromHours(8)); + } + }); } private static void loadCurrency() { + Console.WriteLine("loading currency exchange data."); if (File.Exists(currencyPath)) { currencyConf = JsonConvert.DeserializeObject(File.ReadAllText(currencyPath)); @@ -112,7 +119,7 @@ namespace silverworker_discord.Conversion } else { - return $"{String.Format("{0:0.####}", accumulator)} {normalizedDestUnit}"; + return $"{String.Format("{0:G4}", accumulator)} {normalizedDestUnit}"; } } return "no conversion known"; diff --git a/Conversion/ExchangePairs.cs b/Conversion/ExchangePairs.cs index b4d0a79..9bb8249 100644 --- a/Conversion/ExchangePairs.cs +++ b/Conversion/ExchangePairs.cs @@ -8,7 +8,7 @@ namespace silverworker_discord.Conversion public string disclaimer{ get; set; } public string license{ get; set; } public int timestamp{ get; set; } - public DateTime DateUpdated { get { return DateTime.UnixEpoch.AddSeconds(timestamp); }} + public DateTime DateUpdated { get { return DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime(); }} public string Base{ get; set; } public Dictionary rates { get; set; } } diff --git a/Program.cs b/Program.cs index 1698561..59a4898 100644 --- a/Program.cs +++ b/Program.cs @@ -53,8 +53,6 @@ namespace silverworker_discord _client.Log += Log; - Console.WriteLine("token, why u null?"); - Console.WriteLine(config["token"]); await _client.LoginAsync(TokenType.Bot, config["token"]); await _client.StartAsync(); diff --git a/assets/conversion.json b/assets/conversion.json index 83b659c..9005d4a 100644 --- a/assets/conversion.json +++ b/assets/conversion.json @@ -1,8 +1,209 @@ { "units":[ { - "canonical": "f", - "aliases": ["degrees fahrenheit"] + "canonical": "℉", + "aliases": [ + "degrees f", + "deg f", + "degf", + "fahrenheit", + "deg fahrenheit", + "degrees fahrenheit", + "°f", + "° f", + "℉", + "f" + ] + }, + { + "canonical":"°C", + "aliases": [ + "degrees c", + "deg c", + "degc", + "celsius", + "deg celsiu", + "degrees celsiu", + "°c", + "° c", + "c" + ] + }, + { + "canonical":"m", + "aliases": [ + "meter", + "metre" + ] + }, + { + "canonical":"km", + "aliases": [ + "kilometer", + "kilometre" + ] + }, + { + "canonical":"kg", + "aliases": [ + "kilogram", + "kilo" + ] + }, + { + "canonical":"g", + "aliases": [ + "gram" + ] + }, + { + "canonical":"lb", + "aliases": [ + "pound" + ] + }, + { + "canonical":"oz", + "aliases": [ + "ounce" + ] + }, + { + "canonical":"floz", + "aliases": [ + "us fl oz", + "us fl ounce", + "us fluid ounce", + "us fluid oz" + ] + }, + { + "canonical":"mL", + "aliases": [ + "ml", + "milliletre", + "millileter" + ] + }, + { + "canonical":"ft", + "aliases": [ + "'", + "feet", + "foot" + ] + }, + { + "canonical":"in", + "aliases": [ + "\"", + "inch" + ] + }, + { + "canonical":"yd", + "aliases": [ + "yard" + ] + }, + { + "canonical":"hhd", + "aliases": [ + "hogshead" + ] + }, + { + "canonical":"gal", + "aliases": [ + "gallon" + ] + }, + { + "canonical":"tbsp", + "aliases": [ + "tablespoon", + "table spoon" + ] + }, + { + "canonical":"tsp", + "aliases": [ + "teaspoon", + "tea spoon" + ] + }, + { + "canonical":"qt", + "aliases": [ + "quart" + ] + }, + { + "canonical":"ac", + "aliases": [ + "acres" + ] + }, + { + "canonical":"AU", + "aliases": [ + "au", + "astronomical unit" + ] + }, + { + "canonical":"Pa", + "aliases": [ + "pascal", + "pa" + ] + }, + { + "canonical":"kPa", + "aliases": [ + "kilopascal", + "kpa" + ] + }, + { + "canonical":"atm", + "aliases": [ + "atmosphere" + ] + }, + { + "canonical":"m^2", + "aliases": [ + "square meter", + "meter squared", + "meters squared", + "sq meter", + "sq m", + "sqm" + ] + }, + { + "canonical":"km^2", + "aliases": [ + "square kilometer", + "kilometer squared", + "kilometers squared", + "sq kilometer", + "sq km", + "sqkm" + ] + }, + { + "canonical":"ly", + "aliases": [ + "light year" + ] + }, + { + "canonical":"pc", + "aliases": [ + "parsec" + ] } ], "linearPairs":[