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.
210 lines
6.9 KiB
210 lines
6.9 KiB
import steam as SteamPy
|
|
import argparse, os, sys
|
|
from colors import *
|
|
from json import load
|
|
import asyncio
|
|
|
|
from db_driver import Database
|
|
from discord_alarm import DiscordAlarm
|
|
from post_effect import PostEffect
|
|
|
|
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):
|
|
db = None
|
|
items = TradeChecker()
|
|
discord_alarm = None
|
|
post_effect = None
|
|
|
|
trade_tracker = {}
|
|
|
|
async def on_ready(self):
|
|
info(f"Logged in as: {self.user}")
|
|
|
|
async def on_connect(self):
|
|
ok("Success connect to steam")
|
|
await self.db.connect()
|
|
|
|
async def on_disconnect(self):
|
|
ok("Disconnect from steam")
|
|
await self.db.disconnect()
|
|
|
|
#Проверка шмота на леквид
|
|
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 send_msg(trade, "Бот не сможет принять трейд от тебя по причине удержания вещей с твоей стороны")
|
|
await trade.decline()
|
|
return
|
|
|
|
if not trade.is_gift():
|
|
warning(f"[{trade.id}] partner wanna get bot items, decine trade")
|
|
#await send_msg(trade, "Не пытайся спиздить вещи у бота")
|
|
await trade.decline()
|
|
return
|
|
|
|
if len(trade.items_to_receive) > 25:
|
|
warning(f"[{trade.id}] cannot accept trade with more 25 items")
|
|
#await send_msg(trade, "За один раз можно отправить неболее 25 вещей")
|
|
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 send_msg(trade, "Ты отправил неправльные вещи! Проверь что это:\n- Ключ МаннКо (уникальный)\n- Очищенный метал (уникальный)")
|
|
await trade.decline()
|
|
return
|
|
|
|
info(f"[{trade.id}] Try accept trade")
|
|
#await send_msg(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}")
|
|
#await send_msg(trade, "Успешно, сейчас посчитаем сколько ты надонатил")
|
|
|
|
seconds = self.items.Items2Seconds(trade.items_to_receive)
|
|
result = await self.db.processing_vip(trade.partner, seconds)
|
|
await self.discord_alarm.alert(trade.partner, seconds)
|
|
await self.post_effect.execute()
|
|
|
|
if result == False:
|
|
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} дней")
|
|
|
|
return
|
|
|
|
if __name__ == "__main__":
|
|
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", ""))
|
|
parser.add_argument("--db-host", type=str, default=os.environ.get("DB_HOST", ""))
|
|
parser.add_argument("--db-username", type=str, default=os.environ.get("DB_USERNAME", ""))
|
|
parser.add_argument("--db-password", type=str, default=os.environ.get("DB_PASSWORD", ""))
|
|
parser.add_argument("--db-name", type=str, default=os.environ.get("DB_NAME", ""))
|
|
parser.add_argument("--discord-url", type=str, default=os.environ.get("DISCORD_WEBHOOK_URL", ""))
|
|
parser.add_argument("--servers-list", type=str, default=os.environ.get("SERVERS_LIST", ""))
|
|
args = parser.parse_args()
|
|
|
|
client = SteamClient(game = SteamPy.Game(id=440))
|
|
|
|
if args.db_host and args.db_username and args.db_password and args.db_name:
|
|
client.db = Database(args.db_host, args.db_username, args.db_password, args.db_name)
|
|
else:
|
|
error("DB data not be setted")
|
|
sys.exit(1)
|
|
|
|
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)
|
|
|
|
if args.discord_url:
|
|
client.discord_alarm = DiscordAlarm(args.discord_url)
|
|
else:
|
|
error("need discord webhook")
|
|
sys.exit(5)
|
|
|
|
if args.servers_list:
|
|
client.post_effect = PostEffect(args.servers_list)
|
|
else:
|
|
error("need servers list file")
|
|
sys.exit(6)
|
|
|
|
client.run(
|
|
username=login,
|
|
password = password,
|
|
shared_secret=secrets["shared_secret"],
|
|
identity_secret=secrets["identity_secret"],
|
|
)
|
|
|