Add type conversion for /setvar commands with index

This commit is contained in:
Cohee
2024-08-29 12:55:54 +00:00
parent 7aaabbd2bb
commit 3746f08590
4 changed files with 166 additions and 39 deletions

View File

@ -1,4 +1,5 @@
import { SlashCommandClosure } from './SlashCommandClosure.js';
import { convertValueType } from '../utils.js';
export class SlashCommandScope {
/**@type {string[]}*/ variableNames = [];
@ -55,7 +56,8 @@ export class SlashCommandScope {
if (this.existsVariableInScope(key)) throw new SlashCommandScopeVariableExistsError(`Variable named "${key}" already exists.`);
this.variables[key] = value;
}
setVariable(key, value, index = null) {
setVariable(key, value, index = null, type = null) {
value = convertValueType(value, type);
if (this.existsVariableInScope(key)) {
if (index !== null && index !== undefined) {
let v = this.variables[key];