Initial commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/__pycache__/
|
||||||
|
/connection.py
|
||||||
|
/users.json
|
||||||
4
README.md
Normal file
4
README.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# ts3-rank-bot
|
||||||
|
|
||||||
|
A bot that automatically sets a teamspeak group according
|
||||||
|
to the persons rainbow 6 siege rank
|
||||||
5
connection.py.example
Normal file
5
connection.py.example
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
HOST = "0.0.0.0"
|
||||||
|
PORT = 10011
|
||||||
|
SID = 315
|
||||||
|
USER = "rank_bot"
|
||||||
|
PASS = "password"
|
||||||
70
main.py
Executable file
70
main.py
Executable file
@@ -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()
|
||||||
|
|
||||||
4
users.json.example
Normal file
4
users.json.example
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"User1": 32853,
|
||||||
|
"User2": 23467,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user