From 8bbbcdedef1b1c4086fa216778b7714669566e48 Mon Sep 17 00:00:00 2001 From: Anatoly Date: Sun, 23 Jan 2022 18:19:32 +0300 Subject: [PATCH] Initial commit --- .gitignore | 3 ++ README.md | 4 +++ connection.py.example | 5 ++++ main.py | 70 +++++++++++++++++++++++++++++++++++++++++++ users.json.example | 4 +++ 5 files changed, 86 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 connection.py.example create mode 100755 main.py create mode 100644 users.json.example diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd74c67 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/__pycache__/ +/connection.py +/users.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..bb4bc75 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# ts3-rank-bot + +A bot that automatically sets a teamspeak group according +to the persons rainbow 6 siege rank diff --git a/connection.py.example b/connection.py.example new file mode 100644 index 0000000..ea33b6a --- /dev/null +++ b/connection.py.example @@ -0,0 +1,5 @@ +HOST = "0.0.0.0" +PORT = 10011 +SID = 315 +USER = "rank_bot" +PASS = "password" \ No newline at end of file diff --git a/main.py b/main.py new file mode 100755 index 0000000..b7c4a1e --- /dev/null +++ b/main.py @@ -0,0 +1,70 @@ +import sys +from lxml import html +import json +import requests +import time +import telnetlib +from connection import * + +with open('users.json', 'r') as f: + users = json.load(f) + +groups = { + 'COPPER': '6351', + 'BRONZE': '6352', + 'SILVER': '6353', + 'GOLD': '6354', + 'PLATINUM': '6355', + 'DIAMOND': '6356' +} + + +def run(*arg): + cmnd = b"" + for i in arg: + if isinstance(i, int): + i = str(i) + cmnd = cmnd + i.encode('ascii') + b" " + + time.sleep(0.3) + tn.write(cmnd + b"\n") + return tn.read_until(b"msg").decode('ascii', 'ignore') + + +tn = telnetlib.Telnet(HOST, PORT) + +print(tn.read_sb_data().decode('ascii')) +run("login", USER, PASS) +run("use", SID) + +raw_list = run("clientlist") +print(raw_list) +print("USERCOUNT: " + str(raw_list.count("client_nickname")-1)) + +nick = [] +last_index = 0 +for i in range(raw_list.count("client_nickname")): + raw_list = raw_list[raw_list.find("client_nickname=", last_index) + len("client_nickname="):] + nick.append(raw_list.split(" ", 1)[0]) + print(raw_list.split(" ", 1)[0]) + +for nick, cldbid in users.items(): + try: + print("Setting rank for "+nick+"; "+str(cldbid)) + page = requests.get('https://r6.tracker.network/profile/pc/' + nick) + tree = html.fromstring(page.content) + + if tree.xpath('//div[@class="trn-text--dimmed trn-text--center"]/text()'): + rank = tree.xpath('//div[@class="trn-text--dimmed trn-text--center"]/text()')[0] + " " + print("Scraped rank: " + rank) + + for r, id in groups.items(): + if rank.startswith(r): + run("servergroupaddclient sgid=" + str(id), "cldbid=" + str(cldbid)) + else: + run("servergroupdelclient sgid=" + str(id), "cldbid=" + str(cldbid)) + except: + print("Something went wrong!") + +tn.close() + diff --git a/users.json.example b/users.json.example new file mode 100644 index 0000000..0fb0a4d --- /dev/null +++ b/users.json.example @@ -0,0 +1,4 @@ +{ + "User1": 32853, + "User2": 23467, +} \ No newline at end of file