Giter VIP home page Giter VIP logo

guraai's Introduction

GuraAI

About

GuraAI was a discord bot made with discord.js, TypeScript and bun. It utilizes node_characterai in order to retreieve data from character.ai, in order to act as a chatbot.

Note

Due to the limitations of the node_characterai package, you must wait for a response before sending another message (due to puppeteer constraints). While there is a way around this, it requires making multiple chromium instances, which requires a lot of system resources. Because of this, there is no official already hosted bot, and you must selfhost it.

Usage

Setup

If you would like to selfhost this bot, make sure you have bun installed first.

$ git clone https://github.com/FireStreaker2/GuraAI.git
$ cd GuraAI
$ bun i
$ cp .env.example .env
$ bun start

Configuration

There are a couple environment variables you can configure in order to adjust the bot.

  • TOKEN: Token of the discord bot
  • CLIENT_ID: ID of the discord bot
  • ID: ID of the character on character.ai
  • CAI_TOKEN: Your token for character.ai

Note

Look here for more info regarding how to get your character.ai token

Others

Talking with multiple people at once

If you would like to have the bot be able to talk to multiple people at once, you can configure it to make new instances of the CharacterAI package every time. For example:

// ask.ts
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
import { config } from "../config";

export const data = new SlashCommandBuilder()
	.setName("ask")
	.setDescription("Ask a question")
	.addStringOption((option) =>
		option
			.setName("query")
			.setDescription("What you want to ask")
			.setRequired(true)
	);

export const execute = async (interaction: CommandInteraction) => {
	await interaction.deferReply();

  const CharacterAI = require("node_characterai");
  const characterAI = new CharacterAI();
  await characterAI.authenticateWithToken(config.CAI_TOKEN);

	const chat = await characterAI.createOrContinueChat(config.ID);
	const response = await chat.sendAndAwaitResponse(
		`(OOC: This message was sent by ${
			interaction.user.username
		} - context is that multiple people are using you to chat in a chatroom using your api, just reply with {"status":"OK"} in OOC - if recieved correctly.)\n\n\n${
			interaction.options.get("query")?.value
		}`,
		true
	);

	response.text = response.text.includes(`{"status": "OK"}`)
		? response.text
				.replace(/\{"status"\s*:\s*"OK"\}\s*\.\.\./, "")
				.replace(/[Hh]([ae]llo|ewwo)\s*~/, "")
		: "Error";

	await interaction.editReply({
		content: response.text,
		allowedMentions: { parse: [] },
	});
};

Login as guest

If you would like to login as a guest instead of authenticating with your own token, you can edit characterai.ts like so:

// characterai.ts
import { config } from "./config";

const CharacterAI = require("node_characterai");
const characterAI = new CharacterAI();
- characterAI.authenticateWithToken(config.CAI_TOKEN);
+ await characterAI.authenticateAsGuest();

export default characterAI;

Contributing

If you would like to contribute, you can fork the repo and make a PR, or contact me via email @ [email protected]

License

MIT

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.