mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-22 23:18:27 +01:00
error handling
This commit is contained in:
parent
e3c2d6771c
commit
a088fb1746
@ -72,7 +72,9 @@ export class QuickReplyApi {
|
|||||||
*/
|
*/
|
||||||
toggleGlobalSet(name, isVisible = true) {
|
toggleGlobalSet(name, isVisible = true) {
|
||||||
const set = this.getSetByName(name);
|
const set = this.getSetByName(name);
|
||||||
if (!set) return;
|
if (!set) {
|
||||||
|
throw new Error(`No quick reply set with name "${name}" found.`);
|
||||||
|
}
|
||||||
if (this.settings.config.hasSet(set)) {
|
if (this.settings.config.hasSet(set)) {
|
||||||
this.settings.config.removeSet(set);
|
this.settings.config.removeSet(set);
|
||||||
} else {
|
} else {
|
||||||
@ -88,7 +90,9 @@ export class QuickReplyApi {
|
|||||||
*/
|
*/
|
||||||
addGlobalSet(name, isVisible = true) {
|
addGlobalSet(name, isVisible = true) {
|
||||||
const set = this.getSetByName(name);
|
const set = this.getSetByName(name);
|
||||||
if (!set) return;
|
if (!set) {
|
||||||
|
throw new Error(`No quick reply set with name "${name}" found.`);
|
||||||
|
}
|
||||||
this.settings.config.addSet(set, isVisible);
|
this.settings.config.addSet(set, isVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +103,9 @@ export class QuickReplyApi {
|
|||||||
*/
|
*/
|
||||||
removeGlobalSet(name) {
|
removeGlobalSet(name) {
|
||||||
const set = this.getSetByName(name);
|
const set = this.getSetByName(name);
|
||||||
if (!set) return;
|
if (!set) {
|
||||||
|
throw new Error(`No quick reply set with name "${name}" found.`);
|
||||||
|
}
|
||||||
this.settings.config.removeSet(set);
|
this.settings.config.removeSet(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +119,9 @@ export class QuickReplyApi {
|
|||||||
toggleChatSet(name, isVisible = true) {
|
toggleChatSet(name, isVisible = true) {
|
||||||
if (!this.settings.chatConfig) return;
|
if (!this.settings.chatConfig) return;
|
||||||
const set = this.getSetByName(name);
|
const set = this.getSetByName(name);
|
||||||
if (!set) return;
|
if (!set) {
|
||||||
|
throw new Error(`No quick reply set with name "${name}" found.`);
|
||||||
|
}
|
||||||
if (this.settings.chatConfig.hasSet(set)) {
|
if (this.settings.chatConfig.hasSet(set)) {
|
||||||
this.settings.chatConfig.removeSet(set);
|
this.settings.chatConfig.removeSet(set);
|
||||||
} else {
|
} else {
|
||||||
@ -130,7 +138,9 @@ export class QuickReplyApi {
|
|||||||
addChatSet(name, isVisible = true) {
|
addChatSet(name, isVisible = true) {
|
||||||
if (!this.settings.chatConfig) return;
|
if (!this.settings.chatConfig) return;
|
||||||
const set = this.getSetByName(name);
|
const set = this.getSetByName(name);
|
||||||
if (!set) return;
|
if (!set) {
|
||||||
|
throw new Error(`No quick reply set with name "${name}" found.`);
|
||||||
|
}
|
||||||
this.settings.chatConfig.addSet(set, isVisible);
|
this.settings.chatConfig.addSet(set, isVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +152,9 @@ export class QuickReplyApi {
|
|||||||
removeChatSet(name) {
|
removeChatSet(name) {
|
||||||
if (!this.settings.chatConfig) return;
|
if (!this.settings.chatConfig) return;
|
||||||
const set = this.getSetByName(name);
|
const set = this.getSetByName(name);
|
||||||
if (!set) return;
|
if (!set) {
|
||||||
|
throw new Error(`No quick reply set with name "${name}" found.`);
|
||||||
|
}
|
||||||
this.settings.chatConfig.removeSet(set);
|
this.settings.chatConfig.removeSet(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,24 +85,48 @@ export class SlashCommandHandler {
|
|||||||
|
|
||||||
|
|
||||||
toggleGlobalSet(name, args = {}) {
|
toggleGlobalSet(name, args = {}) {
|
||||||
|
try {
|
||||||
this.api.toggleGlobalSet(name, JSON.parse(args.visible ?? 'true') === true);
|
this.api.toggleGlobalSet(name, JSON.parse(args.visible ?? 'true') === true);
|
||||||
|
} catch (ex) {
|
||||||
|
toastr.error(ex.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
addGlobalSet(name, args = {}) {
|
addGlobalSet(name, args = {}) {
|
||||||
|
try {
|
||||||
this.api.addGlobalSet(name, JSON.parse(args.visible ?? 'true') === true);
|
this.api.addGlobalSet(name, JSON.parse(args.visible ?? 'true') === true);
|
||||||
|
} catch (ex) {
|
||||||
|
toastr.error(ex.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
removeGlobalSet(name) {
|
removeGlobalSet(name) {
|
||||||
|
try {
|
||||||
this.api.removeGlobalSet(name);
|
this.api.removeGlobalSet(name);
|
||||||
|
} catch (ex) {
|
||||||
|
toastr.error(ex.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
toggleChatSet(name, args = {}) {
|
toggleChatSet(name, args = {}) {
|
||||||
|
try {
|
||||||
this.api.toggleChatSet(name, JSON.parse(args.visible ?? 'true') === true);
|
this.api.toggleChatSet(name, JSON.parse(args.visible ?? 'true') === true);
|
||||||
|
} catch (ex) {
|
||||||
|
toastr.error(ex.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
addChatSet(name, args = {}) {
|
addChatSet(name, args = {}) {
|
||||||
|
try {
|
||||||
this.api.addChatSet(name, JSON.parse(args.visible ?? 'true') === true);
|
this.api.addChatSet(name, JSON.parse(args.visible ?? 'true') === true);
|
||||||
|
} catch (ex) {
|
||||||
|
toastr.error(ex.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
removeChatSet(name) {
|
removeChatSet(name) {
|
||||||
|
try {
|
||||||
this.api.removeChatSet(name);
|
this.api.removeChatSet(name);
|
||||||
|
} catch (ex) {
|
||||||
|
toastr.error(ex.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -174,13 +198,16 @@ export class SlashCommandHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
clearContextMenu(args, label) {
|
clearContextMenu(args, label) {
|
||||||
const qr = this.getQrByLabel(args.set, args.label ?? label);
|
try {
|
||||||
if (!qr) return;
|
this.api.clearContextMenu(args.set, args.label ?? label);
|
||||||
qr.clearContextLinks();
|
} catch (ex) {
|
||||||
|
toastr.error(ex.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
createSet(name, args) {
|
createSet(name, args) {
|
||||||
|
try {
|
||||||
this.api.createSet(
|
this.api.createSet(
|
||||||
args.name ?? name ?? '',
|
args.name ?? name ?? '',
|
||||||
{
|
{
|
||||||
@ -189,8 +216,12 @@ export class SlashCommandHandler {
|
|||||||
injectInput: JSON.parse(args.inject ?? 'false') === true,
|
injectInput: JSON.parse(args.inject ?? 'false') === true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
} catch (ex) {
|
||||||
|
toastr.error(ex.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
updateSet(name, args) {
|
updateSet(name, args) {
|
||||||
|
try {
|
||||||
this.api.updateSet(
|
this.api.updateSet(
|
||||||
args.name ?? name ?? '',
|
args.name ?? name ?? '',
|
||||||
{
|
{
|
||||||
@ -199,5 +230,9 @@ export class SlashCommandHandler {
|
|||||||
injectInput: args.inject !== undefined ? JSON.parse(args.inject ?? 'false') === true : undefined,
|
injectInput: args.inject !== undefined ? JSON.parse(args.inject ?? 'false') === true : undefined,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
} catch (ex) {
|
||||||
|
toastr.error(ex.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user