Skip to content

Commit 1257343

Browse files
committed
feat: feture4- findOffice
- add function findOffice, menu - refactor prettierrc, slackBot
1 parent 53cec9c commit 1257343

File tree

6 files changed

+86
-21
lines changed

6 files changed

+86
-21
lines changed

.prettierrc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"printWidth": 100,
3-
"tabWidth": 2,
4-
"semi": true,
5-
"singleQuote": true,
6-
"bracketSpacing": true,
7-
"arrowParens": "always"
8-
}
2+
"printWidth": 60,
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": true,
6+
"bracketSpacing": true,
7+
"arrowParens": "always"
8+
}

src/bot/bot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ class Bot {
3737
}
3838
}
3939

40-
module.exports.Bot = Bot;
40+
module.exports.Bot = Bot;

src/bot/slackBot.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ const square = require('../square');
33
const schedule = require('../schedule');
44
const menu = require('../menu');
55
const { Bot } = require('./bot');
6-
6+
const findOffice = require('../findOffice');
77

88
class SlackBot extends Bot {
9-
109
/** 멤버들의 id를 담을 hashset */
1110
#userHash = new Set();
1211

@@ -16,15 +15,17 @@ class SlackBot extends Bot {
1615
if (this.#userHash.has(event.user)) {
1716
return;
1817
}
19-
const stringFormat =
20-
` 안녕하세요? <@${event.user}>님\n
18+
const stringFormat = ` 안녕하세요? <@${event.user}>님\n
2119
아래 메시지를 입력하시면 응답 가능합니다.\n
2220
| hi\n
2321
| 학사일정\n
2422
| 오늘 밥 뭐야\n
2523
| (전공)학부 \n`;
2624
this.#userHash.add(event.user);
27-
await this.rtm.sendMessage(stringFormat, event.channel);
25+
await this.rtm.sendMessage(
26+
stringFormat,
27+
event.channel
28+
);
2829
});
2930
}
3031

@@ -65,26 +66,30 @@ class SlackBot extends Bot {
6566
break;
6667
case '오늘 밥 뭐야':
6768
// TODO: feature 3
68-
instruction = menu(this.rtm, new Date().getDay(), channel);
69-
break;
70-
case '*학부':
71-
// TODO: feature 4
69+
instruction = menu(
70+
this.rtm,
71+
new Date().getDay(),
72+
channel
73+
);
7274
break;
7375
default:
74-
instruction = 'undefined';
76+
instruction = findOffice(text);
77+
this.rtm.sendMessage(instruction, channel);
7578
break;
7679
}
77-
if (!Number.isNaN(Number(text))) resolve(square(this.rtm, text, channel));
80+
if (!Number.isNaN(Number(text)))
81+
resolve(square(this.rtm, text, channel));
7882
else if (instruction === 'undefined') reject();
7983
else resolve(instruction);
8084
});
8185
}
8286

8387
requestDate(channel) {
84-
const stringFormat = '| 안내 받을 날짜를 입력해주세요 \n' +
88+
const stringFormat =
89+
'| 안내 받을 날짜를 입력해주세요 \n' +
8590
'| 형식 : 월/일 (12/13)';
8691
return this.rtm.sendMessage(stringFormat, channel);
8792
}
8893
}
8994

90-
module.exports.SlackBot = SlackBot;
95+
module.exports.SlackBot = SlackBot;

src/findOffice.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const fs = require('fs');
2+
3+
const dataInput = fs
4+
.readFileSync('./rsc/data/dept.txt', 'utf-8')
5+
.toString()
6+
.split('\n');
7+
8+
/* 파일에서 학과의 사무실 위치 탐색 */
9+
function findOffice(department) {
10+
let office = 'undefined';
11+
let buffer = '';
12+
13+
/* 입력으로 들어온 학과의 사무실을 찾았을 경우 */
14+
dataInput.forEach((element) => {
15+
if (element.includes(department)) {
16+
buffer = element.split('-');
17+
office = buffer[1].trim();
18+
}
19+
});
20+
21+
return office;
22+
}
23+
24+
module.exports = findOffice;

src/menu.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const menu = (rtm, day, channel) => {
2+
if (day % 6 === 0) {
3+
return rtm.sendMessage('토/일요일은 제공되지 않습니다.', channel);
4+
}
5+
// TODO: 메뉴 데이터 가져오기 및 평점 보내기
6+
return null;
7+
};
8+
9+
module.exports = menu;

test/findOfficeTest.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const { assert } = require('chai');
2+
const findOffice = require('../src/findOffice');
3+
4+
/* 학과의 사무실 주소정보 매핑되어 있는 map */
5+
const locationInfo = [
6+
{ department: 'Architectural Engineering', office: 'College of Engineering Building 1, 132' },
7+
{ department: 'Mechanical Engineering', office: 'College of Engineering Building 4, 212' },
8+
{ department: 'Urban Engineering', office: 'College of Engineering Building 9, 917' },
9+
{ department: 'Electronic Engineering', office: 'College of Engineering Building 7, 224' },
10+
{
11+
department: 'Computer Science and Engineering',
12+
office: 'College of Engineering Building 7, 224',
13+
},
14+
{ department: 'Chemical Engineering', office: 'College of Engineering Building 6, 999' },
15+
{ department: 'Accounting', office: 'College of Commerce 2, 9999' },
16+
{ department: 'International Trade', office: 'College of Commerce 1, 9999' },
17+
{ department: 'Korean Language and Literature', office: 'College of Humanities, 320' },
18+
{ department: 'Library and Information Science', office: 'College of Humanities, 427' },
19+
];
20+
21+
describe('학과 사무실 찾기 테스트', () => {
22+
it('sayOffice should return departmentOffice', () => {
23+
locationInfo.forEach((element) => {
24+
assert.equal(findOffice(element.department), element.office);
25+
});
26+
});
27+
});

0 commit comments

Comments
 (0)