py-ts3 icon indicating copy to clipboard operation
py-ts3 copied to clipboard

Multiple bot functions in one script

Open hcphoon01 opened this issue 7 years ago • 5 comments

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

hcphoon01 avatar Jun 12 '18 19:06 hcphoon01

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.

AdorablePotato avatar Jun 13 '18 00:06 AdorablePotato

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

hcphoon01 avatar Jun 13 '18 02:06 hcphoon01

@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" )

leon1995 avatar Jun 13 '18 10:06 leon1995

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

hcphoon01 avatar Jun 13 '18 12:06 hcphoon01

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.

whookie avatar Jul 04 '18 19:07 whookie