-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
186 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.json | ||
*.yml | ||
.prettierrc | ||
*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { CocoaSlash } from "cocoa-discord-utils/slash"; | ||
import { SlashCommandBuilder } from "@discordjs/builders"; | ||
|
||
export const aboutme: CocoaSlash = { | ||
command: new SlashCommandBuilder() | ||
.setName("aboutme") | ||
.setDescription("Get Info about me!") | ||
.toJSON(), | ||
func: async (ctx) => { | ||
await ctx.reply( | ||
`I am Cocoa Grader! Who will carefully grade your code! 💖💖\nVersion: ${process.env.npm_package_version}` | ||
); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import { Cog } from "cocoa-discord-utils/slash"; | ||
|
||
import { aboutme } from "./aboutme"; | ||
import { getstatement } from "./getstatement"; | ||
|
||
export const Cocoa: Cog = { | ||
name: "Cocoa", | ||
commands: { | ||
aboutme, | ||
getstatement, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import chalk from "chalk"; | ||
import { writeFile } from "fs/promises"; | ||
import { exec } from "./grader"; | ||
|
||
export type SupportedLang = "C" | "C++" | "Python"; | ||
|
||
export function getLang(str: string): SupportedLang | "Unsupported" { | ||
if (str == "cpp" || str == "c++" || str == "cc") return "C++"; | ||
if (str == "c") return "C"; | ||
if (str.startsWith("py")) return "Python"; | ||
return "Unsupported"; | ||
} | ||
|
||
const extensions = { | ||
C: "c", | ||
"C++": "cpp", | ||
Python: "py", | ||
}; | ||
|
||
export async function Compile( | ||
lang: SupportedLang, | ||
content: string, | ||
id: string | ||
): Promise<boolean> { | ||
try { | ||
await writeFile(`temp/${id}.${extensions[lang]}`, content); | ||
} catch (error) { | ||
console.log(chalk.red(`ERROR while writing file: ${error}`)); | ||
return false; | ||
} | ||
|
||
try { | ||
switch (lang) { | ||
case "C": | ||
await exec(`gcc temp/${id}.c -o temp/${id} -std=c17 -O2 -lm`); | ||
break; | ||
case "C++": | ||
await exec( | ||
`g++ temp/${id}.cpp -o temp/${id} -std=c++17 -O2 -lm` | ||
); | ||
break; | ||
case "Python": | ||
// Do Nothing Lmao | ||
break; | ||
} | ||
} catch (error) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
export function getECmd(lang: string, id: string) { | ||
if (lang == "Python") return `python3 ./temp/${id}.py`; | ||
return `./temp/${id}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { CaseVerdict, VerdictDict } from "./grader"; | ||
|
||
export function shortenVerdicts(verdicts: CaseVerdict[]): string { | ||
const verdictsShort = verdicts.map((verdict) => VerdictDict[verdict]); | ||
return verdictsShort.join(""); | ||
} |