Skip to content

Latest commit

 

History

History
136 lines (101 loc) · 3.9 KB

README.md

File metadata and controls

136 lines (101 loc) · 3.9 KB

aoi.MongoDB

A Mongo DB connecting package for AoiJS without conflicting with AoiDB!


Installation

npm install github:NanotechPikachu/aoi.mongodb

Index Setup

const aoimongo = require("aoi.mongodb");
const { AoiClient } = require("aoi.js");

// AOI setup
const client = new AoiClient({
    token: "DISCORD BOT TOKEN",
    prefix: "DISCORD BOT PREFIX",
    intents: ["MessageContent", "Guilds", "GuildMessages"],
    events: ["onMessage", "onInteractionCreate"],
    database: {
        type: "aoi.db",
        db: require("@akarui/aoi.db"),
        dbType: "KeyValue",
        tables: ["main"],
        securityKey: "a-32-characters-long-string-here"
    }
});

client.loadCommands("./commands/", true);

// aoi.MongoDB setup
aoimongo.setup({
    client: client,
    mongoURL: "MONGO URL", // Like - "mongodb+srv://..."
    variables: require("Path to Variable File") // You MUST initialize a file with variables and require() it here. Like - require("./var.js") if var.js is the variables file name
});

Variables File

module.exports = {
    num: 0, // Number
    ar: [], // Array
    ob: {}, // Object
    st: "Hola!", // String
    boo: true // Boolean
}

Warning

Without the variables file, you cannot use functions nor the app(bot) will work.

Note

It is also essential to make(initialize) the variable in this file before accessing it; the same as AoiDB. Provided, it must not be the same file AKA this file and the AoiDB variables file are different.

Functions

aoi.MongoDB AoiDB Usage
$getMVar $getVar $getMVar[varname]
$getGlobalUserMVar $getGlobalUserVar $getGlobalUserMVar[varname;userId?]
$getGuildMVar $getGuildVar $getGuildMVar[varname;guildId?]
$getMessageMVar $getMessageVar $getMessageMVar[varname;messageId?]
$getUserMVar $getUserVar $getUserMVar[varname;userId?;guildId?]
$getChannelMVar $getChannelVar $getChannelMVar[varname;channelId?]
$setMVar $setVar $setMVar[varname;value]
$setGlobalUserMVar $setGlobalUserVar $setGlobalUserMVar[varname;value;userId?]
$setGuildMVar $setGuildVar $setGuildMVar[varname;value;guildId?]
$setMessageMVar $setMessageVar $setMessageMVar[varname;value;messageId?]
$setUserMVar $setUserVar $setUserMVar[varname;value;userId?;guildId?]
$setChannelMVar $setChannelVar $setChannelMVar[varname;value;channelId?]

Add-on Functions

$mongoArray

A function for performing Array functions "push" and "pull".

Syntax: $mongoArray[varname;value;action;varType;id?]

  • Action - push / pull

  • varType - user / globaluser / guild / global / message / channel

  • id - default null(or depending on varType default will be auto added). If you want to use vars which has 2 params like user(which supports guildId and userId) use like - if "user" -> userId:guildId

$mongoPing

A function which returns the latency of mongo DB in ms.

Syntax: $mongoPing




Note

Basically, the difference is that you have to add an "M" before the "Var" in the function name and Walah! you can use AoiDB as well as, Mongo DB in your app!




DiscordJS Usage

This package also has JavaScript functions which can be used with $djsEval which you are evaling DJS / JS in aoi or not.

Note

This section can only be used in JS evaling. But, can be used with non aoi packages too!

Functions

  • getUserVar()
  • getGlobalUserVar()
  • getGuildVar()
  • getChannelVar()
  • getMessageVar()
  • getGlobalVar()
  • setUserVar()
  • setGlobalUserVar()
  • setGuildVar()
  • setChannelVar()
  • setMessageVar()
  • setGlobalVar()

In order to use the above function, import it in the JS medium like:

const { functionName } = require('aoi.mongodb/func'); // 'func' is the path where these functions are made