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

easy-goat

v1.1.0

Published

A utility for simplifying GoatbotV2 messenger chatbot handling.

Downloads

17

Readme

EasyGoat Documentation

Overview

EasyGoat is a utility designed to simplify the development of the GoatbotV2 messenger chatbot. It facilitates message handling, command execution, and dynamic content management, allowing for easy integration into your chatbot environment.

Author

  • Liane Cagara

Function: EasyGoat

Description

The EasyGoat function simplifies the creation of a message handler for the GoatbotV2 chatbot. It allows you to configure message templates with dynamic placeholders, handle command execution based on context, and manage command arguments effortlessly.

Syntax

async function EasyGoat(ctx = {});

Parameters

ctx (Object | String | Function): Configuration for the message handler. The type of ctx determines how it is processed.

  • String: If ctx is a string, it is used as the default message text.

  • Function: If ctx is a function, it is used as the command to execute.

  • Object: If ctx is an object, it can include the following properties:

    • name (String | Array):

      • Type: String or Array<String>
      • Default: "noname"
      • Description: The name of the command or handler. An array uses the first element as the name and the remaining elements as aliases.
    • category (String):

      • Type: String
      • Default: "Uncategorized"
      • Description: The category of the command.
    • cooldown (Number):

      • Type: Number
      • Default: 5
      • Description: Cooldown period in seconds to limit how often the command can be executed.
    • author (String):

      • Type: String
      • Default: "Not Specified"
      • Description: The author of the command.
    • description (String):

      • Type: String
      • Default: "No description provided"
      • Description: A brief description of the command's purpose.
    • args (Object):

      • Type: Object
      • Default: {}
      • Description: Defines how command arguments are handled. It maps argument names to their corresponding handlers. Handlers can be:
        • String: A static message or template with placeholders.
        • Function: A function that takes the context and returns a string or a promise that resolves to a string.
    • config (Object):

      • Type: Object
      • Default: {}
      • Description: Additional configuration options that override default settings.
    • text (String):

      • Type: String
      • Default: "Please configure the .text property in EasyGoat as String."
      • Description: Default message to send if no arguments are used.
    • command (Function | null):

      • Type: Function or null
      • Default: null
      • Description: A function to execute if no arguments match and no other handler is present. Should return a string or a promise resolving to a string.

Returns

An object with the following properties:

  • config (Object): The finalized configuration including name, role, category, shortDescription, longDescription, author, aliases, and countDown.
  • onStart (Function): A function that handles the message logic based on the context.

Example

const { EasyGoat } = require("easy-goat");

module.exports = EasyGoat({
  name: 'greet',
  category: 'Fun',
  cooldown: 10,
  author: 'Liane Cagara',
  description: 'Sends a greeting message.',
  args: {
    name: 'Hello, {name}!',
    uid({ print, event }) {
      print('Your ID is {uid}.');
    }
  },
  //text: 'Default greeting message.',
  async command({ print }) {
    print('Custom command result.');
  }
});
const { EasyGoat } = require("easy-goat");

module.exports = EasyGoat({
  name: "greet",
  author: "Liane",
  description: "Greet kita uwu",
  text: "Hello {mention}, kamusta kana? Have a good day."
});

args Property

The args property allows for dynamic handling of command arguments. It is an object where:

  • Keys represent argument names.
  • Values define how the argument is processed.

Each value in args can be:

  • String: A static message template that may contain placeholders like {name} or {uid}. These placeholders are replaced with actual values when generating the message.

  • Function: A function that receives the context object and returns a string or a promise that resolves to a string. This function can be used for more complex argument processing.

Example

args: {
  'user': 'Hello, {name}!',
  'id': async (ctx) => `Your ID is ${ctx.event.senderID}.`
}

In this example:

  • If the argument user is used, the handler replaces {name} with the user's name.
  • If the argument id is used, the handler dynamically returns the user's ID.

Error Handling

  • Throws a TypeError if ctx is not a valid type (i.e., neither an object, string, nor function).

License

This project is licensed under the MIT License. See the LICENSE file for details.