Advertisement
Jupiter_Crafter

Teamspeak Automute

Jan 23rd, 2017
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1. import time, ts3
  2.  
  3.  
  4.  
  5.  
  6. dead = open("dead.txt", "r")
  7. checklist = set()
  8. deadlist = set()
  9. check = True
  10.  
  11. def teamspeak_funktion(ts3conn, dead_players, permission_value):
  12.     #ID zum Nickname finden
  13.     try:   
  14.         client_id = ts3conn.clientdbfind(pattern=dead_players)
  15.         client_id = [client["cldbid"] for client in client_id]
  16.     except ts3.query.TS3QueryError:
  17.         print("Name didn't match to IDs")
  18.         return
  19.     #Permission für ID ändern
  20.     for ids in client_id:
  21.         try:
  22.             ts3conn.clientaddperm(cldbid=ids, permsid="i_client_talk_power",
  23.                 permvalue=permission_value, permskip=True,)
  24.         except ts3.query.TS3QueryError:
  25.             print("Something went wrong")
  26.  
  27.  
  28.  
  29.  
  30. def main(ts3conn):
  31.     '''
  32.     Connection Counter sorgt dafür das an den Server ein
  33.     lehrer String alle 5 Minuten gesendet wird
  34.     damit die Verbindung nicht abbricht
  35.     '''
  36.     connection_counter = time.perf_counter()
  37.     while True:
  38.         time.sleep(0.1)
  39.         with open("dead.txt", "r") as dead:
  40.             dead.seek(0)
  41.             first_char = dead.read(1)
  42.             #wenn datei leer, TTT Runde zuende und alle Spieler werden entmuted
  43.             if not first_char:
  44.                 for dead_players in deadlist:
  45.                     teamspeak_funktion(ts3conn, dead_players, 50)
  46.                 check = False
  47.                 print(check)
  48.                 deadlist.clear()
  49.                 checklist.clear()
  50.             else:
  51.                 dead.seek(0)       
  52.             for line in dead:          
  53.                 line = line.strip()
  54.                 #checklist um den Server nicht unnötig zu belasten
  55.                 if line not in checklist:
  56.                     teamspeak_funktion(ts3conn, line, 40)
  57.                     checklist.add(line)
  58.                 else:
  59.                     print("Person schon gemuted")
  60.                    
  61.                 print(line)
  62.                 if len(line) > 0:
  63.                     deadlist.add(line)
  64.                 else:
  65.                     print("Nix")
  66.                 print(deadlist)
  67.         check_connection = time.perf_counter()
  68.         if check_connection - connection_counter > 300:
  69.             ts3conn.send_keepalive()
  70.             connection_counter = time.perf_counter()
  71.  
  72.         else:
  73.             print("Connection didnt need to be restarted")
  74.    
  75.  
  76.  
  77.  
  78. if __name__ == "__main__":
  79.     # teamspeak connection aufbauen
  80.     with ts3.query.TS3Connection("127.0.0.1") as ts3conn:
  81.         try:
  82.             ts3conn.login(
  83.                 client_login_name="serveradmin",
  84.                 client_login_password="lAs33Lsdc5"
  85.                 )
  86.             print("connected")
  87.         except ts3.query.TS3QueryError as err:
  88.             print("Login failed:", err.resp.error["msg"])
  89.             exit(1)
  90.         #virtuellen Server 1 auswählen
  91.         ts3conn.use(sid=1)
  92.         main(ts3conn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement