Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김민욱
/
Slack Jokebot
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
오원석
2019-06-06 20:36:36 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a79ebdc593c66a94a905eaff92591554a3073e71
a79ebdc5
1 parent
e05ce66f
random print userjoke
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
25 deletions
Routers/route.js
joke_data/user.json
Routers/route.js
View file @
a79ebdc
...
...
@@ -6,6 +6,7 @@ const url = 'mongodb://13.124.65.242:27017/';
const
url2
=
'mongodb://13.124.65.242:27017/userdb'
;
const
fs
=
require
(
'fs'
);
message_recieved
=
0
;
ary_size
=
0
;
exports
.
startbot
=
()
=>
{
// Get authorization to use the slackbot
...
...
@@ -174,13 +175,13 @@ function MakeJoke(message,user_channel){
});
})
//
var json=JSON.stringify(obj);
//
fs.writeFile(path,json,'utf8',function(err){
//
if(err){
//
console.log(err);
//
}
//
console.log('완료');
//
});
var
json
=
JSON
.
stringify
(
obj
);
fs
.
writeFile
(
path
,
json
,
'utf8'
,
function
(
err
){
if
(
err
){
console
.
log
(
err
);
}
console
.
log
(
'완료'
);
});
}
});
comment
=
"Sucess making joke!!:+1::thumbsup:\nWhen you want to show your joke, please enter @jokebot tell-me-userjoke"
;
...
...
@@ -267,35 +268,63 @@ UserMakeJoke= (message,user_channel)=>{
if
(
err
)
throw
err
;
//go into database name jokeapi
var
db
=
client
.
db
(
'userdb'
);
ary_size
=
0
;
var
array
=
db
.
collection
(
'user'
).
find
({
type
:
user
}).
toArray
(
function
(
err
,
docs
){
if
(
err
){
callback
(
err
,
null
);
return
;
return
;
}
ary_size
=
docs
.
length
;
console
.
log
(
docs
.
length
);
});
var
random
=
getRandomInt
(
1
,
ary_size
+
1
);
console
.
log
(
random
);
var
result
=
docs
[
random
-
1
];
user
=
result
;
console
.
log
(
user
);
// var random=getRandomInt(1,ar+1);
//console.log(array.);
var
result
=
db
.
collection
(
'user'
).
findOne
({
type
:
user
,
id
:
random
});
user
=
result
;
//After finding one joke, use promise to run codes synchronously
user
.
then
(
function
(
total
){
question
=
total
.
setup
;
question
=
user
.
setup
;
joke
=
user
.
punchline
;
bot
.
postMessageToChannel
(
user_channel
,
question
,
emoji
.
emojis
(
'laughing'
));
console
.
log
(
"질문 불려짐"
);
return
total
;
})
.
then
((
all
)
=>
{
joke
=
all
.
punchline
;
//Use setTimeout function to delay the code execution, making sure the user reads the question first and then see the final funny joke
setTimeout
(
function
secondFunction
(){
setTimeout
(
function
secondFunction
(){
bot
.
postMessageToChannel
(
user_channel
,
`
${
joke
}
:stuck_out_tongue_winking_eye::laughing:`
,
emoji
.
emojis
(
'laughing'
));
console
.
log
(
"허무개그 전송~~~~~~!"
);
},
3000
);
})
// //After finding one joke, use promise to run codes synchronously
// user.then(function(total){
// question = total.setup;
// bot.postMessageToChannel(user_channel, question, emoji.emojis('laughing'));
// console.log("질문 불려짐");
// return total;
// })
// .then((all)=>{
// joke=all.punchline;
// //Use setTimeout function to delay the code execution, making sure the user reads the question first and then see the final funny joke
// setTimeout(function secondFunction(){
// bot.postMessageToChannel(user_channel,`${joke}:stuck_out_tongue_winking_eye::laughing:`,emoji.emojis('laughing'));
// console.log("허무개그 전송~~~~~~!");
// },3000);
// })
});
//var random=getRandomInt(1,ary_size+1);
// console.log(ary_size);
// var result=db.collection('user').findOne({type : user ,id : random});
// user = result;
// //After finding one joke, use promise to run codes synchronously
// user.then(function(total){
// question = total.setup;
// bot.postMessageToChannel(user_channel, question, emoji.emojis('laughing'));
// console.log("질문 불려짐");
// return total;
// })
// .then((all)=>{
// joke=all.punchline;
// //Use setTimeout function to delay the code execution, making sure the user reads the question first and then see the final funny joke
// setTimeout(function secondFunction(){
// bot.postMessageToChannel(user_channel,`${joke}:stuck_out_tongue_winking_eye::laughing:`,emoji.emojis('laughing'));
// console.log("허무개그 전송~~~~~~!");
// },3000);
// })
//close mongodb
client
.
close
();
})
...
...
joke_data/user.json
View file @
a79ebdc
{
"table"
:[{
"id"
:
1
,
"type"
:
"UJZF5UTMX"
,
"setup"
:
" ok"
,
"punchline"
:
" okkk"
},{
"id"
:
2
,
"type"
:
"UJZF5UTMX"
,
"setup"
:
" man"
,
"punchline"
:
" woman"
},{
"id"
:
3
,
"type"
:
"UJZF5UTMX"
,
"setup"
:
" kim "
,
"punchline"
:
" minuk"
},{
"id"
:
4
,
"type"
:
"UH9RRHSTG"
,
"setup"
:
" 팔에 비빔면 뭍으면 빨리 닦아야됨 왜?"
,
"punchline"
:
" 팔도비빔면됨"
},{
"id"
:
5
,
"type"
:
"UH9RRHSTG"
,
"setup"
:
" 팔에 비빔소스 묻으면 빨리 닦아야함"
,
"punchline"
:
" 팔도비빔면되서"
},{
"id"
:
6
,
"type"
:
"UH9RRHSTG"
,
"setup"
:
" check"
,
"punchline"
:
" working"
},{
"id"
:
7
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" minuk"
},{
"id"
:
8
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" yeonjun"
},{
"id"
:
9
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" hi"
,
"punchline"
:
" hello"
},{
"id"
:
10
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" hello"
,
"punchline"
:
" hi"
},{
"id"
:
11
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" bye"
,
"punchline"
:
" bi"
},{
"id"
:
12
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kkkkk"
,
"punchline"
:
" jjjjj"
},{
"id"
:
13
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
"wonserk"
},{
"id"
:
14
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
15
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
16
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" minuk"
},{
"id"
:
17
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" yeonjun"
},{
"id"
:
18
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
19
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
20
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
21
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" minuk"
},{
"id"
:
22
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
"yeonjun"
},{
"id"
:
23
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
24
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" minuk"
},{
"id"
:
25
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" yeonjun"
},{
"id"
:
26
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
27
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
28
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
}]}
\ No newline at end of file
{
"table"
:[{
"id"
:
1
,
"type"
:
"UJZF5UTMX"
,
"setup"
:
" ok"
,
"punchline"
:
" okkk"
},{
"id"
:
2
,
"type"
:
"UJZF5UTMX"
,
"setup"
:
" man"
,
"punchline"
:
" woman"
},{
"id"
:
3
,
"type"
:
"UJZF5UTMX"
,
"setup"
:
" kim "
,
"punchline"
:
" minuk"
},{
"id"
:
4
,
"type"
:
"UH9RRHSTG"
,
"setup"
:
" 팔에 비빔면 뭍으면 빨리 닦아야됨 왜?"
,
"punchline"
:
" 팔도비빔면됨"
},{
"id"
:
5
,
"type"
:
"UH9RRHSTG"
,
"setup"
:
" 팔에 비빔소스 묻으면 빨리 닦아야함"
,
"punchline"
:
" 팔도비빔면되서"
},{
"id"
:
6
,
"type"
:
"UH9RRHSTG"
,
"setup"
:
" check"
,
"punchline"
:
" working"
},{
"id"
:
7
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" minuk"
},{
"id"
:
8
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" yeonjun"
},{
"id"
:
9
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" hi"
,
"punchline"
:
" hello"
},{
"id"
:
10
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" hello"
,
"punchline"
:
" hi"
},{
"id"
:
11
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" bye"
,
"punchline"
:
" bi"
},{
"id"
:
12
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kkkkk"
,
"punchline"
:
" jjjjj"
},{
"id"
:
13
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
"wonserk"
},{
"id"
:
14
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
15
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
16
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" minuk"
},{
"id"
:
17
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" yeonjun"
},{
"id"
:
18
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
19
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
20
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
21
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" minuk"
},{
"id"
:
22
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
"yeonjun"
},{
"id"
:
23
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
24
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" minuk"
},{
"id"
:
25
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" yeonjun"
},{
"id"
:
26
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
27
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
28
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
29
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" oh"
,
"punchline"
:
" wonserk"
},{
"id"
:
30
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" minuk"
},{
"id"
:
31
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" kim"
,
"punchline"
:
" yeonjun"
},{
"id"
:
32
,
"type"
:
"UJP8BFSNP"
,
"setup"
:
" open"
,
"punchline"
:
" source"
}]}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment