1.12.3 • Published 2 years ago

chatty.js v1.12.3

Weekly downloads
-
License
GPL-3.0
Repository
-
Last release
2 years ago

Chatty.js

Simple, yet effective bot API wrapper for Chatty

Example

import Bot from 'chatty.js'
import commands from './[your commands file here].js'

let config = {
    name: "example (name cannot have spaces)",
    info: "example",
    channel: "hangout",
    image: "https://i.enzon3.wip.la/code.png"
}

const bot = new Bot(config, commands)

//callback for when a message is received (slash commands should not handled here)
bot.onMessageRecv = function (e) {
    let data = JSON.parse(e.data)

    if (data.token !== undefined || data.error !== undefined) {
        console.log(data)
    }
}

bot.run()

Commands file for example

Fallback command is required for proper functionality.

import { Exports } from "chatty.js";

let exports = new Exports();

let commands = {
    help: {
      desc: 'Get a list of commands, or help for a specific command',
      usage: 'help [command]',
      exec: async function (e) {
        return exports.helpString();
      },
    },
    say: {
      desc: 'Quote something from you',
      usage: 'say <whatever>',
      exec: async function(e) {
        return `> ${e.command.slice(1).join(' ')}  \n— *${e.who.name}*`;
      }
    },
    fallback: {
      exec: async function (e) {
        return `I'm sorry, ${e.who.name}, I did not understand your command.`;
      },
    },
};

export default commands
1.12.3

2 years ago