Socket
Book a DemoInstallSign in
Socket

beepbot-message-parser

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

beepbot-message-parser

Message parser for BeepBot.

2.6.1
latest
npmnpm
Version published
Weekly downloads
4
-20%
Maintainers
1
Weekly downloads
 
Created
Source

Beepbot Message Parser

A simple message parser for making complex problems so simple.

npm version Build Status

Introduction

Imagine you are creating a chatbot and you want to create a way for your users to create dynamic responses for messages. Like being able to get the current title on the platform or even getting the current time in the streamers timezone. This can be a complex problem to solve but this module is here to help!

This is BMP or "BeepBot Message Parser" it allows you to give an input string which could contain args/methods which get converted to methods and new values replace them. Pretty neat huh?

Usage

import  { Parser } from 'beepbot-message-parser';

const testVars: { [name: string]: number } = {
    cheese: 1,
    test: 2,
};
const parser = new Parser({
    varCallback: async (coreId: string, varName: string, type: VarType) => {
        const val = testVars[varName.toLowerCase()];
        if (testVars[varName.toLowerCase()] === undefined) {
            return 1;
        }
        switch (type) {
            case 'incr':
                return val + 1;
            case 'decr':
                return val - 1;
            default:
                return val;
        }
    },
})

async function run(channelMessage: IMessage, channelSettings: any, input: string) {
    return await parser.parse(channelMessage: IMessage, channelSettings: any, input: string);
}

run(channelMessage, channelSettings, input)
    .then(res => console.log(res))
    .catch(err => console.error(err));

Example Inputs

// Get the current user.
let input = 'I am {user}' // I am TestUser

// Get the current song that a user is scrobbling.
let input = 'Now Playing: {lastfm artdude543}' // Now Playing: Hunter by Galantis

Supported Methods

TODO.

Keywords

beepbot

FAQs

Package last updated on 13 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.