This module can be used to make a chat bot for the website DogeChat using Node.JS and it simplifies the process a great deal. Please note the following when making a bot for DogeChat:
- A bot account must have a username ending in bot.
- Bot accounts must be registered as bots - contact a moderator on DogeChat to arrange this.
- A bot must not make more than 2 sequential unprompted messages.
To install the module and its dependencies, create a folder to make you bot in and open your command line there. Then type npm install dogechat-bot
to install the module.
You will first need to sign up for a new account, following the rules above, on DogeChat. Next you should create a room to host your bot in, this is usually the same as your bots name. To start the script make a javascript file containing the following code and run this file to start your bot. Below is an example of a simple bot.
var bot = require('dogechat-bot');
bot.connect(BOT_USERNAME, BOT_PASSWORD, function() {
bot.joinRoom("awesomebot");
bot.chat("Bot is online!", "awesomebot");
});
bot.addCommand("!help", function(data) {
bot.chat(data.user + ": Welcome to my bot! This message is displayed when a user types !help.", data.room);
});
This adds a command to the command registry so that when a user types command
the function fn
will be executed.
bot.addCommand("!command", function(data) {
// Handle what to do with the command here.
});
data
contains an object with some information about the message received.
user
- The user who sent the messagemessage
- A neatly formatted version of the message receivedmessageArray
- An array containing the message split up by spaces to make handling parameters easierroom
- The room in which the message was postedtimestamp
- An ISO-8601 formatted datetime string of when the message was sent
This will add message
to an internal buffer to output it and chat the message in room
.
bot.chat("Hello, world!", "awesomebot");
This will tip user
the specified amount
of dogecoins in the room room
with the optional message: message
.
bot.tip("cainy", 20, "awesomebot", "Thanks for the cool node module!");
This specifies a function to be called when the bot receives a tip. The data object contains the following information:
bot.onTip(function(data) {
// Handle what to do when you receive a tip.
});
user
- The user who tipped youamount
- How many dogecoins they tipped youmessage
- The message they specified (if any)room
- The room the user tipped you intimestamp
- An ISO-8601 formatted datetime string of when the message was sent
This will send a request for your bot to join room
.
bot.joinRoom("awesomebot");
This will quit the room room
.
bot.quitRoom("awesomebot");
This returns the bots balance. This is unfortunately often inaccurate because DogeChat does not always send you every balance update and because a bot is likely to send and receive many tips in quick succession this can become quite inaccurate. However, immediately after logging in it will be accurate.
var myBalance = bot.getBalance();
This will set the color your bot messages with. Obviously you must have bought this color on the bots account otherwise the color will default to black.
bot.setColor("a22");
This will set the badge your bot messages with. Obviously you must have bought this badge on the bots account otherwise the badge will default to none.
bot.setBadge("cake");
This sets how detailed the logging will be made by the module. This will default to 1
if not set.
0
- No logs will be made at all.1
- Only important information and warnings will be logged2
- The above as well as debug logs3
- All of the above as well as any chat messages/tips received