2.6.1 • Published 2 months ago

beepbot-message-parser v2.6.1

Weekly downloads
212
License
MIT
Repository
github
Last release
2 months ago

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.

2.6.1

2 months ago

2.6.0

2 months ago

2.5.0

2 months ago

2.4.3

10 months ago

2.4.4

10 months ago

2.4.2

10 months ago

2.4.1

1 year ago

2.4.0

1 year ago

2.2.6

1 year ago

2.3.0

1 year ago

2.3.2

1 year ago

2.3.1

1 year ago

2.2.5

1 year ago

2.2.4

1 year ago

2.2.1

2 years ago

2.2.3

2 years ago

2.2.2

2 years ago

2.2.0

2 years ago

2.1.29

2 years ago

2.1.27

2 years ago

2.1.28

2 years ago

2.1.26

3 years ago

2.1.25

3 years ago

2.1.24

3 years ago

2.1.23

3 years ago

2.1.21

4 years ago

2.1.22

3 years ago

2.1.20

4 years ago

2.1.19

4 years ago

2.1.18

4 years ago

2.1.16

4 years ago

2.1.17

4 years ago

2.1.15

4 years ago

2.1.14

4 years ago

2.1.12

4 years ago

2.1.13

4 years ago

2.1.11

4 years ago

2.1.10

4 years ago

2.1.9

4 years ago

2.1.8

4 years ago

2.1.7

4 years ago

2.1.6

4 years ago

2.1.5

4 years ago

2.0.12

5 years ago

2.0.11

5 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

8 years ago