1.2.4 • Published 4 years ago

framecord v1.2.4

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

FrameCord

A Discord bot framework made by Sana Rinomi.

Install via NPM: npm i -s framecord

Index

Setting up a Bot

To get your bot up up and running is rather simple! We create a Client and then we use the login() function to start the bot!

const {Client} = require("framecord");

let client = new Client("Discord bot token", "d", function(client) { console.log(`Logged in as ${client.discordCli.user.tag}`); });

client.login();

Adding Commands

To add commands to our bot, we need to first create a Node! This node can be be a simple Node or it could also be a DataNode. This node will be the base we will call commands from, and there can be multiple!

In this example we will use a DataNode with the ID of ! and add it to our client.

const {Client, Nodes} = require("framecord");

let client = new Client("Discord bot token", "d", function(client) { console.log(`Logged in as ${client.discordCli.user.tag}`); });

let Base = new Nodes.DataNode("!");

client.registerNode(Base);

client.login();

Now we can add our command, which to do so, we will create a new CommandNode. And as an example, we will make a command that closes our program.

Here's how we create a command:

const {Client, Nodes} = require("framecord");

let client = new Client("Discord bot token", "d", function(client) { console.log(`Logged in as ${client.discordCli.user.tag}`); });

let Base = new Nodes.DataNode("!");
let Exit = new Nodes.CommandNode("exit", (cli, command, msg) => {
    msg.reply("See you later!").then(() => {
        cli.exit();
    });
});

client.registerNode(Base);

client.login();

There are 2 ways we can add the command node to our client:

  • Using addChild(Node)
  • Using the client method registerNode(Node, String) with a path

Each one has their own benefits, so choose according to what you want to do. You can also use both methods at the same time, so a hybrid approach is possible.

Adding Commands: Method 1

This example shows the use of addChild(Node):

const {Client, Nodes} = require("framecord");

let client = new Client("Discord bot token", "d", function(client) { console.log(`Logged in as ${client.discordCli.user.tag}`); });

let Base = new Nodes.DataNode("!");
let Exit = new Nodes.CommandNode("exit", (cli, command, msg) => {
    msg.reply("See you later!").then(() => {
        cli.exit();
    });
});

Base.addChild(Exit);
client.registerNode(Base);

client.login();

This method is easier to implement, since you directly add your node to the parent using Node's addChild(Node) method without having to worry if the parent exists.

Adding Commands: Method 2

This example shows the use of your client's registerNode(Node, String) method using a path:

const {Client, Nodes} = require("framecord");

let client = new Client("Discord bot token", "d", function(client) { console.log(`Logged in as ${client.discordCli.user.tag}`); });

let Base = new Nodes.DataNode("!");
let Exit = new Nodes.CommandNode("exit", (cli, command, msg) => {
    msg.reply("See you later!").then(() => {
        cli.exit();
    });
});

client.registerNode(Base);
client.registerNode(Exit, "!");

client.login();

With this method, you have to make sure your parent node is already registered, the path is exactly like how you'd call a command within Discord just without the prefix. Like in this example, we want to register a node to our base !, in Discord our path would be e! while the path within the client itself would just be !. A few more examples:

  • e!foo => !foo
  • e!foo bar => !foo bar

Be aware that registerNode(Node, String) uses the same method as executeNode(String) which is used to call commands. Which means that registering something to !foo bar doesntexist would register to node bar, and doesntexist would be returned as a command argument.

This method works great for modular bots, with code that's loaded in dynamically.

Nodes

You can find all the nodes under Nodes in FrameCord:

const {Nodes} = require("framecord");

These are the nodes available by default with FrameCord:

Node

Type: blank. This node is our base node, and every other node is going to be based off of it.

Constructor

ValueDescriptionTypeDefault
idID of the nodeStringnull

Variables

VariableTypeRead-Only
TypeStringYes
IDStringYes
ParentNodeNo
ChildrenArrayNo
HasChildrenBooleanYes
FirstChildNodeYes
LastChildNodeYes

Methods

MethodDescriptionReturn Value
addChild(Node)Adds a child node to the current node. Errors if child with same ID is present!null
getChild()Gets a child from the current node. Returns null if that child doesn't exist.Node or null
removeChild(String)Removes any child with the ID specified.*null
removeChildren()Removes all children from the current node.null
delete()Calls removeChildren() and sets all data stored within to null.null
equals(Node)Returns true if the IDs and Types match between the current node and the one passed, false if not.Boolean
toBlankNode()Returns a new Node instance with the same ID and Children as the current node.Node of type blank
clone()Returns a new Node of the same type with the same values.Node of same type
  • Removing children will call the delete() function of the children.

Data Node

DataNode extends Node.

Type: data. This node adds basic data such as Name. Description, Tags and IsNSFW to Node.

Constructor

ValueDescriptionTypeDefault
idID of the nodeStringnull
dataObject with the values name, desc, tags[] and nsfwJSON or JS Object{name: "", desc: "", tags: [], nsfw: false}

Variables

VariableTypeRead-Only
NameStringYes
DescriptionStringYes
TagsArrayYes
IsNSFWBooleanYes

Methods

MethodDescriptionReturn Value
toDataNode()Same function as toBlankNode(), but includes the values Name, Description, Tags and IsNSFWNode of type data
static toDataNode(Node, {name: "", desc: "", tags: [], nsfw: false})Same function as toBlankNode(), but includes the values Name, Description, Tags and IsNSFWNode of type data

Root Node

RootNode extends Node.

Type: root. This node includes a bunch of methods related to finding and retrieving nodes, and creating command variables. Used mainly by a Client instance.

Constructor

ValueDescriptionTypeDefault
idID of the nodeStringnull

Methods

MethodDescriptionReturn Value
getRegex(Boolean = true)Returns a regular expression, mainly to separate out the prefix, from the base node and from the command nodeRegExp
getCommandObj(String)Creates a command object from a string.Command Obj: {prefix, values: [], commands: [], args: []}
crawl(String or CommandObj)Crawls the tree to return in search of an appropriate node. If a string is passes, it will be turned into a CommandObj. Returns null if nothing could be found.{Node, CommandObj} or null
static toRootNode(Node)Same function as toBlankNode().Node of type root

Command Node

CommandNode extends DataNode.

Type: command. This node adds basic data such as Name. Description, Tags and IsNSFW to Node.

Constructor

ValueDescriptionTypeDefault
idID of the nodeStringnull
callFunction to call when executing commandFunctionnull
dataObject with the values name, desc, tags[] and nsfwJSON or JS Object{name: "", desc: "", tags: [], nsfw: false}

Variables

VariableTypeRead-Only
CallFunctionNo

Methods

MethodDescriptionReturn Value
execute()Executes Call as long as bot has SEND_MESSAGES privilages, else calls command.botPermissionFail event. If IsNSFW is true, then checks if in NSFW channel in Discord servers, if fails, calls command.notInNSFW event.null
toCommandNode()Same function as toDataNode(), but includes the Call value.Node of type data
static toCommandNode(Node, callFunc, {name: "", desc: "", tags: [], nsfw: false})Same function as toDataNode(), but includes the Call value.Node of type command
1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.18

4 years ago

1.1.17

4 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago