Skip to main content

AoiTelegram@0.8.2

Added

  • Added a delay before triggering the process:SIGINT event in the AoiWarning class to ensure all registered SIGINT handlers are executed.
  • For the CustomEvent class, registration of all process events now occurs. Events can be used by specifying process:EVENT_NAME (process:beforeExit, process:SIGTERM, process:SIGINT, process:worker, process:warning, process:unhandledRejection, process:uncaughtExceptionMonitor, process:uncaughtException, process:rejectionHandled, process:multipleResolves, process:message, process:exit, process:disconnect).
  • Added extended parameters that are specified only in the class constructor:
abstract class AoiExtension {
/** Extension name. */
abstract name: string;
/** Extension description. */
abstract description: string;
/** Extension version. */
abstract version: string;
/** Aoi library version(s) supported by the extension. */
abstract targetVersion?: string | string[];
/** Extensions required for the proper operation of this extension. */
abstract requireExtension?: string[];

/**
* Extension initialization.
* @param aoitelegram - AoiClient instance.
*/
abstract init(aoitelegram: AoiClient): void;
}

import { AoiClient, AoiExtension } from "aoitelegram";

class Abc extends AoiExtension {
name = "abc";
description = "Math or alphabet";
version = "0.0.1";

init(aoitelegram) {
aoitelegram.on("ready", () => {
console.log("Connect extension");
});
}
}

const client = new AoiClient({
token: "BOT_TOKEN",
extension: [new Abc()],
});
  • Added a new type of functions called "native functions." These are wrapper functions that can be local (not globally accessible in other events/commands) or global. They can be created using the <AoiClient>.addNative method or specified in the <AoiClient>.options.native constructor. Native functions use JavaScript functions that you specify.

First example:

import { AoiClient, type Context } from "aoitelegram";

// If we create a global native function, we can access the command context. AoiTelegram also parses the arguments passed, making working with native functions easier.
function isNumberNative(context: Context, ...args: any[]) {
return typeof args[0] !== "number" ? false : true;
}

const client = new AoiClient({
token: "BOT_TOKEN",
native: [isNumberNative],
});

function isStringNative(context: Context, ...args: any[]) {
return typeof args[0] !== "string" ? false : true;
}

client.addNative([isStringNative]);

Second example:

// Local native functions are only available in a specific command/event. Unlike global native functions, local functions only have access to the passed arguments.
function sempai(args: any[]) {
return `${args[0]}:sempaika`;
}

client.addCommand({
name: "start",
useNative: [sempai],
code: "$sendMessage[$sempai[$username]]" // @SempaiJS:sempaika
});

client.addCommand({
name: "start2",
code: "$sendMessage[$sempai[$username]]" // $sempai[@SempaiJS]
});

Third example:

// If we use native functions in custom functions, we can access not only the specified native functions when creating, but also the native functions of the command in which this function was called.
// The priority of native functions specified in the command is higher, so if we have the same names of native functions both in the custom function and in the command, the native function will be called from the command.

// File commands/findUsers:
function findIndex(text: string, findChar: string) {
return text.findIndex((char) => char === findChar);
}

export default {
name: "find",
useNative: [findIndex],
code: `
$sendMessage[Index "@": $get[text]]
$let[text;$testIndex[$message;@]]
`
}

// File index.js:
function findIndex(text: string, findChar: string) {
return text.findIndex((char) => char === findChar) !== 1;
}

client.addFunction({
name: "$testIndex",
params: ["text", "findChar"],
useNative: "aoitelegram",
code: "$sendMessage[Has/index?: $findIndex[{text};{findChar}]]"
});
// As a result, $testIndex will return a number, even though we have a registered native function that returns a logical expression.

Changed

  • For easier code writing, the import-sync library has been added, which supports both esm and cjs syntax simultaneously. Now you can use different types of modules regardless of the settings in package.json (the main file always has cjs syntax).
  • Promises are now used for loading functions in PluginManager. Instead of <AoiClient>.addFunction, <AoiClient>.ensureFunction is now used, allowing function rewriting.
  • Promises are now also used for event loaders in CustomEvent.
  • The function context has been completely changed. The function context will no longer be created each time a command is run; it will be updated each time functions are called. Also, different information can now be passed between functions in the context. This is related to future function updates.

AoiTelegram Function

Changed

  • Slightly modified the $eventData function for CustomEvent. Now, in some cases, it will not output [object Object], but will use JSON.stringify (this also applies to events: <AoiClient>.variableCreateCommand, <AoiClient>.variableUpdateCommand, <AoiClient>.variableDeleteCommand).

Removed

  • The $updateCommands function has been temporarily removed.

Added

  • Added the packageJSON object to the context of custom functions, which provides information from the AoiTelegram package.json.
  • Added new functions: $clientDestroy, $concatTextSplit, $replaceTextWithRegex, $textSplit, $toLocaleDateString, $toLocaleString, $toLocaleTimeString, $parseJSON, $isPositive, $isNegative, $stringifyJSON, $inRange, $minSafeInteger, $chatFirstName, $chatIsForum, $chatTitle, $chatType, $chatUsername, $entitiesMessage, $filterTextSplitElement, $editTextSplitElement, $findTextSplitIndex, $getTextSplit, $getTextSplitLength, $isFloat, $isInteger, $isSafeInteger, $isUnicodeEmoji, $joinSplitText, $numberSeparator, $removeTextSplitElement, $findChars, $findNumbers, $hasFunction, $isValidLink, $randomShuffle.