Coder Social home page Coder Social logo

yunaforseyfert's Introduction

yunaforseyfert

this really is for me and my friends. (my first enemies)

yunaforseyfert, it's a package that tries to bring the features of my bot, but for seyfert, at a really slow pace

installation

you can do it using npm or another packager manager, i prefer use pnpm

pnpm add yunaforseyfert

Features

YunaParser

An args parser for text commands, which adds various syntax for more convenient use of said commands, to the standard one provided.

Installation

After you install yunaforseyfert you need to import YunaParser like this

import { YunaParser } from "yunaforseyfert"

Then, you need to add it as seyfert's default argsParser, as follows

// your bot's client
new Client({ 
    commands: {
        argsParser: YunaParser() // Here are the settings, but that will be explained below
    }
});

And now, the magic will begin!

How this works, and what do?

Let's say you have the following command

const options = {
  first: createStringOption({
    description: "Penguins are life",
    required: true
  }),
  second: createStringOption({
    description: "Do you know i love penguins?",
    required: true
  })
}

@Declare({
  name: 'test',
  description: 'Test command'
})
@Options(options)
export default class TestCommand extends Command {

  async run(ctx: CommandContext<typeof options>) { 

    const { first, second } = ctx.options;

    const embed = new Embed({
        title: "Parsed!",
        fields: [
            {
                name: "First",
                value: first
            },
            {
                name: "Second",
                value: second
            }
        ]
    })

    await ctx.write({
      embeds: [embed]
    });
  }

}

The command has two options first and second, in that order.

For the parser, each word counts as an option, and will be added in the order of the command. That is, if we use the command in the following way:

ctx.options will be return

{
    "first": "Hellow!",
    "second": "penguin"
}

But, if i want to use more than one word?

You can use the following syntax

"your words" 'yout beutiful sentence' `penguin world`

it will return

{
    "first": "your words",
    "second": "your beatiful sentence"
}

Another case is that the option is the last or only one, in this case it will not be necessary to use "" and all the remaining content will be taken as the option, Example:

Named Syntax

What if I want to use the options in the order I want or need?

you can use the following syntaxes

--option content

-option content

option: content

Like this.

Escaping characters

You can escape any special character or syntax, if you need to, using \

this will return:

{
    "first": "hey!",
    "second": "how are you? --second well."
}

also this works with

" ' `

: - -- (in named options)

/ (in urls, like https://)

Config

The configurations allow changing the behavior of the parser; this is done when using YunaParser The allowed ones are as follows:

YunaParser({
    /**
     * this only show console.log with the options parsed.
     * @default false */
    logResult: false,

    enabled: {
        /** especify what longText tags you want
         *
         * " => "penguin life"
         *
         * ' => 'beautiful sentence'
         *
         * ` => `LiSA『Shouted Serenade』 is a good song`
         *
         * @default 🐧 all enabled
         */
        longTextTags: ['"', "'", "`"],
        /** especify what named syntax you want
         *
         *  -  => -option content value
         *
         *  -- => --option content value
         *
         *  :  => option: content value
         *
         * @default 🐧 all enabled
         */
        namedOptions: ["-", "--", ":"]
    },

    /**
     * Turning it on can be useful for when once all the options are obtained,
     * the last one can take all the remaining content, ignoring any other syntax.
     * @default {false}
     */
    breakSearchOnConsumeAllOptions: false,

    /**
     * Limit that you can't use named syntax "-" and ":" at the same time,
     * but only the first one used, sometimes it's useful to avoid confusion.
     * @default {false}
     */
    useUniqueNamedSyntaxAtSameTime: false,
    /**
    * This disables the use of longTextTags in the last option
    * @default {false}
    */
    disableLongTextTagsInLastOption: false,


    /** Use Yuna's choice resolver instead of the default one, put null if you don't want it,
     * 
     * YunaChoiceResolver allows you to search through choices regardless of case or lowercase, 
     * as well as allowing direct use of an choice's value,
     * and not being forced to use only the name. 
     * 
     * @default enabled
     */
    resolveCommandOptionsChoices: {
        /** Allow you to use the value of a choice directly, not necessarily search by name
         * @default {true}
         */
        canUseDirectlyValue: true;
    };
})

breakSearchOnConsumeAllOptions example

useUniqueNamedSyntaxAtSameTime example

disableLongTextTagsInLastOption example

Also, if necessary, each command can use a specific configuration. For this, you can use the @DeclareParserConfig decorator

import { DeclareParserConfig } from "yunaforseyfert";


const options = {
    first: createStringOption({
        description: "first option",
        required: true,
    }),
};

@Declare({
    name: "test",
    description: "with penguins the life is better.",
})
@Options(options)
@DeclareParserConfig({
  // Place your settings here
}) 
export default class TestCommand extends Command {}

Also, we provide some recommended configurations (only one at the moment :] ) for commands such as an Eval.

This can be used as

import { DeclareParserConfig, ParserRecommendedConfig } from "yunaforseyfert";


@DeclareParserConfig(ParserRecommendedConfig.Eval)

This will enable disableLongTextTagsInLastOption and breakSearchOnConsumeAll. Things that I consider necessary in an eval.

"Demostration" thanks to @justo

Thanks for read and using yunaforseyfert!
By SagiriIkeda with 🐧

yunaforseyfert's People

Contributors

sagiriikeda avatar

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.