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

@hayato/core

v2.0.2

Published

Bot core

Downloads

1

Readme

core

Hayato's core framework

Usage

import { App } from '@hayato/core

The App is the main class exported by this module. It refers to a base object that works with a Discord.js Client object to implement various commands.

get/set app.name

Type: string Default value: hayato

The name of the app. When the client is replaced, the value is emitted by the app.observables.nameChange observable.

Consequently, a new app.log with the new name will be assigned.

get/set app.client

Type: (discord.js) Client Default value: new Client()

The Discord.js Client instance the app is working with. A default instance is available on initialization and can be reassigned.

The client can be reassigned in order to enable scenarios that require replacing the client such as providing options to the Client constructor.

When the client is replaced, the value is emitted by the app.observables.clientChange observable.

Consequently, the backing instance for app.clientEvents will be replaced to refer to the new client. Also, the main bot logic will be routed from the new client.

get clientEvents

A plain object whose values are observables that emit values when corresponding events are emitted by the client.

The following observables are available:

  • message: Observable<Message>
  • messageReactionAdd: Observable<[MessageReaction, User]>
  • messageDelete: Observable<Message>
  • ready: Observable<void>

See the Discord.js documentation for details.

get router

Type: (xerpath) OpenRadixTrie<IActionCommand, IRouteContext>

The router for the app. The values consist of all the action commands added to the app which can be drilled to with paths using the app's own IRouteContext.

For documentation on the router, see xerpath

log

Type: (pino) Logger

The logger for the app.

get commands

Type: ReadonlyArray<ITopLevelCommand | ICommand>

.......................

get observables

An object whose values consist of observables related to the app.

The following observables are available:

  • invocationError - emits a value when the command invocation directly throws an error
  • reply - emits a value when any command sends a message, either via the send caller or by returning a value.
  • unrouted - emits a value when any message does not get routed through the app (for example when the bot prefix is not matched)
  • requestHelpCommand - emits a value when a command is traversed through and requires a help command
  • commandAdded - emits a value when a command is traversed through
  • error - miscellaneous errors (for example when using app.call). Errors also cause a log.error line to be logged.
  • routerNoMatch - emits a value when a command gets through the router but does not match any top-level command
  • clientChange - emits the new client whenever the client is set
  • nameChange - emits the new name whenever the name is set. A new logger with the new name will also be set.

getPrefix

Type: ((message: Message) => MaybePromise<string>)[] Default value: () => this.name + ' '

A function that is called to determine the prefix needed for the incoming message.

Typically this would change on a per-guild basis.

addCommand(...commands)

Adds a command to the app.

Commands persist even when the client changes.

commands

Type: Command[]

A command has the following properties:

  • title?: string - Optional. The title of the command.
  • description?: string - Optional. The description of the command.
  • key: ExtensiblePath<IRouteContext> | string - Optional. The key of the command. The key is the final part of the path that will be used to access the command.
  • children?: ICommand - Optional. Children commands to this command. The path of children is the path of this command appended by the child's key.
  • hidden?: true - Optional. Set to true to hide the command from help providers.
  • usage?: string

If the command is an action command:

  • invoke(context: ICommandContext): MaybePromise<CommandInvocationResult>: A function to call when the command is invoked by accessing its path along with any parameters.
  • params?: Record<string, ParameterDefinition>: Optional. An object whose keys are parameter definition names and values are parameter definitions. The following are the valid parameter definitions:
    • { type: 'rest' } - a "rest" parameter
    • { type: 'param' } - a single word
    • { type: 'optional' } - an optional single word
    • { type: 'channel' } - a Discord.js channel

addSubscription(...subscriptions)

Adds one or more subscriptions that will be unsubscribed when the app is destroyed.

subscriptions

Type: (rxjs) TeardownLogic[]

addAsyncTeardown(...teardownFns)

Adds one or more async functions that will be called when the app is destroyed.

teardownFns

Type: (() => MaybePromise<void>)[]

destroy

Destroys the app by unsubscribing from subscriptions, calling async teardown functions, and calling client.destroy.

call

Call a function and emit the error on the error observable if an error occurs.

Return type: Promise<void>

fn

Type: () => MaybePromise<void>