-
Notifications
You must be signed in to change notification settings - Fork 5
/
SteamKitBot.cs
130 lines (115 loc) · 4.12 KB
/
SteamKitBot.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
using System;
using System.Threading.Tasks;
using ConsoleUtilities;
using Microsoft.Extensions.Logging;
using SDroid;
using SteamKit2;
namespace SDroidTest
{
internal class SteamKitBot : SDroid.SteamKitBot
{
// ReSharper disable once SuggestBaseTypeForParameter
public SteamKitBot(SteamKitBotSettings settings, ILogger botLogger) : base(settings, botLogger)
{
SubscribedCallbacks.Add(
CallbackManager.Subscribe<SteamFriends.FriendMsgCallback>(OnSteamFriendsMessage)
);
}
public new SteamKitBotSettings BotSettings
{
get => base.BotSettings as SteamKitBotSettings;
}
/// <inheritdoc />
public override async Task StartBot()
{
await base.StartBot().ConfigureAwait(false);
while (BotStatus != SteamBotStatus.Running && BotStatus != SteamBotStatus.Faulted)
{
await Task.Delay(TimeSpan.FromMilliseconds(200)).ConfigureAwait(false);
}
}
/// <inheritdoc />
protected override Task OnAccountInfoAvailable(SteamUser.AccountInfoCallback accountInfo)
{
ConsoleWriter.Default.WriteObject(new
{
accountInfo.AccountFlags,
accountInfo.CountAuthedComputers,
accountInfo.Country,
accountInfo.FacebookID,
accountInfo.FacebookName,
accountInfo.PersonaName
});
return Task.CompletedTask;
}
/// <inheritdoc />
protected override Task<string> OnAuthenticatorCodeRequired()
{
return Task.FromResult(ConsoleWriter.Default.PrintQuestion("Steam Guard Code"));
}
/// <inheritdoc />
protected override Task OnConnected()
{
return BotLogin();
}
/// <inheritdoc />
protected override Task OnLoggedIn()
{
BotLogger.LogInformation("Changing state to Online.");
SteamFriends.SetPersonaState(EPersonaState.Online);
return Task.CompletedTask;
}
/// <inheritdoc />
protected override Task<string> OnPasswordRequired()
{
return Task.FromResult(ConsoleWriter.Default.PrintQuestion("Password"));
}
/// <inheritdoc />
protected override Task OnWalletInfoAvailable(SteamUser.WalletInfoCallback walletInfo)
{
ConsoleWriter.Default.WriteObject(
new
{
walletInfo.Balance,
walletInfo.Currency,
walletInfo.HasWallet
}
);
return Task.CompletedTask;
}
private void OnSteamFriendsMessage(SteamFriends.FriendMsgCallback friendMsgCallback)
{
switch (friendMsgCallback.EntryType)
{
case EChatEntryType.ChatMsg:
BotLogger.LogInformation(
"New message from {0}. Message = {1}",
friendMsgCallback.Sender,
friendMsgCallback.Message
);
break;
case EChatEntryType.HistoricalChat:
BotLogger.LogInformation(
"Historic message from {0}. Message = {1}",
friendMsgCallback.Sender,
friendMsgCallback.Message
);
break;
case EChatEntryType.InviteGame:
BotLogger.LogInformation(
"Invited to game by {0}. Message = {1}",
friendMsgCallback.Sender,
friendMsgCallback.Message
);
break;
default:
BotLogger.LogInformation(
"Chat event by {0}. EChatEntryType = {1}",
friendMsgCallback.Sender,
friendMsgCallback.EntryType
);
break;
}
}
}
}