benediktschmitt / py-ts3

A Python 3 API for the TeamSpeak 3 server query and file transfer interface.
http://py-ts3.readthedocs.io
Other
157 stars 31 forks source link

Multiple bot functions in one script #66

Open hcphoon01 opened 6 years ago

hcphoon01 commented 6 years ago

Is it possible to have multiple bot functions within one python script if there are multiple server admin logins?

AdorablePotato commented 6 years ago

Sure it is, but it depends on what you want to do. If you have two bots with different tasks then I'd choose one connection per bot. You can write a script for each one or you simply use threads, but that's up to you.

hcphoon01 commented 6 years ago

What would be the correct code for having two functions running in one bot?

leon1995 commented 6 years ago

@AdmagTwoXray You can just execute 2 times the login and save it in an other variable like: First one with ts3.query.TS3ServerConnection("localhost") as ts3conn: ts3conn.exec_( "login", client_login_name="login", client_login_password="password" )

Second one with ts3.query.TS3ServerConnection("localhost") as ts3conn2: ts3conn.exec_( "login", client_login_name="login2", client_login_password="password2" )

hcphoon01 commented 6 years ago

I'm on v1 so used this code if __name__ == "__main__": with ts3.query.TS3Connection(HOST, PORT) as ts3conn: ts3conn.login(client_login_name=USER, client_login_password=PASS) ts3conn.use(sid=SID) register(ts3conn) with ts3.query.TS3Connection(HOST, PORT) as ts3conn2: ts3conn2.login(client_login_name=USER2, client_login_password=PASS2) ts3conn2.use(sid=SID) bot(ts3conn2) but it did not work

whookie commented 6 years ago

What you could do is:

import threading

def BotAction1(param1, param2, paramX):
    pass #  Your bot action here

def BotAction2(param1, paramX):
    pass # Your bot action here

t1 = threading.Thread(target=BotAction1, args=(p1, p2, p3))
t1.start()

This starts a new nonblocking thread. Im just not really sure on how the telnet connection handles that, since I am using that construct (untested) by passing a TS3 Connection object as parameter, so I can use it inside a thread. Not sure if thats safe or if that would even work.