plaudereckenbot.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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, displayname, 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, displayname, sid)
  18. def connect(self, ip, port, username, password, displayname, 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. self.teamspeak.command("clientupdate client_nickname=" + self.teamspeak.string2escaping(displayname))
  26. def getUserInfo(self):
  27. self.userInfo = self.teamspeak.command("clientlist")
  28. self.userInfoArray = list()
  29. for i in range(len(self.userInfo)):
  30. if(self.userInfo[i]['cid'] == 152):
  31. self.userInfoArray.append(self.userInfo[i]['clid'])
  32. def getChannelUsers(self, cid):
  33. x = self.teamspeak.command("channellist")
  34. for i in range(len(x)):
  35. if(x[i]['cid'] in self.channellist):
  36. if(x[i]['cid'] == cid):
  37. return x[i]['total_clients']
  38. def addChannel(self):
  39. #print str(self.channellist[len(self.channellist) - 1])
  40. y = str("channelcreate channel_name=Plauderecke\s"
  41. + str(len(self.channellist) + 1) + " channel_order="
  42. + str(self.channellist[len(self.channellist) - 1]) + "")
  43. print y
  44. x = self.teamspeak.command("channelcreate channel_name=Plauderecke\s"
  45. + str(len(self.channellist) + 1) + " channel_order="
  46. + str(self.channellist[len(self.channellist) - 1]) +
  47. " cpid=" + str(self.cpid) + " channel_flag_semi_permanent=1 CHANNEL CODEC")
  48. print x
  49. if isinstance(x['cid'], int):
  50. self.channellist.append(x['cid'])
  51. print self.channellist
  52. #print x # dbg
  53. def delChannel(self, cid):
  54. print "deleteChannel: " + str(cid) + " "
  55. x = self.teamspeak.command("channeldelete cid=" + str(cid) + " force=1")
  56. self.channellist.remove(cid)
  57. print x
  58. # nothing