-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTradeOfferBot.cs
172 lines (145 loc) · 5.12 KB
/
TradeOfferBot.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System;
using System.Threading.Tasks;
using ConsoleUtilities;
using Microsoft.Extensions.Logging;
using SDroid;
using SDroid.Interfaces;
using SDroid.SteamTrade;
namespace SDroidTest
{
// ReSharper disable once InconsistentNaming
internal class TradeOfferBot : SteamBot, ITradeOfferBot
{
// ReSharper disable once SuggestBaseTypeForParameter
public TradeOfferBot(TradeOfferBotSettings settings, ILogger botLogger) : base(settings, botLogger)
{
}
public new TradeOfferBotSettings BotSettings
{
get => base.BotSettings as TradeOfferBotSettings;
}
public UserInventory MyInventory { get; protected set; }
/// <inheritdoc />
public Task OnTradeOfferAccepted(TradeOffer tradeOffer)
{
return Task.CompletedTask;
}
/// <inheritdoc />
public Task OnTradeOfferCanceled(TradeOffer tradeOffer)
{
return Task.CompletedTask;
}
/// <inheritdoc />
public Task OnTradeOfferChanged(TradeOffer tradeOffer)
{
return Task.CompletedTask;
}
/// <inheritdoc />
public Task OnTradeOfferDeclined(TradeOffer tradeOffer)
{
return Task.CompletedTask;
}
/// <inheritdoc />
public Task OnTradeOfferInEscrow(TradeOffer tradeOffer)
{
return Task.CompletedTask;
}
/// <inheritdoc />
public Task OnTradeOfferNeedsConfirmation(TradeOffer tradeOffer)
{
return Task.CompletedTask;
}
/// <inheritdoc />
public Task OnTradeOfferReceived(TradeOffer tradeOffer)
{
return Task.CompletedTask;
}
/// <inheritdoc />
public Task OnTradeOfferSent(TradeOffer tradeOffer)
{
return Task.CompletedTask;
}
/// <inheritdoc />
public ITradeOfferBotSettings TradeOfferBotSettings
{
get => BotSettings;
}
/// <inheritdoc />
TradeOfferManager ITradeOfferBot.TradeOfferManager { get; set; }
/// <inheritdoc />
public override async Task StartBot()
{
await base.StartBot().ConfigureAwait(false);
if (BotStatus != SteamBotStatus.Running)
{
await BotLogin().ConfigureAwait(false);
}
}
public async Task AcceptTradeOfferById(long tradeOfferId)
{
try
{
var tradeOfferManager = (this as ITradeOfferBot).TradeOfferManager;
var tradeOffer = await tradeOfferManager.GetTradeOffer(tradeOfferId).ConfigureAwait(false);
if (tradeOffer != null)
{
await tradeOfferManager.Accept(tradeOffer).ConfigureAwait(false);
BotLogger.LogInformation("Requested to accept trade offer #{0}", tradeOffer.TradeOfferId);
}
else
{
BotLogger.LogInformation("Trade offer #{0} not found.", tradeOfferId);
}
}
catch (Exception e)
{
BotLogger.LogError(e, e.Message);
}
}
public async Task DeclineTradeOfferById(long tradeOfferId)
{
try
{
var tradeOfferManager = (this as ITradeOfferBot).TradeOfferManager;
var tradeOffer = await tradeOfferManager.GetTradeOffer(tradeOfferId).ConfigureAwait(false);
if (tradeOffer != null)
{
await tradeOfferManager.Decline(tradeOffer).ConfigureAwait(false);
BotLogger.LogInformation("Requested to decline trade offer #{0}", tradeOffer.TradeOfferId);
}
else
{
BotLogger.LogInformation("Trade offer #{0} not found.", tradeOfferId);
}
}
catch (Exception e)
{
BotLogger.LogError(e, e.Message);
}
}
/// <inheritdoc />
protected override Task<string> OnAuthenticatorCodeRequired()
{
return Task.FromResult(ConsoleWriter.Default.PrintQuestion("Steam Guard Code"));
}
/// <inheritdoc />
protected override async Task OnLoggedIn()
{
BotLogger.LogInformation("Retrieving bot's inventory.");
if (MyInventory == null)
{
MyInventory = await UserInventory.GetInventory(WebAccess, SteamId).ConfigureAwait(false);
}
MyInventory.ClearCache();
//var assets = await MyInventory.GetAssets().ConfigureAwait(false);
//await BotLogger.Info(nameof(OnLoggedIn), "{0} assets found in bot's inventory.", assets.Length)
// .ConfigureAwait(false);
await base.OnLoggedIn().ConfigureAwait(false);
}
/// <inheritdoc />
protected override Task<string> OnPasswordRequired()
{
return Task.FromResult(ConsoleWriter.Default.PrintQuestion("Password"));
}
}
}