@enitoni/gears-ws

1.0.0 • Public • Published

gears-ws

This package adds ws bindings to Gears.

Client usage

import { Adapter, Bot, CommandBuilder } from "@enitoni/gears-ws/client"
import { matchPrefixes } from "@enitoni/gears"

const adapter = new Adapter({
  path: "ws://localhost:1337"
})

const command = new CommandBuilder()
  .match(matchPrefixes("!test"))
  .use(context => {
    const { message } = context

    return message.reply("Got your message!")
  })
  .done()

const bot = new Bot({
  adapter,
  commands: [command]
})

bot.start().then(() => {
  // bot is running, log something here if you want
})

Server usage

Server usage is the same, except for a few differences:

import { Adapter, Bot, CommandBuilder } from "@enitoni/gears-ws/server"
import { matchPrefixes } from "@enitoni/gears"

const adapter = new Adapter({
  port: 1337
})

const command = new CommandBuilder()
  .match(matchPrefixes("!test"))
  .use(context => {
    const { message } = context

    return message.reply("Got your message!")
  })
  .done()

const bot = new Bot({
  adapter,
  commands: [command]
})

bot.start().then(() => {
  // bot is running, log something here if you want
})

If you wish to get the socket from the message, you can access it via message.socket

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i @enitoni/gears-ws

    Weekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    12.9 kB

    Total Files

    7

    Last publish

    Collaborators

    • enitoni