Parcourir la source

Merge pull request #3 from ozzy2345/master

Adding display name
Moritz il y a 13 ans
Parent
commit
abc17f5679
2 fichiers modifiés avec 16 ajouts et 14 suppressions
  1. 9 8
      plaudereckenbot.py
  2. 7 6
      run.py

+ 9 - 8
plaudereckenbot.py

@@ -8,7 +8,7 @@ except:
 
 
 class pBot:
-    def __init__(self, ip, port, username, password, sid, channellist, cpid):
+    def __init__(self, ip, port, username, password, displayname, sid, channellist, cpid):
         self.ip = ip
         self.port = port
         self.username = username
@@ -16,15 +16,16 @@ class pBot:
         self.sid = sid
         self.channellist = channellist
         self.cpid = cpid
-        self.connect(ip, port, username, password, sid)
+        self.connect(ip, port, username, password, displayname, sid)
 
-    def connect(self, ip, port, username, password, sid):
+    def connect(self, ip, port, username, password, displayname, sid):
         self.teamspeak = PyTS3.ServerQuery(ip, port)
         if self.teamspeak.connect() == False:
             print "Could not connect"
             os._exit(7)
         self.teamspeak.command("login " + username + " " + password)
         self.teamspeak.command("use " + str(sid))
+        self.teamspeak.command("clientupdate client_nickname=" + self.teamspeak.string2escaping(displayname))
 
     def getUserInfo(self):
         self.userInfo = self.teamspeak.command("clientlist")
@@ -43,13 +44,13 @@ class pBot:
     def addChannel(self):
         #print str(self.channellist[len(self.channellist) - 1])
         y = str("channelcreate channel_name=Plauderecke\s"
-         + str(len(self.channellist) + 1) + " channel_order="
-         + str(self.channellist[len(self.channellist) - 1]) + "")
+                + str(len(self.channellist) + 1) + " channel_order="
+                + str(self.channellist[len(self.channellist) - 1]) + "")
         print y
         x = self.teamspeak.command("channelcreate channel_name=Plauderecke\s"
-        + str(len(self.channellist) + 1) + " channel_order="
-        + str(self.channellist[len(self.channellist) - 1]) +
-        " cpid=" + str(self.cpid) + " channel_flag_semi_permanent=1 CHANNEL CODEC")
+                                   + str(len(self.channellist) + 1) + " channel_order="
+                                   + str(self.channellist[len(self.channellist) - 1]) +
+                                   " cpid=" + str(self.cpid) + " channel_flag_semi_permanent=1 CHANNEL CODEC")
         print x
         if isinstance(x['cid'], int):
             self.channellist.append(x['cid'])

+ 7 - 6
run.py

@@ -5,12 +5,13 @@ IP = ""
 PORT = 10011
 USERNAME = "serveradmin"
 PASSWORD = ""
+DISPLAYNAME = "Plauderecken-Bot"
 SID = 1
-ORIGINALCHANNELS = []
-CHANNELLIST = [] # == ORIGINALCHANNELS
+ORIGINALCHANNELS = [151, 152, 153]
+CHANNELLIST = [151, 152, 153] # == ORIGINALCHANNELS
 CPID = 54
-pBot = plaudereckenbot.pBot(IP, PORT, USERNAME, PASSWORD,
-     SID, CHANNELLIST, CPID)
+pBot = plaudereckenbot.pBot(IP, PORT, USERNAME, PASSWORD, DISPLAYNAME,
+    SID, CHANNELLIST, CPID)
 while 1:
     emptyRooms = 0
     pBot.getUserInfo()
@@ -25,7 +26,7 @@ while 1:
             emptyRooms = emptyRooms + 1
     print "ChanUserCount: " + str(channelUserCount)
     print "lenSetUserCount: " + str(len(set(channelUserCount)) == 1
-        and channelUserCount[0] == True)
+    and channelUserCount[0] == True)
     if len(set(channelUserCount)) == 1 and channelUserCount[0] == True:
         pBot.addChannel()
     print "emptyRooms: " + str(emptyRooms)
@@ -35,4 +36,4 @@ while 1:
                 if pBot.channellist[i] not in ORIGINALCHANNELS:
                     pBot.delChannel(pBot.channellist[i])
                     break
-    time.sleep(5)
+    time.sleep(5)