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 ProcessBuilder在使用多个参数时运行不正常   java如何使用Spring数据ORM/JPA创建EntityManagerFactory?   将Velocity宏转换为Java指令   internet上的Java TCP/IP服务器客户端通信   java为什么JDK 8允许一个局部内部类(在方法内部)访问封闭方法的非最终局部变量?   基于Java的比率算法   java应用程序在选择列表首选项时出错   java保存对象以供以后使用   java如何使用MySQL JDBC驱动程序连接Android和MySQL   java Zipkin可以用于控制台应用程序   java单击刷新Servlet页面显示重复内容   java如何递归地反转字符串数组?   java如何使用inputStream作为outputStream的文本?   java扩展令牌选择操作符   java在映射中使用通用枚举类   arraylist如何使用JAVA流从对象列表中查找平均值   windows将FileInputStream和FileOutputStream传递给ffmpeg进行转码(使用JAVEJava音频视频编码)   java Ant脚本在执行CVS签出后找不到目标   重复值情况下的java插入排序,双链表ADT   java如何在Accumulo中获取数据库查询计数