3.0.0 • Published 17 days ago

msgroom v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
17 days 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-6

17 days ago

3.0.1-5

17 days ago

3.0.1-4

1 month ago

3.0.1-3

2 months ago

3.0.1-2

2 months ago

3.0.1-1

2 months ago

3.0.0

2 months ago

3.0.1-0

2 months ago

2.0.1-13

2 months ago

2.0.1-14

2 months ago

2.0.1-11

2 months ago

2.0.1-12

2 months ago

2.0.1-10

2 months ago

2.0.1-9

3 months ago

2.0.1-8

3 months ago

2.0.1-7

3 months ago

2.0.1-0

3 months ago

2.0.0

3 months ago

2.0.0-79

3 months ago

2.0.0-78

3 months ago

2.0.0-84

3 months ago

2.0.0-83

3 months ago

2.0.0-82

3 months ago

2.0.0-81

3 months ago

2.0.0-80

3 months ago

2.0.0-77

3 months ago

2.0.0-76

4 months ago

2.0.0-75

4 months ago

2.0.0-73

4 months ago

2.0.0-72

4 months ago

2.0.0-69

4 months ago

2.0.0-68

4 months ago

2.0.0-67

4 months ago

2.0.0-66

4 months ago

2.0.0-65

4 months ago

2.0.0-64

4 months ago

2.0.0-63

4 months ago

2.0.0-62

4 months ago

2.0.0-61

4 months ago

2.0.0-59

4 months ago

2.0.0-60

4 months ago

2.0.0-58

5 months ago

2.0.0-57

5 months ago

2.0.0-56

5 months ago

2.0.0-55

5 months ago

2.0.0-54

5 months ago

2.0.0-53

6 months ago

2.0.0-52

6 months ago

2.0.0-51

6 months ago

2.0.0-50

7 months ago

2.0.0-29

8 months ago

2.0.0-28

8 months ago

2.0.0-27

8 months ago

2.0.0-26

8 months ago

2.0.0-25

8 months ago

2.0.0-24

8 months ago

2.0.0-23

8 months ago

2.0.0-22

8 months ago

2.0.0-21

8 months ago

2.0.0-39

7 months ago

2.0.0-38

7 months ago

2.0.0-37

7 months ago

2.0.0-36

7 months ago

2.0.0-35

7 months ago

2.0.0-34

7 months ago

2.0.0-33

7 months ago

2.0.0-32

7 months ago

2.0.0-31

8 months ago

2.0.0-30

8 months ago

2.0.0-49

7 months ago

2.0.0-48

7 months ago

2.0.0-47

7 months ago

2.0.0-46

7 months ago

2.0.0-45

7 months ago

2.0.0-44

7 months ago

2.0.0-43

7 months ago

2.0.0-42

7 months ago

2.0.0-41

7 months ago

2.0.0-40

7 months ago

2.0.0-19

8 months ago

2.0.0-18

8 months ago

2.0.0-17

8 months ago

2.0.0-16

8 months ago

2.0.0-14

8 months ago

2.0.0-13

8 months ago

2.0.0-12

8 months ago

2.0.0-11

8 months ago

2.0.0-10

8 months ago

2.0.0-6

8 months ago

2.0.0-5

8 months ago

2.0.0-4

8 months ago

2.0.0-3

8 months ago

2.0.0-2

8 months ago

2.0.0-20

8 months ago

2.0.0-9

8 months ago

2.0.0-8

8 months ago

2.0.0-7

8 months ago

1.4.1

11 months ago

1.3.2

11 months ago

1.4.0

11 months ago

1.3.1

11 months ago

1.3.0

11 months ago

2.0.0-1

10 months ago

2.0.0-0

10 months ago

1.2.0

12 months ago

1.1.0

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago

0.1.0

2 years ago