Skip to content

Commit c2be676

Browse files
YeonSeong-LeeKKWANHmjy9088minjae9610
committed
INIT: az-gag prototype
Co-authored-by: kkim <KKWANH@users.noreply.github.com> Co-authored-by: Juyeong Maing <mjy9088@users.noreply.github.com> Co-authored-by: hjn966@naver.com <hjn966@naver.com>
1 parent c3373ca commit c2be676

5 files changed

Lines changed: 86 additions & 0 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "AZ-GAG-dataset"]
2+
path = AZ-GAG-dataset
3+
url = https://github.com/AZ-GAG/AZ-GAG-dataset.git

AZ-GAG-dataset

Submodule AZ-GAG-dataset added at f9e9154

index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import readline from 'readline'
2+
import getGag from './lib.js'
3+
4+
const rl = readline.createInterface({
5+
input: process.stdin,
6+
output: process.stdout,
7+
terminal: process.stdin.isTTY,
8+
});
9+
10+
let [question, answer] = getGag();
11+
let isWaiting = false;
12+
13+
process.stdout.write('\u001b[2J\u001b[0;0f');
14+
console.log(`질문: ${question}`);
15+
16+
rl.on('line', (line) => {
17+
if (isWaiting)
18+
return;
19+
console.log(`정답: ${answer}`);
20+
([question, answer] = getGag());
21+
isWaiting = true;
22+
setTimeout(() => {
23+
process.stdout.write('\u001b[2J\u001b[0;0f');
24+
console.log(`질문: ${question}`);
25+
isWaiting = false;
26+
}, 1000);
27+
});
28+
29+
rl.on('close', () => {
30+
console.log(`정답: ${answer}`);
31+
});

lib.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { readFileSync } from "fs";
2+
import assert from "assert";
3+
4+
/**
5+
* @type {[a: string, answer: string][]}
6+
*/
7+
const dataset = (() => {
8+
const question = readFileSync("./AZ-GAG-dataset/question.csv").toString().split("\n").filter((line) => line);
9+
const answer = readFileSync("./AZ-GAG-dataset/answer.csv").toString().split("\n").filter((line) => line);
10+
assert(question.length === answer.length);
11+
return question.map((_, i) => [question[i], answer[i]]);
12+
})();
13+
14+
/**
15+
* @returns {[question: string, answer: string]} random AZGag
16+
*/
17+
export default function AZGagGenerator() {
18+
return dataset[Math.floor(Math.random() * dataset.length)];
19+
};

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "az-generator",
3+
"organizations": "AZ-GAG",
4+
"version": "0.0.0",
5+
"description": "generates az-gag",
6+
"main": "index.js",
7+
"type": "module",
8+
"scripts": {
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/AZ-GAG/AZ-generator.git"
14+
},
15+
"keywords": [
16+
"az-gag",
17+
"comedy",
18+
"generator"
19+
],
20+
"author": "AZ-GAG",
21+
"contributors": [
22+
"Kwanho Kim <kwanho0096@gmail.com> (https://github.com/KKWANH)",
23+
"YeonSeong-Lee <yeonseong.dev@gmail.com> (https://github.com/YeonSeong-Lee)",
24+
"Minjae Kim <hjn966@naver.com> (https://github.com/minjae9610)",
25+
"Juyeong Maing <mjy9088@naver.com> (https://github.com/mjy9088)"
26+
],
27+
"license": "MIT",
28+
"bugs": {
29+
"url": "https://github.com/AZ-GAG/AZ-generator/issues"
30+
},
31+
"homepage": "https://github.com/AZ-GAG/AZ-generator#readme"
32+
}

0 commit comments

Comments
 (0)