-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathASFConnector.py
executable file
·323 lines (308 loc) · 11.5 KB
/
ASFConnector.py
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import logger
import requests
import json
from IPCProtocol import IPCProtocolHandler
LOG = None
class ASFConnector:
def __init__(self, host='127.0.0.1', port='1242', path='/Api', password=None):
global LOG
LOG = logger.get_logger(__name__)
self.host = host
self.port = port
self.path = path
LOG.debug(__name__ + " initialized. Host: '%s'. Port: '%s'", host, port)
self.connection_handler = IPCProtocolHandler(host, port, path, password)
def get_asf_info(self):
"""" Fetches common info related to ASF as a whole. """
data = self.connection_handler.get('/ASF')
LOG.debug(data)
return data
def get_bot_info(self, bot):
""" Fetches common info related to given bots. """
LOG.debug('get_bot_info: bot {}'.format(bot))
resource = '/Bot/' + bot
response = self.connection_handler.get(resource)
if 'Result' in response:
message = ""
for bot_name in response['Result']:
message += 'Bot {}: '.format(bot_name)
bot = response['Result'][bot_name]
if bot['IsConnectedAndLoggedOn']:
cards_farmer = bot['CardsFarmer']
farm_message = ""
if cards_farmer['Paused']:
farm_message += 'Farming paused.'
elif cards_farmer['CurrentGamesFarming']:
farm_message += 'Currently farming games:'
for current_games in cards_farmer['CurrentGamesFarming']:
appid = current_games['AppID']
appname = current_games['GameName']
cards_remaining = current_games['CardsRemaining']
farm_message += '\n\t[{}/{}] {} cards remaining.'.format(appid, appname, cards_remaining)
if len(cards_farmer['GamesToFarm']) > 0:
farm_message += ' {} game(s) to farm ('.format(len(cards_farmer['GamesToFarm']))
for games_to_farm in cards_farmer['GamesToFarm']:
appid = games_to_farm['AppID']
appname = games_to_farm['GameName']
farm_message += '[{}/{}] '.format(appid, appname)
farm_message = farm_message[:-1] + "). "
time_remaining = cards_farmer['TimeRemaining']
if time_remaining != '00:00:00':
farm_message += 'Time remaining: {}'.format(time_remaining)
if len(farm_message) == 0:
farm_message += 'Idle.'
message += farm_message + '\n'
else:
if len(bot['BotConfig']) == 0:
message += 'Not configured.\n'
else:
message += 'Offline.\n'
elif response['Success']:
message = 'Bot {} not found.'.format(bot)
else:
message = 'Getting bot info failed: {}'.format(response['Message'])
return message
def bot_redeem(self, bot, keys):
""" Redeems cd-keys on given bot. """
LOG.debug('bot_redeem: bot {}, keys {}'.format(bot, keys))
assert type(keys) is set or type(keys) is str
resource = '/Bot/' + bot + '/Redeem'
if type(keys) is str:
payload_keys = [keys]
else:
payload_keys = []
for key in keys:
payload_keys.append(key)
data = {'KeysToRedeem': payload_keys}
response = self.connection_handler.post(resource, payload=data)
if 'Result' in response:
results = response['Result']
message = ""
for bot_name in results:
bot = results[bot_name]
for key in bot:
if bot[key]:
message += "Bot {}: \n".format(bot_name)
if 'purchase_receipt_info' in bot[key] and bot[key]['purchase_receipt_info']:
purchase_receipt_info = bot[key]['purchase_receipt_info']
items = ''
# Parse items in the key
for item in purchase_receipt_info['line_items']:
items += '[{}, {}] '.format(item['packageid'], item['line_item_description'])
# Build message with the receipt info and the items
message += "\t[{}] {}: {}/{}\n".format(
key, items, purchase_receipt_info['purchase_status']
if type(purchase_receipt_info['purchase_status']) is str
else Result[purchase_receipt_info['purchase_status']],
purchase_receipt_info['result_detail'] if type(purchase_receipt_info['result_detail']) is str
else PurchaseResultDetail[purchase_receipt_info['result_detail']])
else:
message += "\t[{}] {}/{}\n".format(
key, bot[key]['Result'] if type(bot[key]['Result']) is str
else Result[bot[key]['Result']],
bot[key]['PurchaseResultDetail'] if type(bot[key]['PurchaseResultDetail']) is str
else PurchaseResultDetail[bot[key]['PurchaseResultDetail']])
elif response['Success']:
message = 'Bot {} not found.'.format(bot)
else:
message = 'Redeem failed: {}'.format(response['Message'])
return message
def send_command(self, command):
"""
This API endpoint is supposed to be entirely replaced by ASF actions available under /Api/ASF/{action} and /Api/Bot/{bot}/{action}.
You should use “given bot” commands when executing this endpoint, omitting targets of the command will cause the command to be executed on first defined bot
"""
LOG.debug("Send command: {}".format(command))
resource = '/Command/'
data = {"Command": command}
response = self.connection_handler.post(resource, payload=data)
message = ""
if response['Success']:
message += response['Result']
else:
message += 'Command unsuccessful: {}'.format(response['Message'])
return message
PurchaseResultDetail = {
0: 'NoDetail',
1: 'AVSFailure',
2: 'InsufficientFunds',
3: 'ContactSupport',
4: 'Timeout',
5: 'InvalidPackage',
6: 'InvalidPaymentMethod',
7: 'InvalidData',
8: 'OthersInProgress',
9: 'AlreadyPurchased',
10: 'WrongPrice',
11: 'FraudCheckFailed',
12: 'CancelledByUser',
13: 'RestrictedCountry',
14: 'BadActivationCode',
15: 'DuplicateActivationCode',
16: 'UseOtherPaymentMethod',
17: 'UseOtherFunctionSource',
18: 'InvalidShippingAddress',
19: 'RegionNotSupported',
20: 'AcctIsBlocked',
21: 'AcctNotVerified',
22: 'InvalidAccount',
23: 'StoreBillingCountryMismatch',
24: 'DoesNotOwnRequiredApp',
25: 'CanceledByNewTransaction',
26: 'ForceCanceledPending',
27: 'FailCurrencyTransProvider',
28: 'FailedCyberCafe',
29: 'NeedsPreApproval',
30: 'PreApprovalDenied',
31: 'WalletCurrencyMismatch',
32: 'EmailNotValidated',
33: 'ExpiredCard',
34: 'TransactionExpired',
35: 'WouldExceedMaxWallet',
36: 'MustLoginPS3AppForPurchase',
37: 'CannotShipToPOBox',
38: 'InsufficientInventory',
39: 'CannotGiftShippedGoods',
40: 'CannotShipInternationally',
41: 'BillingAgreementCancelled',
42: 'InvalidCoupon',
43: 'ExpiredCoupon',
44: 'AccountLocked',
45: 'OtherAbortableInProgress',
46: 'ExceededSteamLimit',
47: 'OverlappingPackagesInCart',
48: 'NoWallet',
49: 'NoCachedPaymentMethod',
50: 'CannotRedeemCodeFromClient',
51: 'PurchaseAmountNoSupportedByProvider',
52: 'OverlappingPackagesInPendingTransaction',
53: 'RateLimited',
54: 'OwnsExcludedApp',
55: 'CreditCardBinMismatchesType',
56: 'CartValueTooHigh',
57: 'BillingAgreementAlreadyExists',
58: 'POSACodeNotActivated',
59: 'CannotShipToCountry',
60: 'HungTransactionCancelled',
61: 'PaypalInternalError',
62: 'UnknownGlobalCollectError',
63: 'InvalidTaxAddress',
64: 'PhysicalProductLimitExceeded',
65: 'PurchaseCannotBeReplayed',
66: 'DelayedCompletion',
67: 'BundleTypeCannotBeGifted'
}
Result = {
0: 'Invalid',
1: 'OK',
2: 'Fail',
3: 'NoConnection',
4: 'InvalidPassword',
5: 'LoggedInElsewhere',
6: 'InvalidProtocolVer',
7: 'InvalidParam',
8: 'FileNotFound',
9: 'Busy',
10: 'InvalidState',
11: 'InvalidName',
12: 'InvalidEmail',
13: 'DuplicateName',
14: 'AccessDenied',
15: 'Timeout',
16: 'Banned',
17: 'AccountNotFound',
18: 'InvalidSteamID',
19: 'ServiceUnavailable',
20: 'NotLoggedOn',
21: 'Pending',
22: 'EncryptionFailure',
23: 'InsufficientPrivilege',
24: 'LimitExceeded',
25: 'Revoked',
26: 'Expired',
27: 'AlreadyRedeemed',
28: 'DuplicateRequest',
29: 'AlreadyOwned',
30: 'IPNotFound',
31: 'PersistFailed',
32: 'LockingFailed',
33: 'LogonSessionReplaced',
34: 'ConnectFailed',
35: 'HandshakeFailed',
36: 'IOFailure',
37: 'RemoteDisconnect',
38: 'ShoppingCartNotFound',
39: 'Blocked',
40: 'Ignored',
41: 'NoMatch',
42: 'AccountDisabled',
43: 'ServiceReadOnly',
44: 'AccountNotFeatured',
45: 'AdministratorOK',
46: 'ContentVersion',
47: 'TryAnotherCM',
48: 'PasswordRequiredToKickSession',
49: 'AlreadyLoggedInElsewhere',
50: 'Suspended',
51: 'Cancelled',
52: 'DataCorruption',
53: 'DiskFull',
54: 'RemoteCallFailed',
55: 'PasswordUnset',
56: 'ExternalAccountUnlinked',
57: 'PSNTicketInvalid',
58: 'ExternalAccountAlreadyLinked',
59: 'RemoteFileConflict',
60: 'IllegalPassword',
61: 'SameAsPreviousValue',
62: 'AccountLogonDenied',
63: 'CannotUseOldPassword',
64: 'InvalidLoginAuthCode',
65: 'AccountLogonDeniedNoMail',
66: 'HardwareNotCapableOfIPT',
67: 'IPTInitError',
68: 'ParentalControlRestricted',
69: 'FacebookQueryError',
70: 'ExpiredLoginAuthCode',
71: 'IPLoginRestrictionFailed',
72: 'AccountLockedDown',
73: 'AccountLogonDeniedVerifiedEmailRequired',
74: 'NoMatchingURL',
75: 'BadResponse',
76: 'RequirePasswordReEntry',
77: 'ValueOutOfRange',
78: 'UnexpectedError',
79: 'Disabled',
80: 'InvalidCEGSubmission',
81: 'RestrictedDevice',
82: 'RegionLocked',
83: 'RateLimitExceeded',
84: 'AccountLoginDeniedNeedTwoFactor',
85: 'ItemDeleted',
86: 'AccountLoginDeniedThrottle',
87: 'TwoFactorCodeMismatch',
88: 'TwoFactorActivationCodeMismatch',
89: 'AccountAssociatedToMultiplePartners',
90: 'NotModified',
91: 'NoMobileDevice',
92: 'TimeNotSynced',
93: 'SMSCodeFailed',
94: 'AccountLimitExceeded',
95: 'AccountActivityLimitExceeded',
96: 'PhoneActivityLimitExceeded',
97: 'RefundToWallet',
98: 'EmailSendFailure',
99: 'NotSettled',
100: 'NeedCaptcha',
101: 'GSLTDenied',
102: 'GSOwnerDenied',
103: 'InvalidItemType',
104: 'IPBanned',
105: 'GSLTExpired',
106: 'InsufficientFunds',
107: 'TooManyPending',
108: 'NoSiteLicensesFound',
109: 'WGNetworkSendExceeded',
110: 'AccountNotFriends',
111: 'LimitedUserAccount'
}