lytescript
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

LyteScript

A powerful TypeScript library to create Revolt bots with ease.

Basic Setup

const { Bot } = require('lytescript')

const client = new Bot({
    database?: DatabaseOptions,
    events?: string[],
    prefixes: string[]
})

Syntax

LyteScript has a basic syntax to create your codes.

Prefix

Every LyteScript function starts with "@" as prefix. Every text starting with "@" will be interpreted as function, if the function doesn't exists, it won't be interpreted.

Parameter container

Functions can contain parameters or not. Function parameters must be delimited with "[" and "]". Example: @function[inside]

Multiple parameters

Functions can contain multiple parameters, each parameter must be separated with ";". Example: @function[param1;param2;...]

Commands

Command Manager lets you add your own commands.

Main File

Add your commands in your main file.
const bot = new Bot({...})
bot.commands.add({
    name: 'ping',
    type: 'message',
    code: `
        @sendMessage[
            @setContent[Pong! <#AT#@author[id]>]
        ]
    `
})

Loader

Load commands from a directory. (Directory must be absolute)
const bot = new Bot({...})
bot.commands.load('./commands_path/').then(async () => {
    console.log('Commands loaded')
    await bot.login('<TOKEN>', 'bot')
})

In-file command

/** @type {import('lytescript').ICommand} */
module.exports['default'] = {
    name: 'ping',
    type: 'message',
    code: `
        @sendMessage[
            @setContent[Pong! <#AT#@author[id]>]
        ]
    `
} // <- This can be an array too.

Events

To run all commands you declared you must declare its types in bot constructor options. If you don't do this, the event won't be listened.
const bot = new Bot({
    events: [
        'message',
        'ready'
    ],
    prefixes: ['!']
})
bot.commands.add({
    name: 'ping',
    type: 'message',
    code: `
        @sendMessage[
            @setContent[Pong! <#AT#@author[id]>]
        ]
    `
}).add({
    type: 'ready',
    code: `
        @log[Client started: Name => @client[name]]
    `
})

Database

LyteScript provides native support for a built-in database. Just configure as you want and you're ready to go.
const { Bot } = require('lytescript')

const bot = new Bot({
    database: {
        path: './mydb',
        tables: ['main']
    },
    events: ['ready'],
    prefixes: ['!']
})

bot.commands.add({
    type: 'ready',
    code: `
        @setVar[msg;Hello world!]
        @log[@getVar[msg]] // Hello world!
    `
})

Custom Functions

Function Manager provides the possibility for adding your own functions.
const bot = new Bot({...})
bot.functions.add({
    name: 'multipleSum',
    description: 'Sum multiple numbers.',
    parameters: [
        {
            name: 'Numbers',
            description: 'Numbers to sum.',
            type: ParameterType.Number,
            required: true
        }
    ],
    execute: async (d) => {
        const numbers = d.function.compiled.parameters.map(param => Number(param.value))
        let result = 0
        for (const nm of numbers)
            result = result + nm
        return result
    }
})

⚠️ This library reads from top to bottom and never the opposite.

Package Sidebar

Install

npm i lytescript

Weekly Downloads

0

Version

0.0.3

License

Apache-2.0

Unpacked Size

285 kB

Total Files

253

Last publish

Collaborators

  • asayukiii