|
|
|
|
18
|
{
|
18
|
{
|
19
|
class Program
|
19
|
class Program
|
20
|
{
|
20
|
{
|
|
|
21
|
+ const string SHORT_DURATION = "SHORT";
|
21
|
private static BlizzSharpClient _client;
|
22
|
private static BlizzSharpClient _client;
|
22
|
private static PushClient _pushClient;
|
23
|
private static PushClient _pushClient;
|
23
|
private static IEnumerable<Auction> lastAuctions;
|
24
|
private static IEnumerable<Auction> lastAuctions;
|
24
|
private static IConfiguration _configuration;
|
25
|
private static IConfiguration _configuration;
|
25
|
private static ILog _logger;
|
26
|
private static ILog _logger;
|
26
|
|
27
|
|
|
|
28
|
+ private static string _character;
|
|
|
29
|
+ private static string _locale;
|
|
|
30
|
+ private static string _realm;
|
|
|
31
|
+
|
27
|
private static string FormatCurrency(long full)
|
32
|
private static string FormatCurrency(long full)
|
28
|
{
|
33
|
{
|
29
|
long gold = full / 10000;
|
34
|
long gold = full / 10000;
|
|
|
|
|
33
|
}
|
38
|
}
|
34
|
private static async Task RunUpdate()
|
39
|
private static async Task RunUpdate()
|
35
|
{
|
40
|
{
|
36
|
- AuctionResponse response = await _client.GetAuctionsAsync("Khaz'goroth", "en_GB");
|
|
|
37
|
- IEnumerable<Auction> auctions = response.Auctions.Where(a => a.Owner == "Karathan");
|
|
|
|
|
41
|
+ _logger.Info($"Running Update for {_character} on {_realm}");
|
|
|
42
|
+ AuctionResponse response = await _client.GetAuctionsAsync(_realm, _locale);
|
|
|
43
|
+ IEnumerable<Auction> auctions = response.Auctions.Where(a => a.Owner == _character);
|
38
|
if(lastAuctions != null)
|
44
|
if(lastAuctions != null)
|
39
|
{
|
45
|
{
|
40
|
HashSet<Auction> expiredAuctions = new HashSet<Auction>();
|
46
|
HashSet<Auction> expiredAuctions = new HashSet<Auction>();
|
|
|
|
|
44
|
if(!auctions.Any(b => b.Id == a.Id))
|
50
|
if(!auctions.Any(b => b.Id == a.Id))
|
45
|
{
|
51
|
{
|
46
|
//the auction is now gone, but why?
|
52
|
//the auction is now gone, but why?
|
47
|
- Item item = await _client.GetItemInfoAsync(a.Item, "en_GB");
|
|
|
48
|
- if(a.TimeLeft == "SHORT")
|
|
|
|
|
53
|
+ Item item = await _client.GetItemInfoAsync(a.Item, _locale);
|
|
|
54
|
+ if(a.TimeLeft == SHORT_DURATION)
|
49
|
{
|
55
|
{
|
50
|
//the auction probably expired
|
56
|
//the auction probably expired
|
51
|
expiredAuctions.Add(a);
|
57
|
expiredAuctions.Add(a);
|
|
|
|
|
61
|
if(!removedFound)
|
67
|
if(!removedFound)
|
62
|
{
|
68
|
{
|
63
|
_logger.Info("No Expired/Sold Auctions found");
|
69
|
_logger.Info("No Expired/Sold Auctions found");
|
64
|
- Console.WriteLine("No Expired/Sold Auctions found");
|
|
|
65
|
}
|
70
|
}
|
66
|
if(expiredAuctions.Any())
|
71
|
if(expiredAuctions.Any())
|
67
|
{
|
72
|
{
|
68
|
StringBuilder sb = new StringBuilder();
|
73
|
StringBuilder sb = new StringBuilder();
|
69
|
foreach(Auction a in expiredAuctions)
|
74
|
foreach(Auction a in expiredAuctions)
|
70
|
{
|
75
|
{
|
71
|
- string name = (await _client.GetItemInfoAsync(a.Item, "en_GB")).Name;
|
|
|
|
|
76
|
+ string name = (await _client.GetItemInfoAsync(a.Item, _locale)).Name;
|
72
|
sb.AppendLine($"{a.quantity}x {name}");
|
77
|
sb.AppendLine($"{a.quantity}x {name}");
|
73
|
}
|
78
|
}
|
74
|
await _pushClient.SendNotification($"Your Auctions have expired:\n{sb.ToString()}", "none");
|
79
|
await _pushClient.SendNotification($"Your Auctions have expired:\n{sb.ToString()}", "none");
|
|
|
|
|
88
|
.SetBasePath(Directory.GetCurrentDirectory())
|
93
|
.SetBasePath(Directory.GetCurrentDirectory())
|
89
|
.AddJsonFile("appsettings.json");
|
94
|
.AddJsonFile("appsettings.json");
|
90
|
_configuration = builder.Build();
|
95
|
_configuration = builder.Build();
|
|
|
96
|
+ _character = _configuration["character"];
|
|
|
97
|
+ _locale = _configuration["locale"];
|
|
|
98
|
+ _realm = _configuration["realm"];
|
91
|
_logger.Info("Creating Clients");
|
99
|
_logger.Info("Creating Clients");
|
92
|
_client = new BlizzSharpClient($"{_configuration["blizzardApiKey"]}");
|
100
|
_client = new BlizzSharpClient($"{_configuration["blizzardApiKey"]}");
|
93
|
_pushClient = new PushClient($"{_configuration["pushoverSecretKey"]}", $"{_configuration["pushoverUserKey"]}");
|
101
|
_pushClient = new PushClient($"{_configuration["pushoverSecretKey"]}", $"{_configuration["pushoverUserKey"]}");
|