py-ts3, TeamSpeak 3服务器查询和文件传输接口的python 3 API

分享于 

6分钟阅读

GitHub

  繁體 雙語
A Python 3 API for the TeamSpeak 3 server query and file transfer interface.
  • 源代码名称:py-ts3
  • 源代码网址:http://www.github.com/benediktschmitt/py-ts3
  • py-ts3源代码文档
  • py-ts3源代码下载
  • Git URL:
    git://www.github.com/benediktschmitt/py-ts3.git
    Git Clone代码到本地:
    git clone http://www.github.com/benediktschmitt/py-ts3
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/benediktschmitt/py-ts3
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    
    PyTS3

    这里软件包提供了一个收费的python 3 API,用于:

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

    你可以在这里找到完整的API文档

    安装

    这里软件包已经在PyPi上注册,因此你可以执行以下操作:

    $ pip3 install ts3

    TS3服务器配置

    如果要向TS3服务器发送大量查询,请确定你连接,并没有被TS3服务器的防防汛 closed。 因此,将运行TS3查询的主机添加到TS3服务器的query_ip_whitelist.txt 中可能是明智的:

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

    简介

    掌握这个库的最简单方法是查看示例。

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

    示例

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

    • 在虚拟服务器上显示服务器 id 1的所有客户机:

      #!/usr/bin/python3import ts3with ts3.query.TS3Connection("localhost") as ts3conn:
       # 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" )
       except ts3.query.TS3QueryError as err:
       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:for client in resp.parsed:
       print(client)
       for client in resp:
       print(client)
    • 向所有客户问好:

      #!/usr/bin/python3import ts3with ts3.query.TS3Connection("localhost") as ts3conn:
       ts3conn.login(
       client_login_name="serveradmin",
       client_login_password="FoOBa9" )
       ts3conn.use(sid=1)
       for client in ts3conn.clientlist():
       msg ="Hi {}".format(client["client_nickname"])
       ts3conn.clientpoke(clid=client["clid"], msg=msg)
    • 事件处理:

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

      #!/usr/bin/python3import ts3# 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: ChannelTreeNodefrom ts3.examples.viewer import viewwith ts3.query.TS3Connection("localhost") as ts3conn:
       ts3conn.login(
       client_login_name="serveradmin",
       client_login_password="FoOBa9" )
       view(ts3conn, sid=1)
    • 下载并上传文件:

      #!/usr/bin/python3import ts3with ts3.query.TS3Connection("localhost") as ts3conn:
       ts3conn.login(
       client_login_name="serveradmin",
       client_login_password="FoOBa9" )
       # Create a new TS3FileTransfer instance associated with the# TS3Connection. 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)

    Bug

    如果你发现 Bug,请报告或者发送请求请求。

    请报告语法或者拼写错误。

    版本控制

    对于版本号,请看一下 http://semver.org/

    许可证

    这个软件包是在MIT许可下许可的。

    从TS3服务器查询手册复制的文档文件是 TeamSpeak系统GmbH的属性。


    INT  文件  Server  API  接口  team  
    相关文章