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

js-tale

v1.6.2

Published

Please note this library is a work in progress, although usable, it is prone to changes. Any thoughts and feedback is always appreciated.

Downloads

8

Readme

Work In Progress

Please note this library is a work in progress, although usable, it is prone to changes. Any thoughts and feedback is always appreciated.

About

js-tale is a node.js library that eases interaction with A Township Tale's APIs.

It makes extensive use of object-oriented design, with the goal of making getting started as easy and intuitive as possible.

Setup

Dependencies

Firstly, setup a project and install required dependencies.

npm init

npm i js-tale

npm i -g typescript ts-node

tsc --init

In package.json, add a script called start: "start": "ts-node ."

In tsconfig.json, set 'target' to es6 and add 'resolveJsonModule' as true.

Config

You will need to configure client id and secret somewhere that won't be checked into git. For instance, create a file called config.json, and add config.json to the .gitignore.

This file should contain:

{
    "clientId": "<insert id here>",
    "clientSecret": "<insert secret here>",
    "scope" : "<insert scopes here>",
}

At this stage, scopes should be: ws.group ws.group_members ws.group_servers ws.group_bans ws.group_invites group.info group.join group.leave group.view group.members group.invite server.view server.console

index.ts

Create a file called index.ts.

This is the main entry point of your bot. Here's an example of a bot which will automatically connect to available servers.

import { Client, ServerConnection } from 'js-tale/dist';
import Logger, { initLogger } from 'js-tale/dist/logger';

import config from './config.json';

initLogger();

const logger = new Logger('Main');

class Main
{
    client:Client = new Client(config);

    async initialize()
    {
        await this.client.initialize();
        
        await this.client.groupManager.groups.refresh(true);

        await this.client.groupManager.acceptAllInvites(true);

        this.client.groupManager.automaticConsole(this.connectionOpened.bind(this));
    }

    private connectionOpened(connection:ServerConnection)
    {
        logger.success(`Connected to ${connection.server.info.name}`);

        connection.on('closed', this.connectionClosed)
    }

    private connectionClosed(connection:ServerConnection)
    {
        logger.warn(`Disconnected from ${connection.server.info.name}`);
    }
}

var main = new Main();
main.initialize();

Connecting to a server

To invite the bot to your server, invite it by it's username or userid (not client id). With the example above, the bot will automatically accept any invites sent to it (acceptAllInvites(true)), both at startup, and while running.

You will also need to modify the permissions for the bot (eg. by selecting in the member list and clicking 'promote to admin') if you wish for it to be able to connect to the server or do other priveleged actions.

The example above also has an automaticConsole call, which is used to simplify running a bot, by creating a connection and calling a callback whenever a server comes online.

When your server is booted up (due to someone joining it, or the immediately upon the bot launching, if it's already online), you should receive that callback.

Modules

Currently att.js has the following modules:

Client (Core/Client.ts)

Wraps Api Connection, Subscription Manager, and Group Manager for convenience.

Api Connection (Core/ApiConnection.ts)

Provides an access point to the API. Handles login, and fetch requests.

Subscription Manager (Core/SubscriptionManager.ts)

Allows for subscriptions to the API, such as when invites to groups are received.

Group Manager (Groups/GroupManager.ts)

Manages a list of current groups and group invites. Also provides a high level functionality to automatically connect to any available servers, with a callback when connections are created.

Note, bots are unable to request to join groups, they may only accept invites.

Group (Groups/Group.ts)

Manages group members, invites, and join requests. Also provides a list of group servers, with high level functionality to automatically connect to the groups servers, with a callback when connections are created.

Server (Groups/Server.ts)

Maintains information about a server and its status. Allows for the creation of websocket connections to the server when running.

Console (Groups/ServerConnection.ts)

Maintains a websocket connection to a running server. Allows for subscriptions to be made, and commands to be sent.