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-02 02:41:18 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
72d6c969660fc684001445c3a808ee5595d7ef7d
72d6c969
1 parent
5b103ab9
code err detection
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
33 deletions
Routers/route.js
joke_data/jokes.json
Routers/route.js
View file @
72d6c96
...
...
@@ -7,8 +7,8 @@ const url = 'mongodb://localhost:27017/';
exports
.
startbot
=
()
=>
{
// Get authorization to use the slackbot
const
bot
=
new
SlackBot
({
token
:
"xoxb-6
51692943605-645515979745-sfNJBLVbIIb86Bz1gfFc7oT2
"
,
name
:
"joke
r
"
token
:
"xoxb-6
35297512738-635283536771-A03RoBh4Dv8qG1EiLudMpk1f
"
,
name
:
"joke
bot
"
});
// Start the slackbot
...
...
@@ -135,10 +135,8 @@ function MakeJoke(message){
})
}
//Gets a random integer
function
getRandomInt
(
max_num
)
{
min
=
Math
.
ceil
(
1
);
max
=
Math
.
floor
(
max_num
);
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
+
1
))
+
min
;
function
getRandomInt
(
start
,
end
)
{
return
Math
.
floor
((
Math
.
random
()
*
100
)
%
(
end
-
start
))
+
start
;
}
//Function for giving out random joke
...
...
@@ -184,23 +182,15 @@ generalJoke= (user_channel)=>{
if
(
err
)
throw
err
;
var
db
=
client
.
db
(
'jokeapi'
);
json_max
=
376
;
random
=
getRandomInt
(
json_max
);
random
=
getRandomInt
(
24
,
377
);
result
=
db
.
collection
(
'jokes'
).
findOne
({
id
:
random
});
user
=
result
;
//if the random picked api type is not general execute the function from the start to get another format for general type
user
.
then
(
function
(
total
){
if
(
total
.
type
===
"general"
){
question
=
total
.
setup
;
joke
=
total
.
punchline
;
ques_and_joke
=
[
question
,
joke
];
return
ques_and_joke
;
}
else
if
(
total
.
type
!=
"general"
){
client
.
close
();
generalJoke
(
user_channel
);
}
})
.
then
((
joke_info
)
=>
{
bot
.
postMessageToChannel
(
user_channel
,
joke_info
[
0
],
emoji
.
emojis
(
'laughing'
));
...
...
@@ -223,22 +213,14 @@ programmingJoke= (user_channel)=>{
if
(
err
)
throw
err
;
var
db
=
client
.
db
(
'jokeapi'
);
json_max
=
376
;
random
=
getRandomInt
(
json_max
);
random
=
getRandomInt
(
0
,
19
);
result
=
db
.
collection
(
'jokes'
).
findOne
({
id
:
random
});
user
=
result
;
user
.
then
(
function
(
total
){
if
(
total
.
type
===
"programming"
){
question
=
total
.
setup
;
joke
=
total
.
punchline
;
ques_and_joke
=
[
question
,
joke
];
return
ques_and_joke
;
}
else
if
(
total
.
type
!=
"programming"
){
client
.
close
();
programmingJoke
(
user_channel
);
}
})
.
then
((
joke_info
)
=>
{
bot
.
postMessageToChannel
(
user_channel
,
joke_info
[
0
],
emoji
.
emojis
(
'laughing'
));
...
...
@@ -316,23 +298,15 @@ knockknockJoke= (user_channel)=>{
MongoClient
.
connect
(
url
,
function
(
err
,
client
){
if
(
err
)
throw
err
;
var
db
=
client
.
db
(
'jokeapi'
);
json_max
=
61
;
random
=
getRandomInt
(
json_max
);
random
=
getRandomInt
(
19
,
24
);
result
=
db
.
collection
(
'jokes'
).
findOne
({
id
:
random
});
user
=
result
;
user
.
then
(
function
(
total
){
if
(
total
.
type
===
"knock-knock"
){
question
=
total
.
setup
;
joke
=
total
.
punchline
;
ques_and_joke
=
[
question
,
joke
];
return
ques_and_joke
;
}
else
if
(
total
.
type
!=
"knock-knock"
){
client
.
close
();
knockknockJoke
(
user_channel
);
}
})
.
then
((
joke_info
)
=>
{
bot
.
postMessageToChannel
(
user_channel
,
joke_info
[
0
],
emoji
.
emojis
(
'laughing'
));
...
...
joke_data/jokes.json
View file @
72d6c96
This diff is collapsed. Click to expand it.
Please
register
or
login
to post a comment