3.0.0 • Published 11 months ago

msgroom v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

msgroom

A Msgroom client

Wallaby.js

NOTE: This is not the official msgroom package!

Available on npm: npm i msgroom

There are plans to include a msgroom server in the future.

How to use

Getting started

First, create a new client and connect (the package exports commonJS, so you can use require too)

import Client from "msgroom";

const client = new Client("TestBot", [ "!" ]);
await client.connect();

For more information about any functions/variables/properties, hover over them in your IDE. This package is fully typed.

You can listen for any events you like using client.on (or client.addListener).

A map of events can be found in src/events.ts or in dist/events.d.ts.

Defining commands

To define a command, define a property on client.commands. The name of the property will be the name of your command. This property should be a function that is called with

  1. A reply function, this function will concatenate all arguments passed to it together with spaces in between them and send the resulting string as a message.
  2. Any number of arguments, depending on how much the user passed when invoking the command. These arguments are all strings.

Some examples:

client.commands.ping = () => "pong";

client.commands.repeat = (reply, ...args) => {
    return args.join(" ");
};

You can, after defining these commands, use them by sending a message like this:

example command usage

Blocking users

To block a user, add their ID or session ID to client.blockedIDs or client.blockedSessionIDs respectively. These 2 properties are Sets.

You can then check if a user is blocked using client.isBlocked(). Any events caused by blocked users will be ignored, so you likely won't need this method. This method accepts either

  • An ID, and optionally a session id:
client.isBlocked("user-id-here", "session-id-here")
  • Or an object containing one or more of the following:
client.isBlocked({
    id: "user-id-here",
    sessionID: "session-id-here",
    session_id: "session-id-here"
})

for example:

client.isBlocked("bad-user-id", "some session id") // false
client.blockedIDs.add("bad-user-id")
client.isBlocked("bad-user-id", "some session id") // true

Subcommands

You can now also define subcommands like this:

client.commands.someSubommand = {
    subcommand: () => "You used the subcommand!", // user ran `!someSubcommand subcommand`
    undefined: () => "You didn't use any subcommands!", // user ran `!someSubcommand`
    anotherSubcommand: () => "You used another subcommand!", // user ran `!someSubcommand anotherSubcommand`
}

You can also nest subcommands like this:

client.commands.something = {
    someSubcommand: {
        someSubSubcommand: () => "Look at that, a sub-subcommand" // user ran `!something someSubcommand someSubSubcommand`
    }
}

It comes down to one thing: you can now put an object with subcommands (like shown above) anywhere you can put a command handler function

3.0.1-11

11 months ago

3.0.1-10

1 year ago

3.0.1-12

11 months ago

3.0.1-9

1 year ago

3.0.1-6

1 year ago

3.0.1-5

1 year ago

3.0.1-4

1 year ago

3.0.1-3

1 year ago

3.0.1-2

1 year ago

3.0.1-1

1 year ago

3.0.0

1 year ago

3.0.1-0

1 year ago

2.0.1-13

1 year ago

2.0.1-14

1 year ago

2.0.1-11

1 year ago

2.0.1-12

1 year ago

2.0.1-10

1 year ago

2.0.1-9

1 year ago

2.0.1-8

1 year ago

2.0.1-7

1 year ago

2.0.1-0

1 year ago

2.0.0

1 year ago

2.0.0-79

1 year ago

2.0.0-78

1 year ago

2.0.0-84

1 year ago

2.0.0-83

1 year ago

2.0.0-82

1 year ago

2.0.0-81

1 year ago

2.0.0-80

1 year ago

2.0.0-77

1 year ago

2.0.0-76

1 year ago

2.0.0-75

1 year ago

2.0.0-73

1 year ago

2.0.0-72

1 year ago

2.0.0-69

1 year ago

2.0.0-68

1 year ago

2.0.0-67

1 year ago

2.0.0-66

1 year ago

2.0.0-65

1 year ago

2.0.0-64

1 year ago

2.0.0-63

1 year ago

2.0.0-62

1 year ago

2.0.0-61

1 year ago

2.0.0-59

1 year ago

2.0.0-60

1 year ago

2.0.0-58

1 year ago

2.0.0-57

2 years ago

2.0.0-56

2 years ago

2.0.0-55

2 years ago

2.0.0-54

2 years ago

2.0.0-53

2 years ago

2.0.0-52

2 years ago

2.0.0-51

2 years ago

2.0.0-50

2 years ago

2.0.0-29

2 years ago

2.0.0-28

2 years ago

2.0.0-27

2 years ago

2.0.0-26

2 years ago

2.0.0-25

2 years ago

2.0.0-24

2 years ago

2.0.0-23

2 years ago

2.0.0-22

2 years ago

2.0.0-21

2 years ago

2.0.0-39

2 years ago

2.0.0-38

2 years ago

2.0.0-37

2 years ago

2.0.0-36

2 years ago

2.0.0-35

2 years ago

2.0.0-34

2 years ago

2.0.0-33

2 years ago

2.0.0-32

2 years ago

2.0.0-31

2 years ago

2.0.0-30

2 years ago

2.0.0-49

2 years ago

2.0.0-48

2 years ago

2.0.0-47

2 years ago

2.0.0-46

2 years ago

2.0.0-45

2 years ago

2.0.0-44

2 years ago

2.0.0-43

2 years ago

2.0.0-42

2 years ago

2.0.0-41

2 years ago

2.0.0-40

2 years ago

2.0.0-19

2 years ago

2.0.0-18

2 years ago

2.0.0-17

2 years ago

2.0.0-16

2 years ago

2.0.0-14

2 years ago

2.0.0-13

2 years ago

2.0.0-12

2 years ago

2.0.0-11

2 years ago

2.0.0-10

2 years ago

2.0.0-6

2 years ago

2.0.0-5

2 years ago

2.0.0-4

2 years ago

2.0.0-3

2 years ago

2.0.0-2

2 years ago

2.0.0-20

2 years ago

2.0.0-9

2 years ago

2.0.0-8

2 years ago

2.0.0-7

2 years ago

1.4.1

2 years ago

1.3.2

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

2.0.0-1

2 years ago

2.0.0-0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.0

3 years ago