plaudereckenbot.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/python
  2. import os
  3. try:
  4. import PyTS3
  5. except:
  6. print "PyTS3 not found. Aborting"
  7. os._exit(7)
  8. class pBot:
  9. def __init__(self, ip, port, username, password, sid, channellist, cpid):
  10. self.ip = ip
  11. self.port = port
  12. self.username = username
  13. self.password = password
  14. self.sid = sid
  15. self.channellist = channellist
  16. self.cpid = cpid
  17. self.connect(ip, port, username, password, sid)
  18. def connect(self, ip, port, username, password, sid):
  19. self.teamspeak = PyTS3.ServerQuery(ip, port)
  20. if self.teamspeak.connect() == False:
  21. print "Could not connect"
  22. os._exit(7)
  23. self.teamspeak.command("login " + username + " " + password)
  24. self.teamspeak.command("use " + str(sid))
  25. def getUserInfo(self):
  26. self.userInfo = self.teamspeak.command("clientlist")
  27. self.userInfoArray = list()
  28. for i in range(len(self.userInfo)):
  29. if(self.userInfo[i]['cid'] == 152):
  30. self.userInfoArray.append(self.userInfo[i]['clid'])
  31. def getChannelUsers(self, cid):
  32. x = self.teamspeak.command("channellist")
  33. for i in range(len(x)):
  34. if(x[i]['cid'] in self.channellist):
  35. if(x[i]['cid'] == cid):
  36. return x[i]['total_clients']
  37. def addChannel(self):
  38. #print str(self.channellist[len(self.channellist) - 1])
  39. y = str("channelcreate channel_name=Plauderecke\s"
  40. + str(len(self.channellist) + 1) + " channel_order="
  41. + str(self.channellist[len(self.channellist) - 1]) + "")
  42. print y
  43. x = self.teamspeak.command("channelcreate channel_name=Plauderecke\s"
  44. + str(len(self.channellist) + 1) + " channel_order="
  45. + str(self.channellist[len(self.channellist) - 1]) +
  46. " cpid=" + str(self.cpid) + " channel_flag_semi_permanent=1 CHANNEL CODEC")
  47. print x
  48. if isinstance(x['cid'], int):
  49. self.channellist.append(x['cid'])
  50. print self.channellist
  51. #print x # dbg
  52. def delChannel(self, cid):
  53. print "deleteChannel: " + str(cid) + " "
  54. x = self.teamspeak.command("channeldelete cid=" + str(cid) + " force=1")
  55. self.channellist.remove(cid)
  56. print x
  57. # nothing