@@ -17,6 +17,7 @@ import { Logger } from '@/utils/logger';
1717
1818import type { PSCommandContext } from '@/types/chat' ;
1919import type { PSMessage } from '@/types/ps' ;
20+ import type { Interaction } from 'discord.js' ;
2021
2122// Exporting into side variables for eval lookup; this gets garbage-collected otherwise
2223const cache = _cache ;
@@ -37,20 +38,21 @@ const E: Record<string, unknown> = {};
3738// Storing in context for eval()
3839const _evalContext = [ cache , cachebust , fs , fsSync , fsPath , path , Tools , $ , Sentinel , E , jsxToHTML , paste ] ;
3940
40- export type EvalModes = 'COLOR_OUTPUT ' | 'FULL_OUTPUT' | 'ABBR_OUTPUT' | 'NO_OUTPUT' ;
41+ export type EvalModes = 'COLOR_OUTPUT_HTML' | 'COLOR_OUTPUT_ANSI ' | 'FULL_OUTPUT' | 'ABBR_OUTPUT' | 'NO_OUTPUT' ;
4142export type EvalOutput = {
4243 success : boolean ;
4344 output : string ;
4445} ;
4546
4647export function formatValue ( value : unknown , mode : EvalModes ) : string {
4748 switch ( mode ) {
48- case 'COLOR_OUTPUT' :
49+ case 'COLOR_OUTPUT_ANSI' :
50+ case 'COLOR_OUTPUT_HTML' :
4951 case 'FULL_OUTPUT' : {
50- const color = mode === 'COLOR_OUTPUT ' ;
52+ const color = mode === 'COLOR_OUTPUT_HTML' || mode === 'COLOR_OUTPUT_ANSI ';
5153 // TODO Stringify functions and render with syntax highlighting
5254 const inspection = inspect ( value , { depth : 2 , colors : color , numericSeparator : true } ) ;
53- return color
55+ return mode === 'COLOR_OUTPUT_HTML'
5456 ? ansiToHtml ( inspection )
5557 . replace ( / \t / g, ' ' . repeat ( 4 ) ) // Fill out tabs
5658 . replace ( / (? = | $ ) / g, ' ' ) // Fill out multi-spaces
@@ -104,10 +106,12 @@ export function formatValue(value: unknown, mode: EvalModes): string {
104106export async function evaluate (
105107 code : string ,
106108 mode : EvalModes ,
107- passedContext : {
108- message : PSMessage ;
109- context : PSCommandContext ;
110- } // Add Discord case here, eventually
109+ passedContext :
110+ | {
111+ message : PSMessage ;
112+ context : PSCommandContext ;
113+ }
114+ | { message : Interaction ; context : null }
111115) : Promise < EvalOutput > {
112116 let success : boolean , value : unknown ;
113117 try {
0 commit comments