Browse Source

деньги мне неси

master
gsd 2 years ago
parent
commit
711da8630c
  1. 7
      backend_integration.py
  2. 39
      tradebot.facti13.external.py

7
backend_integration.py

@ -54,4 +54,9 @@ class BackendClient:
error(f"[S64:{steamid.id64}] Backend returned error")
traceback.print_exc()
return False
return False
return False
async def prices(self):
async with aiohttp.ClientSession() as session:
async with session.get(self.vip_url) as response:
return await response.json()

39
tradebot.facti13.external.py

@ -15,6 +15,19 @@ class TradeChecker:
WEEK = 604800
DAY = 86400
prices_map = {}
def __init__(self, prices):
for price in prices:
if price["money_price"] == 0:
continue
self.prices_map[price['period']] = int(price["item_price"].split()[0])
if not self.prices_map:
error("cannot parse prices")
sys.exit(228)
else:
info(f"{self.prices_map}")
def mannco_key(self, items):
class_id = 101785959
instance_id = 11040578
@ -40,11 +53,14 @@ class TradeChecker:
metal_count = self.pure_metal(items)
final_amount = 0
#print(key_count, ",", metal_count)
final_amount += key_count * self.MONTH
if(metal_count >= 20):
final_amount += (metal_count / 20) * self.WEEK
elif(metal_count >= 5):
final_amount += (metal_count / 5) * self.DAY
#ключ всегда месяц ибо стабильная единица
if(key_count >= self.prices_map["month"]):
final_amount += key_count * self.MONTH
if(metal_count >= self.prices_map["week"]):
final_amount += (metal_count / self.prices_map["week"]) * self.WEEK
elif(metal_count >= self.prices_map["day"]):
final_amount += (metal_count / self.prices_map["day"]) * self.DAY
return final_amount
@ -56,12 +72,14 @@ async def send_msg(trade: SteamPy.TradeOffer, message: str):
error(f"[{trade.id}] Cannot send message")
class SteamClient(SteamPy.Client):
items = TradeChecker()
items = None
trade_tracker = {}
backend : BackendClient = None
async def on_ready(self):
info(f"Logged in as: {self.user}")
prices = await self.backend.prices()
self.items = TradeChecker(prices)
async def on_connect(self):
await self.backend.pulse()
@ -73,6 +91,11 @@ class SteamClient(SteamPy.Client):
#Проверка шмота на леквид
async def on_trade_receive(self, trade: SteamPy.TradeOffer):
if not self.items:
info("prices is not setup")
prices = await self.backend.prices()
self.items = TradeChecker(prices)
info(f"[{trade.id}] Incoming trade from [{trade.partner.id}] {trade.partner.name}")
if trade.state != SteamPy.enums.TradeOfferState.Active:
@ -85,8 +108,8 @@ class SteamClient(SteamPy.Client):
await trade.decline()
return
if len(trade.items_to_receive) > 25:
warning(f"[{trade.id}] cannot accept trade with more 25 items")
if len(trade.items_to_receive) > 50:
warning(f"[{trade.id}] cannot accept trade with more 50 items")
await trade.decline()
return

Loading…
Cancel
Save