ts3服务器和客户端查询api

ts3quer的Python项目详细描述


https://github.com/benediktschmitt/py-ts3派生,后者仅支持serverquery。然而,Benediktschmitts 版本更可能是最新的,因为它只为一个特定的项目派生,并且只实现一个小的 clientquery方法的子集。

此包为以下对象提供python 3 api

  • TS3查询连接
  • TS3查询事件
  • TS3文件传输

您可以找到完整的api文档 here

安装

此软件包已在PYPI上注册,因此您可以使用:

$ pip3 install ts3

TS3服务器配置

如果要向ts3服务器发送大量查询,请确保 TS3服务器的anti-flood protection未关闭连接。 因此,将运行ts3查询的主机添加到 query_ip_whitelist.txt您的ts3服务器:

$ echo"192.168.178.42" >> path/to/ts3/server/directory/query_ip_whitelist.txt

简介

了解这个库的最简单方法是查看 examples

如果需要有关可能的查询命令的信息,请查看 ts3服务器查询手册

示例

您可以在ts3.examples包中找到更多示例。

  • 显示虚拟服务器上服务器ID为1的所有客户端:

    #!/usr/bin/python3importts3withts3.query.TS3ServerConnection("localhost")asts3conn:# Note, that the client will wait for the response and raise a# **TS3QueryError** if the error id of the response is not 0.try:ts3conn.login(client_login_name="serveradmin",client_login_password="FoOBa9")exceptts3.query.TS3QueryErroraserr:print("Login failed:",err.resp.error["msg"])exit(1)ts3conn.use(sid=1)# Each query method will return a **TS3QueryResponse** instance,# with the response.resp=ts3conn.clientlist()print("Clients on the server:",resp.parsed)print("Error:",resp.error["id"],resp.error["msg"])# Note, the TS3Response class and therefore the TS3QueryResponse# class too, can work as a rudimentary container. So, these two# commands are equal:forclientinresp.parsed:print(client)forclientinresp:print(client)
  • 向所有客户问好:

    #!/usr/bin/python3importts3withts3.query.TS3ServerConnection("localhost")asts3conn:ts3conn.login(client_login_name="serveradmin",client_login_password="FoOBa9")ts3conn.use(sid=1)forclientints3conn.clientlist():msg="Hi {}".format(client["client_nickname"])ts3conn.clientpoke(clid=client["clid"],msg=msg)
  • 向所有客户机打招呼,但将其与clientquery插件一起使用,而不是与serverquery连接一起使用:

    #!/usr/bin/python3importts3withts3.query.TS3Connection("localhost",25639)asts3conn:ts3conn.auth(apikey="AAAA-BBBB-CCCC-DDDD-EEEEh")forclientints3conn.clientlist():msg="Hi {}".format(client["client_nickname"])ts3conn.clientpoke(clid=client["clid"],msg=msg)
  • 事件处理(server query):

    #!/usr/bin/python3importtimeimportts3withts3.query.TS3ServerConnection("localhost")asts3conn:ts3conn.login(client_login_name="serveradmin",client_login_password="FoOBa9")ts3conn.use(sid=1)# Register for eventsts3conn.servernotifyregister(event="server")whileTrue:event=ts3conn.wait_for_event()# Greet new clients.ifevent[0]["reasonid"]=="0":print("client connected")ts3conn.clientpoke(clid=event[0]["clid"],msg="Hello :)")
  • 一个简单的TS3查看器:

    #!/usr/bin/python3importts3# The examples package already contains this implementation.# Note, that the ts3.examples.viewer module has an helpful class to# build a complete channel tree of a virtual server: ChannelTreeNodefromts3.examples.viewerimportviewwithts3.query.TS3ServerConnection("localhost")asts3conn:ts3conn.login(client_login_name="serveradmin",client_login_password="FoOBa9")view(ts3conn,sid=1)
  • 下载和上载文件:

    #!/usr/bin/python3importts3withts3.query.TS3ServerConnection("localhost")asts3conn:ts3conn.login(client_login_name="serveradmin",client_login_password="FoOBa9")# Create a new TS3FileTransfer instance associated with the# TS3ServerConnection.ts3ft=ts3.filetransfer.TS3FileTransfer(ts3conn)# Upload the image *baz.png* to the channel with the id 2 on the# TS3 server.# Note the opening mode ("rb").withopen("baz.png","rb")asfile:ts3ft.init_upload(input_file=file,name="/baz.png",cid=2)# Download the file into *baz1.png*.withopen("baz1.png","wb")asfile:ts3ft.init_download(output_file=file,name="/baz.png",cid=2)
  • 事件处理(client query):

    #!/usr/bin/python3importtimeimportts3withts3.query.TS3ClientConnection("localhost")asts3conn:ts3conn.auth(apikey="AAAA-....-EEEE")ts3conn.use()# Register for eventsts3conn.clientnotifyregister(event="any")whileTrue:event=ts3conn.wait_for_event()print(event.parsed)

错误

如果发现错误,请报告或发送请求。

请同时报告语法或拼写错误。

版本控制

有关版本号,请查看http://semver.org/

许可证

这个软件包是根据麻省理工学院的许可证授权的。

从ts3服务器查询手册复制的docstring是 TeamSpeak Systems GmbH

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java什么是RuleContext类实现中的invokingState?   如何将Scala Seq传递给Java varargs   ELK在ubuntu上升级到最新版本后仍提示升级java版本   java如何实现服务器关闭   类型为java的0上的安卓。无法将lang.String转换为JSONArray   java如何在通过Selenium登录时避免验证代码?   java同时下载文件并上传到别处(转发文件)   java jodatime 1.6.2 jar未从maven central repository下载   java OpenGL ES 2.0屏幕滚动:translate vs.setLookatM   安卓 Java如何在另一个类中使用活动方法   java CSVFormat。RFC4180忽略中引用的值。csv文件   从电话号码中分离数字的java   java找不到net。来源:福格。jtds。jdbc。Tomcat web应用程序中的驱动程序   java Red5无法解析bean引用   java忽略日志配置