Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김연준
/
TeamProject
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Authored by
김연준
2019-05-24 14:22:34 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e74d0761cf21b55d4932524a6879870158f1dc76
e74d0761
1 parent
a4d75cb5
Seperating functions file to Router folder and exporting to index.js
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
54 deletions
Routers/route.js
index.js
Routers/route.js
0 → 100644
View file @
e74d076
File mode changed
index.js
View file @
e74d076
const
SlackBot
=
require
(
'slackbots'
);
const
axios
=
require
(
'axios'
);
const
route
=
require
(
'./Routers/route'
);
const
bot
=
new
SlackBot
({
token
:
"xoxb-582582124755-587875604934-rRhFVlXlB0StEMnlrmsQlcac"
,
...
...
@@ -34,67 +35,32 @@ bot.on('message', (data) => {
// Responding to Data
function
handleMessage
(
message
){
if
(
message
.
includes
(
'chucknorris'
)){
chuckJoke
();
route
.
chuckJoke
()
.
then
((
err
,
res
)
=>
{
if
(
err
)
throw
err
;
res
(
"ChuckJoke function activated"
);
});
}
else
if
(
message
.
includes
(
' yomama'
)){
yoMamaJoke
();
route
.
yoMamaJoke
()
.
then
((
err
,
res
)
=>
{
if
(
err
)
throw
err
;
res
(
"yoMamaJoke function activated"
);
});
}
else
if
(
message
.
includes
(
' random'
)){
randomJoke
();
}
else
if
(
message
.
includes
(
' help'
)){
runHelp
();
}
}
// Tell a Chuck Norris Joke
function
chuckJoke
(){
axios
.
get
(
'http://api.icndb.com/jokes/random/'
)
.
then
(
res
=>
{
const
joke
=
res
.
data
.
value
.
joke
;
const
face
=
{
icon_emoji
:
':laughing:'
};
bot
.
postMessageToChannel
(
'everyone'
,
`Chuck Norris:
${
joke
}
`
,
face
);
bot
.
postMessageToChannel
(
'full-stack-web'
,
`Yo mama:
${
joke
}
`
,
face
);
bot
.
postMessageToChannel
(
'bot_test'
,
`Yo mama:
${
joke
}
`
,
face
);
route
.
randomJoke
()
.
then
((
err
,
res
)
=>
{
if
(
err
)
throw
err
res
(
"randomJoke function activated"
);
});
}
// Tell a yomama Joke
function
yoMamaJoke
(){
axios
.
get
(
'http://api.yomomma.info/'
)
.
then
(
res
=>
{
const
joke
=
res
.
data
.
joke
;
const
face
=
{
icon_emoji
:
':laughing:'
};
bot
.
postMessageToChannel
(
'everyone'
,
`Yo mama:
${
joke
}
`
,
face
);
bot
.
postMessageToChannel
(
'full-stack-web'
,
`Yo mama:
${
joke
}
`
,
face
);
bot
.
postMessageToChannel
(
'bot_test'
,
`Yo mama:
${
joke
}
`
,
face
);
else
if
(
message
.
includes
(
' help'
)){
route
.
runHelp
()
.
then
((
err
,
res
)
=>
{
if
(
err
)
throw
err
res
(
" function activated"
);
});
}
//Tell random joke
function
randomJoke
(){
const
rand
=
Math
.
floor
(
Math
.
random
()
*
2
)
+
1
;
if
(
rand
===
1
){
chuckJoke
();
}
else
if
(
rand
===
2
){
yoMamaJoke
();
}
}
function
runHelp
(){
const
face
=
{
icon_emoji
:
':question:'
};
bot
.
postMessageToChannel
(
'everyone'
,
"Type @joker and write a joke that you would like\n ex- @joker random"
,
face
);
bot
.
postMessageToChannel
(
'full-stack-web'
,
"Type @joker and write a joke that you would like\n ex- @joker random"
,
face
);
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment