GithubHelp home page GithubHelp logo

crivasr / booyah.js Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 1.0 35 KB

A simple booyah.live API implementation for chat bots or apps

JavaScript 100.00%
nodejs javascript chatbot bot booyah websocket stream freefire garena

booyah.js's Introduction

booyah.js

This is a work in progress npm module for interacting with the booyah API and chat.

Getting Started

Instalation

Install using npm:

npm install booyah.js

Connect with account

You first need to get your session_key:
Go to booyah and open the DevTool (press F12)
Then go to Application > Cookies > https://booyah.live/ and search for session_key. If you press it, it will show you the full token


Just copy that and replace "YOUR_SESSION_KEY" with that token.
"YOUR_USER_ID" is the id that shows when you got to your studio under your name.

const { Client } = require("booyah.js");

// start the bot with your credentials
const client = new Client("YOUR_SESSION_KEY", "YOUR_USER_ID");

client.connectChannels(["CHANNEL_ID"]);

client.on("chat", async (message, context, connection, self) => {
  //ignore messages sended by the bot
  if (self) return;
  
  const msg = message.data.msg;
  const name = message.data.nickname;
  
  if (msg.toLowerCase() == "hi"){
    connection.sendMessage(`Hello ${name}!`);
    // you can also do:
    // client.sendMessage(context.channel_id, `Hello ${name}!`);
  }
});

an other way to get a chat message is this:

const { Client, Constants } = require("booyah.js");

client.on("message", async (message, context, connection, self) => {
  if (self) return;

  if(Constants.msgTypes[message.event] != "chat") return;
  // TODO
});

Anonymous connection

You can also connect to a chat without those credentials, you can get the messages but you can't send them. Also, some API endpoints requires you to have a session, just like GET CHATROOMS/${user_id}/AUDIENCES*.

Instead of

const { Client } = require("booyah.js");

const client = new Client();

client.connectChannels(["CHANNEL_ID"]);

use

const { Client } = require("booyah.js");

const client = new Client();

client.connectChannelsAnon(["CHANNEL_ID"]);

If you use the other function it would still work but you'll have this alert when you connect Missing autentication parameters, starting anonoymous connection

Simple command handler

client.on("chat", async (message, context, connection, self) => {
  if (self) return;
  const msg = message.data.msg;

  const args = msg.split(" ");
  const commandName = args.shift();
  
  if (commandName == "!say"){
    connection.sendMessage(`${message.data.nickname} you said: ${args.join(" ")}`);
  }
})

More commands

  const isModerator = message.isModerator;

  // ban user by id 
  if (commandName == "!ban" && isModerator) {
    const target = args.shift();
    const reason = args.join(" ");

    connection.banUser(context.channel_id, target, reason).then((ban) => {
      // the banUser function bans an user and it returns a promise with the banned user and the channel where he got banned 
      // same for muteUser and pardonUser
      connection.sendMessage(`${ban.target.nickname} was banned, reason: ${reason}`);
    });
  }

  // unban an user by id
  if (commandName == "!pardon" && isModerator) {
    connection.pardonUser(context.channel_id, args[0]);
  }

  // ban for 10 minutes by id
  if (commandName == "!mute" && isModerator) {
    connection.muteUser(context.channel_id, args[0]);
  }

booyah.js's People

Contributors

crivasr avatar

Stargazers

 avatar  avatar  avatar  avatar Bruno Marques avatar Srsarcasmo01 avatar Arzex avatar Cristopher Paiva avatar

Watchers

 avatar

Forkers

juniyor-ul

booyah.js's Issues

User List

I'm having a problem using this BOT: it doesn't show up in the users watching list, something that is necessary for what I want to do.
Is there any way to do this without using BOT or to fix this with BOT in case it's an error?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.