diff --git a/.dockerignore b/.dockerignore index b1c70ae..8baece8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ auth_data/ -.env \ No newline at end of file +.env +servers.list \ No newline at end of file diff --git a/.gitignore b/.gitignore index b1c70ae..8baece8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ auth_data/ -.env \ No newline at end of file +.env +servers.list \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index fb487f5..cdb571c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -FROM python:3.7 +FROM python:3.10 RUN groupadd -g 1000 service && useradd -g 1000 -u 1000 service ENV TZ=Europe/Moscow -RUN python -m pip install aiomysql aiohttp steamio +RUN python -m pip install aiomysql aiohttp steamio git+https://github.com/conqp/rcon RUN mkdir /home/service && \ cp /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \ diff --git a/docker-compose.yaml b/docker-compose.yaml index 224b8b5..7038ecf 100644 Binary files a/docker-compose.yaml and b/docker-compose.yaml differ diff --git a/post_effect.py b/post_effect.py new file mode 100644 index 0000000..4647dc3 --- /dev/null +++ b/post_effect.py @@ -0,0 +1,27 @@ +from colors import * +from rcon.source import rcon + +class PostEffect: + servers = [] + def __init__(self, path): + with open(path, "r") as servers_file: + servers = servers_file.readlines() + for line in servers: + try: + address, rcon, command = line.replace("\n","").split("|") + self.servers.append({ + "ip": address.split(":")[0], + "port": int(address.split(":")[1]), + "rcon": rcon, + "command": command + }) + except: + pass + + async def execute(self): + for server in self.servers: + try: + info("{ip}:{port} execute {command}".format(**server)) + await rcon(server["command"], host=server["ip"], port=server["port"], passwd=server["rcon"]) + except: + error("Server {ip}:{port} not response".format(**server)) \ No newline at end of file diff --git a/tradebot.facti13.py b/tradebot.facti13.py index 440a16a..cfd56e5 100644 --- a/tradebot.facti13.py +++ b/tradebot.facti13.py @@ -6,6 +6,7 @@ from colors import * from db_driver import Database from json import load from discord_alarm import DiscordAlarm +from post_effect import PostEffect class TradeChecker: APP_ID = 440 @@ -57,6 +58,7 @@ class SteamClient(SteamPy.Client): db = None items = TradeChecker() discord_alarm = None + post_effect = None async def on_ready(self): info(f"Logged in as: {self.user}") @@ -120,6 +122,7 @@ class SteamClient(SteamPy.Client): elif result == 101: await send_msg(trade, f"Круто! Ты продлил випку на {seconds / 60 / 60 / 24} дней") await self.discord_alarm.alert(trade.partner, seconds) + await self.post_effect.execute() return if __name__ == "__main__": @@ -131,6 +134,7 @@ if __name__ == "__main__": 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)) @@ -168,6 +172,12 @@ if __name__ == "__main__": 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,