An extendable client for interacting with Pokemon Showdown
Project description
Intro
A client for Pokemon Showdown! for Python 3.4 and 3.5. This was written to make it easier to write bots, interact with users, moderate chat rooms, and collect data.
Setup
Install the package with pip3 install --user showdownpy
. This will also install the package's websockets
and aiohttp
dependencies if you do not already have them.
Example
Examples have been provided in the ./examples directory
. Make sure to create your own versions of the login.txt
and owner.txt
files in ./examples/data/
directory. Templates for those files have been provided.
The client on its own doesn't do very much, and is instead intended to be extended and modified. This can be done through various "hook" coroutines left in the base class. The following program uses the on_private_message
hook to echo back the content of any PMs it receives.
"""
An example client that echoes back any message that is
private messaged to it
"""
import showdown
with open('./examples/data/login.txt', 'rt') as f:
username, password = f.read().strip().splitlines()
class EchoClient(showdown.Client):
async def on_private_message(self, pm):
if pm.recipient == self:
await pm.reply(pm.content)
EchoClient(name=username, password=password).start()
Other hooks include on_connect
, on_login
, on_room_init
, on_room_deinit
, on_query_response
and on_chat_message
.
These hooks are by no means all inclusive (Showdown has somewhere upwards of 40 different types of messages it uses to interact with clients in its protocol), and so a catch-all hook on_receive
is also present. Each hook call is given its own task on the event loop, so you can have multiple active coroutines spawned from the same hook.
The bot can also be used for collecting data on battles. The following bot anonymously joins ongoing matches in the format 'OU' and saves replays of them when a user finishes.
"""
An example client that joins all OU battles
and saves replays.
"""
import showdown
with open('./examples/data/login.txt', 'rt') as f:
username, password = f.read().strip().splitlines()
class ReplayClient(showdown.Client):
async def on_query_response(self, response_type, data):
if response_type == 'roomlist':
for battle_id in set(data['rooms']) - set(self.rooms):
await self.join(battle_id)
async def on_receive(self, room_id, inp_type, params):
if inp_type == 'win':
with open('./data/' + room_id, 'wt') as f:
f.write('\n'.join(self.rooms[room_id].logs))
@showdown.Client.on_interval(interval=3)
async def check_ou(self):
await self.query_battles(tier='gen7ou', lifespan=3)
ReplayClient(name=username, password=password).start(autologin=False)
It is recommended that you save local copies of these matches rather than upload them, as to not overwhelm Showdown's replay server.
Contributions
This package is still a work in progress, and any contributions would be great! I'm currently prioritizing documentation over new features, but if you have an idea for something let me know. Feel free to share anything you make with the client and if its succint enough I may add it to the pool of examples.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file showdownpy-0.1.5.tar.gz
.
File metadata
- Download URL: showdownpy-0.1.5.tar.gz
- Upload date:
- Size: 24.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68de90dc98b4730ea24d4d0582a49caabc1d042afba73259fb1bd77a5ebff6ed |
|
MD5 | 9801c6daa551f48acbefafd137a04c16 |
|
BLAKE2b-256 | cf2c3c94b3fc5c67463c269b1499b2b655299e910a7143dbf17a53799ae16455 |
File details
Details for the file showdownpy-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: showdownpy-0.1.5-py3-none-any.whl
- Upload date:
- Size: 27.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21f73779a1b73f43bb9ad5120331ba3272e8a722b715269e8079a6c007f6c268 |
|
MD5 | 6f5d3d23486fcc88ddcb9aaac3cccca0 |
|
BLAKE2b-256 | 0f51d40ab0cd3f724f85139ade1d8c5c43921d981f63bd7b20905e6434ad8b2e |