Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time, ts3
- dead = open("dead.txt", "r")
- checklist = set()
- deadlist = set()
- check = True
- def teamspeak_funktion(ts3conn, dead_players, permission_value):
- #ID zum Nickname finden
- try:
- client_id = ts3conn.clientdbfind(pattern=dead_players)
- client_id = [client["cldbid"] for client in client_id]
- except ts3.query.TS3QueryError:
- print("Name didn't match to IDs")
- return
- #Permission für ID ändern
- for ids in client_id:
- try:
- ts3conn.clientaddperm(cldbid=ids, permsid="i_client_talk_power",
- permvalue=permission_value, permskip=True,)
- except ts3.query.TS3QueryError:
- print("Something went wrong")
- def main(ts3conn):
- '''
- Connection Counter sorgt dafür das an den Server ein
- lehrer String alle 5 Minuten gesendet wird
- damit die Verbindung nicht abbricht
- '''
- connection_counter = time.perf_counter()
- while True:
- time.sleep(0.1)
- with open("dead.txt", "r") as dead:
- dead.seek(0)
- first_char = dead.read(1)
- #wenn datei leer, TTT Runde zuende und alle Spieler werden entmuted
- if not first_char:
- for dead_players in deadlist:
- teamspeak_funktion(ts3conn, dead_players, 50)
- check = False
- print(check)
- deadlist.clear()
- checklist.clear()
- else:
- dead.seek(0)
- for line in dead:
- line = line.strip()
- #checklist um den Server nicht unnötig zu belasten
- if line not in checklist:
- teamspeak_funktion(ts3conn, line, 40)
- checklist.add(line)
- else:
- print("Person schon gemuted")
- print(line)
- if len(line) > 0:
- deadlist.add(line)
- else:
- print("Nix")
- print(deadlist)
- check_connection = time.perf_counter()
- if check_connection - connection_counter > 300:
- ts3conn.send_keepalive()
- connection_counter = time.perf_counter()
- else:
- print("Connection didnt need to be restarted")
- if __name__ == "__main__":
- # teamspeak connection aufbauen
- with ts3.query.TS3Connection("127.0.0.1") as ts3conn:
- try:
- ts3conn.login(
- client_login_name="serveradmin",
- client_login_password="lAs33Lsdc5"
- )
- print("connected")
- except ts3.query.TS3QueryError as err:
- print("Login failed:", err.resp.error["msg"])
- exit(1)
- #virtuellen Server 1 auswählen
- ts3conn.use(sid=1)
- main(ts3conn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement