Skip to content

Commit 00edd2c

Browse files
committed
Update code execution, Add back ImageScript v1 (iscript) to tags
1 parent cde9d43 commit 00edd2c

File tree

9 files changed

+278
-45
lines changed

9 files changed

+278
-45
lines changed

src/api/endpoints.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@ export const Api = Object.freeze({
229229

230230
UTILITIES_CODE_RUN:
231231
'/utilities/code/run',
232-
UTILITIES_CODE_RUN2:
233-
'/utilities/code/run2',
232+
UTILITIES_CODE_RUN_GOCODEIT:
233+
'/utilities/code/run/gocodeit',
234+
UTILITIES_CODE_RUN_REXTESTER:
235+
'/utilities/code/run/rextester',
234236
UTILITIES_FETCH_DATA:
235237
'/utilities/fetch/data',
236238
UTILITIES_FETCH_IMAGE:
@@ -239,6 +241,8 @@ export const Api = Object.freeze({
239241
'/utilities/fetch/media',
240242
UTILITIES_FETCH_TEXT:
241243
'/utilities/fetch/text',
244+
UTILITIES_IMAGESCRIPT_V1:
245+
'/utilities/imagescript/v1',
242246
UTILITIES_QR_CREATE:
243247
'/utilities/qr/create',
244248
UTILITIES_QR_SCAN:

src/api/index.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -976,11 +976,18 @@ export async function uploadCommands(
976976
}
977977

978978

979-
export async function utilitiesCodeRun2(
979+
export async function utilitiesCodeRun(
980980
context: RequestContext,
981-
options: RestOptions.UtilitiesCodeRun2,
981+
options: RestOptions.UtilitiesCodeRun,
982982
) {
983-
return raw.utilitiesCodeRun2(context, options);
983+
return raw.utilitiesCodeRun(context, options);
984+
}
985+
986+
export async function utilitiesCodeRunRextester(
987+
context: RequestContext,
988+
options: RestOptions.UtilitiesCodeRunRextester,
989+
) {
990+
return raw.utilitiesCodeRunRextester(context, options);
984991
}
985992

986993
export async function utilitiesFetchData(
@@ -1013,6 +1020,14 @@ export async function utilitiesFetchText(
10131020
}
10141021

10151022

1023+
export async function utilitiesImagescriptV1(
1024+
context: RequestContext,
1025+
options: RestOptions.UtilitiesImagescriptV1,
1026+
) {
1027+
return raw.utilitiesImagescriptV1(context, options);
1028+
}
1029+
1030+
10161031
export async function utilitiesQrCreate(
10171032
context: RequestContext,
10181033
options: RestOptions.UtilitiesQrCreate,

src/api/raw.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,10 +2014,10 @@ export async function uploadCommands(
20142014
}
20152015

20162016

2017-
export async function utilitiesCodeRun2(
2017+
export async function utilitiesCodeRun(
20182018
context: RequestContext,
2019-
options: RestOptions.UtilitiesCodeRun2,
2020-
): Promise<RestResponsesRaw.UtilitiesCodeRun2> {
2019+
options: RestOptions.UtilitiesCodeRun,
2020+
): Promise<RestResponsesRaw.UtilitiesCodeRun> {
20212021
const body = {
20222022
code: options.code,
20232023
input: options.input,
@@ -2027,7 +2027,26 @@ export async function utilitiesCodeRun2(
20272027
body,
20282028
route: {
20292029
method: HTTPMethods.POST,
2030-
path: Api.UTILITIES_CODE_RUN2,
2030+
path: Api.UTILITIES_CODE_RUN,
2031+
},
2032+
});
2033+
}
2034+
2035+
2036+
export async function utilitiesCodeRunRextester(
2037+
context: RequestContext,
2038+
options: RestOptions.UtilitiesCodeRunRextester,
2039+
): Promise<RestResponsesRaw.UtilitiesCodeRunRextester> {
2040+
const body = {
2041+
code: options.code,
2042+
input: options.input,
2043+
language: options.language,
2044+
};
2045+
return request(context, {
2046+
body,
2047+
route: {
2048+
method: HTTPMethods.POST,
2049+
path: Api.UTILITIES_CODE_RUN_REXTESTER,
20312050
},
20322051
});
20332052
}
@@ -2109,6 +2128,24 @@ export async function utilitiesFetchText(
21092128
}
21102129

21112130

2131+
export async function utilitiesImagescriptV1(
2132+
context: RequestContext,
2133+
options: RestOptions.UtilitiesImagescriptV1,
2134+
): Promise<Response> {
2135+
const body = {
2136+
code: options.code,
2137+
};
2138+
return request(context, {
2139+
dataOnly: false,
2140+
body,
2141+
route: {
2142+
method: HTTPMethods.POST,
2143+
path: Api.UTILITIES_IMAGESCRIPT_V1,
2144+
},
2145+
});
2146+
}
2147+
2148+
21122149
export async function utilitiesQrCreate(
21132150
context: RequestContext,
21142151
options: RestOptions.UtilitiesQrCreate,

src/api/types.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,13 @@ export namespace RestOptions {
391391
}
392392

393393

394-
export interface UtilitiesCodeRun2 {
394+
export interface UtilitiesCodeRun {
395+
code: string,
396+
input?: string,
397+
language: string,
398+
}
399+
400+
export interface UtilitiesCodeRunRextester {
395401
code: string,
396402
input?: string,
397403
language: string,
@@ -417,6 +423,10 @@ export namespace RestOptions {
417423
url: string,
418424
}
419425

426+
export interface UtilitiesImagescriptV1 {
427+
code: string,
428+
}
429+
420430
export interface UtilitiesQrCreate {
421431
margin?: number,
422432
query: string,
@@ -1256,9 +1266,23 @@ export namespace RestResponsesRaw {
12561266
type: YoutubeResultTypes.VIDEO,
12571267
}
12581268

1259-
export interface UtilitiesCodeRun2 {
1269+
export interface UtilitiesCodeRun {
1270+
content: string,
1271+
error: string,
1272+
files: Array<string>,
1273+
stats: {
1274+
memory: string,
1275+
time_compilation: number,
1276+
time_cpu: number,
1277+
time_running: number,
1278+
time_service: number,
1279+
},
1280+
warnings: string | null,
1281+
}
1282+
1283+
export interface UtilitiesCodeRunRextester {
12601284
content: string,
1261-
error: string | null,
1285+
error: string,
12621286
files: Array<string>,
12631287
stats: {
12641288
memory: string,

src/commands/prefixed/tools/code.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Command, CommandClient } from 'detritus-client';
22

33
import { CommandTypes } from '../../../constants';
4-
import { Formatter, Parameters, editOrReply, getCodeRextesterLanguage } from '../../../utils';
4+
import { Formatter, Parameters, editOrReply, getCodeLanguage } from '../../../utils';
55

66
import { BaseCommand } from '../basecommand';
77

@@ -41,7 +41,7 @@ export default class CodeCommand extends BaseCommand<CommandArgs> {
4141
}
4242

4343
async run(context: Command.Context, args: CommandArgs) {
44-
const language = getCodeRextesterLanguage(args.code.language || args.language);
44+
const language = getCodeLanguage(args.code.language || args.language);
4545
if (!language) {
4646
return editOrReply(context, 'Give me a valid language!');
4747
}

src/constants.ts

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,105 @@ export enum BooleanEmojis {
2222
};
2323

2424

25+
export enum CodeLanguages {
26+
ADA = 'ADA',
27+
ASSEMBLY = 'ASSEMBLY',
28+
BASH = 'BASH',
29+
BRAINFUCK = 'BRAINFUCK',
30+
C = 'C',
31+
CLOJURE = 'CLOJURE',
32+
C_CLANG = 'C_CLANG',
33+
C_OBJECTIVE = 'C_OBJECTIVE',
34+
C_PLUS_PLUS = 'C_PLUS_PLUS',
35+
C_PLUS_PLUS_CLANG = 'C_PLUS_PLUS_CLANG',
36+
C_PLUS_PLUS_VC_PLUS_PLUS = 'C_PLUS_PLUS_VC_PLUS_PLUS',
37+
C_SHARP = 'C_SHARP',
38+
C_VC = 'C_VC',
39+
D = 'D',
40+
DART = 'DART',
41+
ELIXIR = 'ELIXIR',
42+
ERLANG = 'ERLANG',
43+
FORTRAN = 'FORTRAN',
44+
F_SHARP = 'F_SHARP',
45+
GO = 'GO',
46+
HASKELL = 'HASKELL',
47+
HAXE = 'HAXE',
48+
JAVA = 'JAVA',
49+
JAVASCRIPT = 'JAVASCRIPT',
50+
KOTLIN = 'KOTLIN',
51+
LISP = 'LISP',
52+
LUA = 'LUA',
53+
OCAML = 'OCAML',
54+
OCTAVE = 'OCTAVE',
55+
ORACLE = 'ORACLE',
56+
PASCAL = 'PASCAL',
57+
PERL = 'PERL',
58+
PHP = 'PHP',
59+
PROLOG = 'PROLOG',
60+
PYTHON_2 = 'PYTHON_2',
61+
PYTHON_3 = 'PYTHON_3',
62+
R = 'R',
63+
RUBY = 'RUBY',
64+
RUST = 'RUST',
65+
SCALA = 'SCALA',
66+
SWIFT = 'SWIFT',
67+
TCL = 'TCL',
68+
TYPESCRIPT = 'TYPESCRIPT',
69+
VB_NET = 'VB_NET',
70+
}
71+
72+
export const CodeLanguagesToName = Object.freeze({
73+
[CodeLanguages.ADA]: ['ada'],
74+
[CodeLanguages.ASSEMBLY]: ['assembly', 'asm', 'nasm'],
75+
[CodeLanguages.BASH]: ['bash'],
76+
[CodeLanguages.BRAINFUCK]: ['brainfuck', 'bf'],
77+
[CodeLanguages.C]: ['c(gcc)', 'c'],
78+
[CodeLanguages.C_CLANG]: ['c(clang)'],
79+
[CodeLanguages.C_OBJECTIVE]: ['objective-c', 'oc', 'obj-c'],
80+
[CodeLanguages.C_PLUS_PLUS]: ['c++(gcc)', 'c++', 'cpp'],
81+
[CodeLanguages.C_PLUS_PLUS_CLANG]: ['c++(clang)'],
82+
[CodeLanguages.C_PLUS_PLUS_VC_PLUS_PLUS]: ['c++(vc++)'],
83+
[CodeLanguages.C_SHARP]: ['c#'],
84+
[CodeLanguages.C_VC]: ['c(vc)'],
85+
[CodeLanguages.CLOJURE]: ['clojure'],
86+
[CodeLanguages.D]: ['d'],
87+
[CodeLanguages.DART]: ['dart'],
88+
[CodeLanguages.ELIXIR]: ['elixir', 'ex'],
89+
[CodeLanguages.ERLANG]: ['erlang'],
90+
[CodeLanguages.F_SHARP]: ['f#'],
91+
[CodeLanguages.FORTRAN]: ['fortran', 'fort'],
92+
[CodeLanguages.GO]: ['go'],
93+
[CodeLanguages.HAXE]: ['haxe'],
94+
[CodeLanguages.HASKELL]: ['haskell', 'hs'],
95+
[CodeLanguages.JAVA]: ['java'],
96+
[CodeLanguages.JAVASCRIPT]: ['javascript', 'js', 'node.js', 'node'],
97+
[CodeLanguages.KOTLIN]: ['kotlin', 'kot'],
98+
[CodeLanguages.LISP]: ['commonlisp', 'lisp'],
99+
[CodeLanguages.LUA]: ['lua'],
100+
//[CodeLanguages.MYSQL]: ['mysql'],
101+
[CodeLanguages.OCAML]: ['ocaml'],
102+
[CodeLanguages.OCTAVE]: ['octave'],
103+
[CodeLanguages.ORACLE]: ['oracle'],
104+
[CodeLanguages.PASCAL]: ['pascal'],
105+
[CodeLanguages.PERL]: ['perl'],
106+
[CodeLanguages.PHP]: ['php', 'php7'],
107+
//[CodeLanguages.POSTGRES_SQL]: ['postgresql', 'psql', 'postgres'],
108+
[CodeLanguages.PROLOG]: ['prolog'],
109+
[CodeLanguages.PYTHON_2]: ['python2', 'python2.7', 'py2.7', 'py2'],
110+
[CodeLanguages.PYTHON_3]: ['python', 'python3', 'py', 'py3'],
111+
[CodeLanguages.R]: ['r'],
112+
[CodeLanguages.RUBY]: ['ruby', 'rb'],
113+
[CodeLanguages.RUST]: ['rust', 'rs'],
114+
[CodeLanguages.SCALA]: ['scala'],
115+
//[CodeLanguages.SCHEME]: ['scheme'],
116+
//[CodeLanguages.SQL_SERVER]: ['sqlserver'],
117+
[CodeLanguages.SWIFT]: ['swift'],
118+
[CodeLanguages.TCL]: ['tcl'],
119+
[CodeLanguages.TYPESCRIPT]: ['typescript', 'ts'],
120+
[CodeLanguages.VB_NET]: ['visualbasic', 'vb'],
121+
});
122+
123+
25124
export enum CodeRextesterLanguages {
26125
ADA = 'ADA',
27126
ASSEMBLY = 'ASSEMBLY',
@@ -111,7 +210,6 @@ export const CodeRextesterLanguagesToName = Object.freeze({
111210
//[CodeRextesterLanguages.SQL_SERVER]: ['sqlserver'],
112211
[CodeRextesterLanguages.SWIFT]: ['swift'],
113212
[CodeRextesterLanguages.TCL]: ['tcl'],
114-
[CodeRextesterLanguages.LUA]: ['lua'],
115213
[CodeRextesterLanguages.VB_NET]: ['visualbasic', 'vb'],
116214
});
117215

src/utils/formatter/commands/tools.code.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Command, Interaction } from 'detritus-client';
22
import { MessageFlags } from 'detritus-client/lib/constants';
33
import { Embed, Markup } from 'detritus-client/lib/utils';
44

5-
import { utilitiesCodeRun2 } from '../../../api';
5+
import { utilitiesCodeRun } from '../../../api';
66
import {
77
EmbedBrands,
88
EmbedColors,
@@ -30,7 +30,7 @@ export async function createMessage(
3030
guild.presences = [];
3131
guild.voice_states = [];
3232
}
33-
const { content, error, stats } = await utilitiesCodeRun2(context, {
33+
const { content, error, stats } = await utilitiesCodeRun(context, {
3434
code: args.code,
3535
input: JSON.stringify({
3636
channel: context.channel,

0 commit comments

Comments
 (0)