Skip to main content

tetr.io api wrapper

Project description

Tetry

PyPi version Code size

A simple python library for interacting with the TETR.IO API.

contents

About

This library is a simple wrapper around the TETR.IO API. It uses trio to provide a simple async interface.

Installation

installing from pip

python3 -m pip install tetry

installing from source

git clone https://github.com/apes0/tetry
cd tetry
python3 -m pip install -U .

Documentation

Coming soon!

Examples

Here you will find code examples for the library.

General api

from tetry import api

def printRecords(username):
    records = api.getRecords(username).records
    for name, record in records.items():
        print(f'{name}: {record}')

while (name := input()):
    printRecords(name)

Chat commands

from tetry import bot

bot = bot.Bot(token='token', commandPrefix='>')

@bot.chatCommand()
async def ping(_msg):
    ping = bot.getPing()
    await bot.room.send(f'The bot\'s ping is {round(ping*1000, 2)}ms')

bot.run()

Simple auto-host bot

import trio

from tetry.bot import Bot

bot = Bot(token='token')

@bot.event
async def ready():
    await bot.createRoom(False)

@bot.event
async def joinedRoom(room):
    print(room.invite)

@bot.event
async def userLeave(user):
    name = user['username']
    print(f'{name} has left')
    await bot.room.send(f'Goodbye {name}, hope to see you here again soon!')

async def start(room):
    delay = 20 # seconds
    needed = 2 # players
    if len(room.getPlaying()) >= needed:
        await room.send(f'Starting in {delay} seconds!')
        await trio.sleep(delay)
        if len(room.getPlaying()) >= needed:
            await room.startGame()
        else:
            await room.send('Not enough players!')
    else:
        await room.send('Not enough players!')

@bot.event
async def userJoin(user):
    room = bot.room
    name = user['username']
    await room.send(f'Welcome to this room, {name}!')
    await start(room)

@bot.event
async def gameEnd():
    room = bot.room
    print('the game has ended')
    await start(room)

bot.run()

Contribution

You can feel free to contribute to the this project by making a PR, making suggestions and opening issues for bugs/questions.

Notice

This library is NOT affiliated with, endorsed by, or otherwise associated with TETR.IO or osk.

Helpful links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tetry-1.3.2-py3-none-any.whl (45.6 kB view details)

Uploaded Python 3

File details

Details for the file tetry-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: tetry-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 45.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/57.4.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for tetry-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5cd620b26257f6f326076b67b319a42a91b3d1f0c39a5f8ab3bfcfdb559f25d8
MD5 87b3481fab3b4b959f10d7159d81c262
BLAKE2b-256 b8f0962746b48fe25721595c30557ed6d22af8a131b2c2f7901505afe5dd9e04

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page