A simple python library for interacting with the TETR.IO API.
This library is a simple wrapper around the TETR.IO API. It uses trio to provide a simple async interface.
python3 -m pip install tetry
git clone https://github.com/apes0/tetry
cd tetry
python3 -m pip install -U .
Coming soon!
Here you will find code examples for the library.
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)
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()
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()
You can feel free to contribute to the this project by making a PR, making suggestions and opening issues for bugs/questions.
This library is NOT affiliated with, endorsed by, or otherwise associated with TETR.IO or osk.
- TETR.IO bot docs - documentation for the bot api
- tetr.js - a javascript library for interacting with the TETR.IO API
- TETR.IO public api docs - the official TETR.IO API documentation