Hopefuly fixed convert
This commit is contained in:
parent
ae8429f0b0
commit
fbd2beb348
@ -109,7 +109,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
await msg.ReplyLong(sb.ToString(), breakOn: new[] { "```xl\n", "\n" });
|
await msg.ReplyLong(sb.ToString(), breakOn: new[] { "```xl\n", "\n" });
|
||||||
}
|
}
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
public async Task Convert(IUserMessage msg, string origin, string target, double value)
|
public async Task Convert(IUserMessage msg, string origin, string target, decimal value)
|
||||||
{
|
{
|
||||||
var originUnit = Units.Find(x => x.Triggers.Select(y => y.ToLowerInvariant()).Contains(origin.ToLowerInvariant()));
|
var originUnit = Units.Find(x => x.Triggers.Select(y => y.ToLowerInvariant()).Contains(origin.ToLowerInvariant()));
|
||||||
var targetUnit = Units.Find(x => x.Triggers.Select(y => y.ToLowerInvariant()).Contains(target.ToLowerInvariant()));
|
var targetUnit = Units.Find(x => x.Triggers.Select(y => y.ToLowerInvariant()).Contains(target.ToLowerInvariant()));
|
||||||
@ -123,7 +123,7 @@ namespace NadekoBot.Modules.Searches
|
|||||||
await msg.Reply(string.Format("Cannot convert {0} to {1}: types of unit are not equal", originUnit.Triggers.First(), targetUnit.Triggers.First()));
|
await msg.Reply(string.Format("Cannot convert {0} to {1}: types of unit are not equal", originUnit.Triggers.First(), targetUnit.Triggers.First()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
double res;
|
decimal res;
|
||||||
if (originUnit.Triggers == targetUnit.Triggers) res = value;
|
if (originUnit.Triggers == targetUnit.Triggers) res = value;
|
||||||
else if (originUnit.UnitType == "temperature")
|
else if (originUnit.UnitType == "temperature")
|
||||||
{
|
{
|
||||||
@ -131,10 +131,10 @@ namespace NadekoBot.Modules.Searches
|
|||||||
switch (originUnit.Triggers.First().ToUpperInvariant())
|
switch (originUnit.Triggers.First().ToUpperInvariant())
|
||||||
{
|
{
|
||||||
case "C":
|
case "C":
|
||||||
res = value + 273.15; //celcius!
|
res = value + 273.15m; //celcius!
|
||||||
break;
|
break;
|
||||||
case "F":
|
case "F":
|
||||||
res = (value + 459.67) * (5 / 9);
|
res = (value + 459.67m) * (5 / 9);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res = value;
|
res = value;
|
||||||
@ -144,10 +144,10 @@ namespace NadekoBot.Modules.Searches
|
|||||||
switch (targetUnit.Triggers.First())
|
switch (targetUnit.Triggers.First())
|
||||||
{
|
{
|
||||||
case "C":
|
case "C":
|
||||||
res = value - 273.15; //celcius!
|
res = value - 273.15m; //celcius!
|
||||||
break;
|
break;
|
||||||
case "F":
|
case "F":
|
||||||
res = res * (9 / 5) - 458.67;
|
res = res * (9 / 5) - 458.67m;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -157,14 +157,14 @@ namespace NadekoBot.Modules.Searches
|
|||||||
{
|
{
|
||||||
if (originUnit.UnitType == "currency")
|
if (originUnit.UnitType == "currency")
|
||||||
{
|
{
|
||||||
res = (value * (double)targetUnit.Modifier) / (double)originUnit.Modifier;
|
res = (value * targetUnit.Modifier) / originUnit.Modifier;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
res = (value * (double)originUnit.Modifier) / (double)targetUnit.Modifier;
|
res = (value * originUnit.Modifier) / targetUnit.Modifier;
|
||||||
}
|
}
|
||||||
res = Math.Round(res, 2);
|
res = Math.Round(res, 2);
|
||||||
|
|
||||||
await msg.Reply(string.Format("{0} {1}s is equal to {2} {3}s", value, originUnit.Triggers.First().SnPl(value.IsInteger() ? (int)value : 2), res, targetUnit.Triggers.First().SnPl(res.IsInteger() ? (int)res : 2)));
|
await msg.Reply(string.Format("{0} {1} is equal to {2} {3}", value, (originUnit.Triggers.First() + "s").SnPl(value.IsInteger() ? (int)value : 2), res, (targetUnit.Triggers.First() + "s").SnPl(res.IsInteger() ? (int)res : 2)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ namespace NadekoBot.Extensions
|
|||||||
http.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
http.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsInteger(this double number) => number == Math.Truncate(number);
|
public static bool IsInteger(this decimal number) => number == Math.Truncate(number);
|
||||||
|
|
||||||
public static string SanitizeMentions(this string str) =>
|
public static string SanitizeMentions(this string str) =>
|
||||||
str.Replace("@everyone", "@everyοne").Replace("@here", "@һere");
|
str.Replace("@everyone", "@everyοne").Replace("@here", "@һere");
|
||||||
|
Loading…
Reference in New Issue
Block a user