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

psim.us

v1.2.1

Published

**A simple, easily customizable bot for connecting to Pokemon Showdown.**

Downloads

9

Readme

A simple, easily customizable bot for connecting to Pokemon Showdown.

This package is meant to be as simple as possible. All you need to do to connect to PS is as follows: (TS)

import {PS} from 'psim.us';

const bot = new PS.Client({
    name: 'uwu', pass: 'uwu',
});

Then you just call

// note these are defaults, so you can just call bot.connect()
// if you want to connect to main
bot.connect('sim.smogon.com', 8000);

For receiving messages, all you need to do is set a listener.

bot.on('message', msg => {
    console.log(`${msg.from}: ${msg.test}`);
    msg.respond('Hello!');
});

To access rooms, all you need to do is call client.rooms.get(). client.users has the same accessor API.

Settings:

export interface Settings {
    name: string;
    pass: string;
    rooms?: string[];
    /* Command prefix */
    prefix?: string;
    status?: string;
    avatar?: string;
    /* Number of MS to wait before attempting to reconnect.
    * Defaults to one minute. */
    reconnectMs?: number;
}

User methods:

export declare class User extends PSSendable {
    data: Record<string, any>;
    group: string;
    rooms: Record<string, {
        group: string;
        isPrivate?: boolean;
    }>;
    name: string;
    avatar: string;
    setData(data: any): void;
    send(message: string): void;
    update(): Promise<boolean>;
    toString(): string;
}

Room methods:

export declare class Room extends PSSendable {
    data: Record<string, any>;
    id: string;
    title: string;
    users: Record<string, User>;
    auth: Record<string, string[]>;
    setData(data: any): void;
    update(): Promise<boolean>;
    send(message: string): void;
    toString(): string;
}

Client methods:

export declare class Client extends EventEmitter {
    connection: ws.connection;
    settings: Settings;
    rooms: RoomList;
    users: UserList;
    constructor(settings: Settings);
    static parse(received: string): PLine[];
    connect(server?: string, port?: number): void;
    query(type: string, args: string[]): Promise<any>;
    send(message: string): void;
}

Message methods:

export declare class Message {
    client: Client;
    text: string;
    group: string;
    /** User if it's a pm, Room if it's in a room, null if it's a system message
     * (from &)
     */
    to: User | Room | null;
    room?: Room | null;
    from: User | null;
    isPSCommand: boolean;
    line: PLine;
    constructor(client: Client);
    static getUser(name: string, client: Client): Promise<false | User | null>;
    static from(line: PLine, client: Client): Promise<Message | null | undefined>;
    /** If the message has a room, sends the response to that room
     * - else PMs the user that it's from
     **/
    respond(text: string): void | undefined;
    /** Sends a reply in pms. */
    privateRespond(text: string): void | undefined;
    isPM(): boolean;
    isCommand(): boolean;
    /**
     * Checks if a user is at least a certain rank.
     * Supports custom callbacks, both as a second param for individual checks,
     * and the checkPermission handler in the config that runs on all checks.
     * This checks the callbacks first:
     * - config handler
     * - if config handler is not met, checks callback handler
     * - if neither of those are met, checks rank superiority
     */
    perms(rank: string, cb?: (message: Message) => boolean): boolean;
    /**
     * This checks only directly "is this user at least this rank"
     * You should prefer using `message.perms(rank)` because that supports
     * custom handlers.
     */
    isRank(rank: string): boolean;
    clone(): Message;
}

Page API:

// request for a page. sent when a user does /join view-bot-[name]-[pageid]
// to listen for this, use client.on('requestpage', listener);
export declare class PageRequest {
    client: Client;
    from: User;
    pageid: string;
    room: Room;
    constructor(client: Client);
    static from(client: Client, args: string[], roomId: string): Promise<PageRequest | undefined>;
    respond(page: PageBuilder | string): Page;
}
// made to make it easy to create page html
export declare class PageBuilder {
    private elem;
    constructor();
    toString(): string;
    html(text: string): this;
    querySelector(selector: string): cheerio.Cheerio<cheerio.Node>;
}
// page wrapper class
export declare class Page {
    user: User;
    room: Room;
    content: string;
    pageid: string;
    closed: boolean;
    constructor(req: {
        from: User;
        room: Room;
        pageid: string;
        content: string;
    });
    toString(): string;
    highlight(title: string, text: string): void;
    changeSelector(selector: string, html: string): void;
    close(): void;
    update(): void;
}

To listen for a specific message type, just call client.on(type, listener).

The listener will be passed the arguments args (string[]), room (string?), line (PLine).