Browse Source

add rcon post effect

master
gsd 2 years ago
parent
commit
6649c3bfa2
  1. 3
      .dockerignore
  2. 3
      .gitignore
  3. 4
      Dockerfile
  4. BIN
      docker-compose.yaml
  5. 27
      post_effect.py
  6. 10
      tradebot.facti13.py

3
.dockerignore

@ -1,2 +1,3 @@
auth_data/
.env
.env
servers.list

3
.gitignore

@ -1,2 +1,3 @@
auth_data/
.env
.env
servers.list

4
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 && \

BIN
docker-compose.yaml

Binary file not shown.

27
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))

10
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,

Loading…
Cancel
Save