Toggle navigation
Toggle navigation
This project
Loading...
Sign in
최현준
/
도와줘요 채팅맨
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
1
Network
Create a new issue
Commits
Issue Boards
Authored by
최현준
2020-06-14 22:32:06 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
33d54b37778687f02188d637e1e31885d7d9c793
33d54b37
1 parent
88d8b67e
개인별 기상 정보 저장 및 기상 정보 번역 제공
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
22 deletions
app.js
app.js
View file @
33d54b3
...
...
@@ -14,20 +14,26 @@ var async = require('async');
const
{
resolve
}
=
require
(
'path'
);
var
Language_Detect_Array
=
new
Array
();
var
User_Info_Array
=
new
Array
();
var
Weahter_
Info
_Array
=
new
Array
();
var
Weahter_
Detect
_Array
=
new
Array
();
Weahter_
Info
_Array
[
0
]
=
Weahter_
Detect
_Array
[
0
]
=
{
"
Locat
ion"
:
'수원'
,
"
Reg
ion"
:
'수원'
,
"nx"
:
61
,
"ny"
:
120
}
Weahter_
Info
_Array
[
1
]
=
Weahter_
Detect
_Array
[
1
]
=
{
"
Locat
ion"
:
'서울'
,
"
Reg
ion"
:
'서울'
,
"nx"
:
60
,
"ny"
:
127
}
Weahter_Detect_Array
[
2
]
=
{
"Region"
:
'밀양'
,
"nx"
:
92
,
"ny"
:
83
}
Language_Detect_Array
[
0
]
=
{
...
...
@@ -53,7 +59,8 @@ Language_Detect_Array[3] =
User_Info_Array
[
0
]
=
{
UserId
:
null
,
UserPapagoLanguage
:
''
UserPapagoLanguage
:
''
,
UserRegion
:
'수원'
,
}
app
.
use
(
bodyParser
.
json
());
...
...
@@ -64,7 +71,7 @@ app.post('/hook', function (req, res) {
var
replyToken
=
eventObj
.
replyToken
;
var
userid
=
eventObj
.
source
.
userId
;
if
(
message
==
'날씨'
)
weathercheck
(
replyToken
);
else
AsyncFunction
(
message
,
replyToken
,
userid
);
AsyncFunction
(
message
,
replyToken
,
userid
);
res
.
sendStatus
(
200
);
});
...
...
@@ -74,18 +81,29 @@ async function AsyncFunction(message, replyToken, userid)
var
User_Location
=
search_user_info
(
userid
);
var
DetectLanguage
=
await
detector
(
message
);
if
(
DetectLanguage
!=
'ko'
)
var
TransToKoreanMessage
=
await
trans
(
DetectLanguage
,
message
,
'ko'
);
else
var
TransToKoreanMessage
=
message
;
var
DetectLanguageChange
=
Detect_Papago_Language_Change
(
TransToKoreanMessage
,
User_Location
);
console
.
log
(
TransToKoreanMessage
);
var
DetectChange
=
Detect_Papago_Language_Change
(
TransToKoreanMessage
,
User_Location
);
if
(
DetectChange
)
DetectChange
=
Detect_Weather_Region_Change
(
TransToKoreanMessage
,
User_Location
);
if
(
TransToKoreanMessage
!=
'날씨'
)
{
if
(
DetectLanguage
!=
User_Info_Array
[
User_Location
].
UserPapagoLanguage
)
var
TransToUserSettingMessage
=
await
trans
(
DetectLanguage
,
message
,
User_Info_Array
[
User_Location
].
UserPapagoLanguage
);
var
Messaging
=
await
messaging
(
TransToUserSettingMessage
,
replyToken
,
Detect
Language
Change
);
var
Messaging
=
await
messaging
(
TransToUserSettingMessage
,
replyToken
,
DetectChange
);
console
.
log
(
"log-Message: "
,
Messaging
);
}
else
weathercheck
(
replyToken
,
userid
,
DetectLanguage
);
}
async
function
weathercheck
(
replyToken
)
async
function
weathercheck
(
replyToken
,
userid
,
DetectLanguage
)
{
var
User_Location
=
search_user_info
(
userid
);
var
location
=
user_location
(
User_Location
);
var
timevalue
=
make_time
()
var
url
=
make_url
(
timevalue
)
var
persentofweawther
=
await
weather_get
(
url
);
var
Messaging
=
await
messaging
(
persentofweawther
,
replyToken
,
1
);
var
url
=
make_url
(
timevalue
,
location
);
var
message
=
await
weather_get
(
url
,
User_Location
);
if
(
DetectLanguage
!=
'ko'
)
message
=
await
trans
(
'ko'
,
message
,
DetectLanguage
)
var
Messaging
=
await
messaging
(
message
,
replyToken
,
1
);
console
.
log
(
"log-Message: "
,
Messaging
);
}
...
...
@@ -122,12 +140,12 @@ function detector (message)
})
}
function
messaging
(
message
,
replyToken
,
Detect
Language
Change
)
function
messaging
(
message
,
replyToken
,
DetectChange
)
//메시지 보내기
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
if
(
Detect
Language
Change
)
if
(
DetectChange
)
request
.
post
(
{
...
...
@@ -203,7 +221,8 @@ function search_user_info (userid)
User_Info_Array
[
User_Info_Array
.
length
]
=
{
UserId
:
userid
,
UserPapagoLanguage
:
'en'
UserPapagoLanguage
:
'en'
,
UserRegion
:
'수원'
}
return
User_Info_Array
.
length
-
1
;
}
...
...
@@ -213,7 +232,6 @@ function search_user_info (userid)
function
Detect_Papago_Language_Change
(
TransToKoreanMessage
,
User_Location
)
//번역 언어 변경 감지
{
console
.
log
(
'user의 정보는'
,
User_Info_Array
[
User_Location
]);
for
(
var
i
in
Language_Detect_Array
)
// Detect Language change
{
if
(
TransToKoreanMessage
==
Language_Detect_Array
[
i
].
Message
)
...
...
@@ -221,6 +239,7 @@ function Detect_Papago_Language_Change (TransToKoreanMessage, User_Location)
//언어 변경 감지o
User_Info_Array
[
User_Location
].
UserPapagoLanguage
=
Language_Detect_Array
[
i
].
PapagoLanguage
;
return
0
;
break
;
}
else
if
(
i
==
Language_Detect_Array
.
length
-
1
)
...
...
@@ -231,6 +250,26 @@ function Detect_Papago_Language_Change (TransToKoreanMessage, User_Location)
}
}
function
Detect_Weather_Region_Change
(
TransToKoreanMessage
,
User_Location
)
//지역 변경 감지
{
for
(
var
i
in
Weahter_Detect_Array
)
{
if
(
TransToKoreanMessage
==
Weahter_Detect_Array
[
i
].
Region
)
{
//지역 변경 감지o
User_Info_Array
[
User_Location
].
UserRegion
=
Weahter_Detect_Array
[
i
].
Region
return
0
;
break
;
}
else
if
(
i
==
Weahter_Detect_Array
.
length
-
1
)
{
//지역 변경 감지x
return
1
;
}
}
}
function
make_time
()
{
var
today
=
new
Date
();
...
...
@@ -282,7 +321,7 @@ function make_time()
return
value
;
}
function
make_url
(
timevalue
)
function
make_url
(
timevalue
,
location
)
{
var
serviceKey
=
weather_key
;
var
pageNo
=
'1'
;
...
...
@@ -290,8 +329,8 @@ function make_url(timevalue)
var
dataType
=
'JSON'
;
var
base_date
=
timevalue
.
today
;
var
base_time
=
timevalue
.
hours
;
var
nx
=
'61'
;
var
ny
=
'120'
;
var
nx
=
location
.
nx
;
var
ny
=
location
.
ny
;
var
url
=
`
${
WEATHER_TARGET_URL
}
`
;
url
+=
'?serviceKey='
+
serviceKey
;
...
...
@@ -305,8 +344,23 @@ function make_url(timevalue)
return
url
;
}
function
user_location
(
User_Location
)
{
var
location_info
=
new
Object
();
for
(
var
i
in
Weahter_Detect_Array
)
{
if
(
User_Info_Array
[
User_Location
].
UserRegion
==
Weahter_Detect_Array
[
i
].
Region
)
{
location_info
.
nx
=
Weahter_Detect_Array
[
i
].
nx
;
location_info
.
ny
=
Weahter_Detect_Array
[
i
].
ny
;
return
location_info
;
break
;
}
}
}
function
weather_get
(
url
)
function
weather_get
(
url
,
User_Location
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
...
...
@@ -318,7 +372,7 @@ function weather_get (url)
if
(
!
error
&&
response
.
statusCode
==
200
)
{
var
weatherObj
=
JSON
.
parse
(
response
.
body
);
resolve
(
'4시간 안에 비가 올 확률은'
+
weatherObj
.
response
.
body
.
items
.
item
[
0
].
fcstValue
+
'%
입니다.'
);
resolve
(
User_Info_Array
[
User_Location
].
UserRegion
+
'에 4시간 안에 비가 올 확률은 '
+
weatherObj
.
response
.
body
.
items
.
item
[
0
].
fcstValue
+
'%
입니다.'
);
}
else
{
console
.
log
(
'Error'
,
error
);
...
...
Please
register
or
login
to post a comment