You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

185 lines
5.5 KiB

import steam as SteamPy
import argparse, os, sys
from colors import *
from json import load
import asyncio
from backend_integration import BackendClient
class TradeChecker:
APP_ID = 440
MONTH = 2678400
WEEK = 604800
DAY = 86400
def mannco_key(self, items):
class_id = 101785959
instance_id = 11040578
count = 0
for item in items:
#print(f"{item._app_id} {item.class_id} {item.instance_id}")
if int(item._app_id) == self.APP_ID and int(item.class_id) == class_id and int(item.instance_id) == instance_id:
count += 1
return count
def pure_metal(self, items):
class_id = 2674
instance_id = 11040547
count = 0
for item in items:
#print(f"{item._app_id} {item.class_id} {item.instance_id}")
if int(item._app_id) == self.APP_ID and int(item.class_id) == class_id and int(item.instance_id) == instance_id:
count += 1
return count
def Items2Seconds(self, items):
key_count = self.mannco_key(items)
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
return final_amount
async def send_msg(trade: SteamPy.TradeOffer, message: str):
try:
await trade.partner.send(message)
except:
error(f"[{trade.id}] Cannot send message")
class SteamClient(SteamPy.Client):
items = TradeChecker()
trade_tracker = {}
backend = BackendClient()
async def on_ready(self):
info(f"Logged in as: {self.user}")
async def on_connect(self):
await self.backend.pulse()
ok("Success connect to steam")
async def on_disconnect(self):
await self.backend.pulse()
ok("Disconnect from steam")
#Проверка шмота на леквид
async def on_trade_receive(self, trade: SteamPy.TradeOffer):
info(f"[{trade.id}] Incoming trade from [{trade.partner.id}] {trade.partner.name}")
if trade.state != SteamPy.enums.TradeOfferState.Active:
error(f"[{trade.id}] trade have not active stats")
await trade.decline()
return
if not trade.is_gift():
warning(f"[{trade.id}] partner wanna get bot items, decine trade")
await trade.decline()
return
if len(trade.items_to_receive) > 25:
warning(f"[{trade.id}] cannot accept trade with more 25 items")
await trade.decline()
return
seconds = self.items.Items2Seconds(trade.items_to_receive)
if seconds == 0:
error(f"[{trade.id}] cannot accept trade not valid items")
await trade.decline()
return
pulse_result = await self.backend.pulse()
if not pulse_result:
error("Backend not response ot pulse, drop trade")
return
info(f"[{trade.id}] Try accept trade")
await trade.accept()
info(f"[{trade.id}] Maybe trade acceped...")
#Force on trade accept
await asyncio.sleep(3)
if not trade.id in self.trade_tracker:
self.trade_tracker[trade.id] = 60
while self.trade_tracker[trade.id] > 2:
await asyncio.sleep(1)
self.trade_tracker[trade.id] -= 1
await self.on_trade_accept(trade)
return
#Принятый трейд
async def on_trade_accept(self, trade: SteamPy.TradeOffer):
info(f"[{trade.id}] Finalize accept")
if trade.id in self.trade_tracker and self.trade_tracker[trade.id] == 0:
return
if trade.id in self.trade_tracker and self.trade_tracker[trade.id] > 0:
self.trade_tracker[trade.id] = 0
if not trade.id in self.trade_tracker:
self.trade_tracker[trade.id] = 0
if not trade.is_gift():
return
info(f"[{trade.id}] Final stage accepted trade [{trade.partner.id}] {trade.partner.name}")
pulse_result = await self.backend.pulse()
if not pulse_result:
warning("Backend not responde, any time try add vip")
extra = f"keys={self.items.mannco_key(trade.items_to_receive)};metal={self.items.pure_metal(trade.items_to_receive)};"
seconds = self.items.Items2Seconds(trade.items_to_receive)
result = await self.backend.vip(trade.partner, seconds, extra)
if result == 99:
await send_msg(trade, "Спасибо за вещи, но у тебя уже есть КРУТЫЕ права на фактах")
elif result == 100:
await send_msg(trade, f"Мои поздавления! Ты получил випку на {seconds / 60 / 60 / 24} дней")
elif result == 101:
await send_msg(trade, f"Круто! Ты продлил випку на {seconds / 60 / 60 / 24} дней")
else:
await send_msg(trade, "Произошла ошибка добавление випа, сообщи об этом разрабу")
return
if __name__ == "__main__":
print(f"Build date: {os.getenv('BUILDDATE', 'not set')}")
parser = argparse.ArgumentParser()
parser.add_argument("--auth-file", type=str, default=os.environ.get("AUTH_FILE", ""))
parser.add_argument("--steam-secret", type=str, default=os.environ.get("STEAM_SECRET", ""))
args = parser.parse_args()
client = SteamClient(game = SteamPy.Game(id=440))
if args.auth_file and args.steam_secret:
try:
with open(args.auth_file, "r") as auth_file:
login = auth_file.readline()[:-1]
password = auth_file.readline()
except:
error("steam auth data is not correct")
sys.exit(3)
try:
with open(args.steam_secret, "r") as steam_file:
secrets = load(steam_file)
#shared_secret
#identity_secret
except:
error("steam secret is not correct")
sys.exit(4)
else:
error("steam auth data or steam secret not be setted")
sys.exit(2)
client.run(
username=login,
password = password,
shared_secret=secrets["shared_secret"],
identity_secret=secrets["identity_secret"],
)