arch-dev
v1.0.2
Published
[![npm version](https://badge.fury.io/js/arch-dev.svg)](https://www.npmjs.com/package/arch-dev)
Downloads
9
Readme
arch-dev
A small library for making "arch" bots, for my own chat application: Arch.
Prerequisites
This project requires NodeJS (version 8 or later) and NPM. Node and NPM are really easy to install. To make sure you have them available on your machine, try running the following command.
$ npm -v && node -v
6.4.1
v8.16.0
Getting Started
Installation
BEFORE YOU INSTALL: please read the prerequisites
To install and set up the library, run:
$ npm install arch-dev
Or if you prefer using Yarn:
$ yarn add --dev arch-dev
Usage
First, Start by importing the library
var arch = require('arch-dev');
var client = new arch.client('name', 'room');
var token = 'your token'; // more on how to get this later
now login with your credentials
client.init(client, token)
Events
client.on("msg", (ws, data) => {
if(data.user == client.user){
return // So the bot doesn't reply to itself
}
let msg = data.msg.msg;
console.log(msg);
});
client.on("ready", (ws, data) => {
console.log(`${data.user} has joined the application in ${data.room}`)
});
In the msg listener
data is all the data including the room and user. data.msg is the message object, which has more data. data.msg.msg is the acutal message sent as a string
In the ready listener
data is just data about the user joining and the room they joined in.
Sending Messages
client.send(ws, "Hello World!", "room");
When responding to specific commands sent from a user that might be in a different channel, I use data.room so the bot responds in the same channel as the user.
client.send(ws, `Hello World, ${data.user}!`, data.room);
Serving the app
$ npm start
Contributing
You can contribute to the project by making a pull request on GitHub.
Credits
Amukh1.
Built With
Authors
- Amukh1 - Github
See also the list of contributors who participated in this project.
License
MIT License © Amukh1