seperated models, added alias attribute

This commit is contained in:
appelemac 2016-09-04 16:57:02 +02:00
parent 673d7698e0
commit b4037f2c33
3 changed files with 29 additions and 21 deletions

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace NadekoBot.Modules.Searches.Commands.Models
{
public class MeasurementUnit
{
public List<string> Triggers { get; set; }
public string UnitType { get; set; }
public decimal Modifier { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
namespace NadekoBot.Modules.Searches.Commands.Models
{
public class Rates
{
public string Base { get; set; }
public DateTime Date { get; set; }
[JsonProperty("rates")]
public Dictionary<string, decimal> ConversionRates { get; set; }
}
}

View File

@ -2,6 +2,7 @@
using Discord.Commands; using Discord.Commands;
using NadekoBot.Attributes; using NadekoBot.Attributes;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Modules.Searches.Commands.Models;
using NadekoBot.Services; using NadekoBot.Services;
using NadekoBot.Services.Database.Models; using NadekoBot.Services.Database.Models;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -91,7 +92,7 @@ namespace NadekoBot.Modules.Searches
public List<ConvertUnit> Units { get; set; } public List<ConvertUnit> Units { get; set; }
[LocalizedCommand, LocalizedDescription, LocalizedSummary] [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task ConvertListE(IUserMessage msg) //extended and bugged list public async Task ConvertListE(IUserMessage msg) //extended and bugged list
{ {
@ -110,7 +111,7 @@ namespace NadekoBot.Modules.Searches
} }
await msg.ReplyLong(sb.ToString(), "```xl", "```", "```xl"); await msg.ReplyLong(sb.ToString(), "```xl", "```", "```xl");
} }
[LocalizedCommand, LocalizedDescription, LocalizedSummary] [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task ConvertList(IUserMessage msg) public async Task ConvertList(IUserMessage msg)
{ {
@ -124,7 +125,7 @@ namespace NadekoBot.Modules.Searches
} }
await msg.ReplyLong(sb.ToString(), "```xl", "```", "```xl"); await msg.ReplyLong(sb.ToString(), "```xl", "```", "```xl");
} }
[LocalizedCommand, LocalizedDescription, LocalizedSummary] [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
public async Task Convert(IUserMessage msg, string origin, string target, decimal 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()));
@ -184,7 +185,6 @@ namespace NadekoBot.Modules.Searches
} }
} }
public static async Task<Rates> UpdateCurrencyRates() public static async Task<Rates> UpdateCurrencyRates()
{ {
using (var http = new HttpClient()) using (var http = new HttpClient())
@ -193,22 +193,5 @@ namespace NadekoBot.Modules.Searches
return JsonConvert.DeserializeObject<Rates>(res); return JsonConvert.DeserializeObject<Rates>(res);
} }
} }
public class Rates
{
[JsonProperty("base")]
public string Base { get; set; }
[JsonProperty("date")]
public DateTime Date { get; set; }
[JsonProperty("rates")]
public Dictionary<string, decimal> ConversionRates { get; set; }
}
public class MeasurementUnit
{
public List<string> Triggers { get; set; }
public string UnitType { get; set; }
public decimal Modifier { get; set; }
}
} }
} }