npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-psim-client

v1.1.6

Published

A TypeScript Pokemon Showdown client library

Downloads

5

Readme

TsPsimClient

This is a TypeScript library that handles connection logic to Pokemon Showdown servers and wraps around some of the low-level parts of interacting with Psim from a bot.

Features

  • Promise-based messages
  • Automatically synchronized room and user data (including alt-tracking)
  • yeah, that's about it for now, but hey it's not JavaScript

Installation

TsPsimClient is available on npm, simply open up your terminal, point to your working directory and enter:

npm install ts-psim-client --save

If it's already in your package.json, just run npm install. If you have it installed and want to update, run npm update ts-psim-client.

Version History

Version 1.1.5

  • Added Client#onPrivateMessage
  • Various fixes

Version 1.1.2

  • Added Client#getUser
  • Added Client#getRoom
  • Added a rules parameter to Room#createTournament

Version 1.1.1

  • Fixed an issue with the message queue still processing while not connected to Pokemon Showdown
  • Fixed an issue with Room#createTournament not allowing it to set double/triple/etc-elimination tournaments.
  • Added Utils.delay(number), example use: await Utils.delay(1000) to halt async method for 1 second

Version 1.1.0

  • Fixed timeout/autoReconnect being used in the wrong places
  • Changed auth handling to be per-message rather than per-user
    • Added Message#rank()
  • Rooms now tracks users who have auth, even after they change display names
    • Added Room#isVoice(User), Room#isDriver(User), Room#isModerator(User), Room#isRoomOwner(User) and Room#isAdministrator(User) which can check the user across renames. Utils.isVoice(string), etc. can still be used to check individual message auth
  • Changed UserCollection to index users by a sanitized username without auth symbol, keeping user state across rooms
  • Added type signatures for the remainder of the functions (() : void, etc)
  • Cleanup removing unused imports

Version 1.0.0

  • Initial Library

Example Setup

import * as config from './Config'
import { Client, Room, User, RoomMessage, Utils } from 'ts-psim-client'

const bot = new Client({})

bot.onReady.subscribe((client : Client) => {
	client.login(config.PsUsername, config.PsPassword, true)
})

bot.onLogin.subscribe((client : Client) => {
	client.join('botdevelopment')
	client.setAvatar('supernerd')
})

bot.onRoomJoin.subscribe((client : Client, room : Room) => {
	room.onUserJoin.subscribe((room : Room, user : User) => {
		if (Utils.isVoice(user)) {
			room.send(`Hello ${user.username}!`)
		}
	})

	room.onUserLeave.subscribe((room : Room, user : User) => {
		if (Utils.isVoice(user)) {
			room.send(`Goodbye ${user.username}!`)
		}
	})

	room.onMessage.subscribe((room : Room, message : RoomMessage) => {
		if (!message.isIntro && message.text.trim() === '(tada)') {
			message.reply('🎉🎉🎉')
		}
	})
})

bot.connect()

Configuration

There are some configuration options that can be specified in the Client constructor:

{
	server : string // The server you'll connect to. Defaults to 'sim.smogon.com'
	port : number // The port you'll connect to. Defaults to 8000
	timeout : number // The time (in milliseconds) you'll attempt to reconnect in if the connection is lost. Defaults to 30 seconds
	loginServer : string // The login server. defaults to 'https://play.pokemonshowdown.com/~~showdown/action.php'
	autoReconnect : number // The time (in milliseconds) you'll attempt to login again if your login is rejected for a non-credential related reason. defaults to 30 seconds
	debug : boolean // Logs messages from the library to the console. defaults to false
}

Events

(todo)

Credits

  • PartMan7 for the PS-Client library, of which some of this library's structure and design is inspired from (and in a few cases, a bit of connection logic directly ripped out)

What's Next?

Not sure. Features will be developed on an as-needed basis for CheirBot Redux. If you have any bugs or ideas, feel free to stick it in Issues or submit something of your own.