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-05-27 15:18:58 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5d8731077a1aa9865c58a43ade37976be192ff40
5d873107
1 parent
7cf78a0a
Making randomJoke function operate correctly
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
41 deletions
.gitignore
Routers/route.js
db_control.js
.gitignore
View file @
5d87310
node_modules
\ No newline at end of file
mongodb
\ No newline at end of file
...
...
Routers/route.js
View file @
5d87310
...
...
@@ -7,7 +7,7 @@ const url = 'mongodb://localhost:27017/';
exports
.
startbot
=
()
=>
{
// Get authorization to use the slackbot
const
bot
=
new
SlackBot
({
token
:
"
xoxb-582582124755-587875604934-86ISu22wmEaDhGWtQmpvumbR
"
,
token
:
""
,
name
:
"Joker"
});
...
...
@@ -70,21 +70,18 @@ randomJoke= ()=>{
user
=
result
;
user
.
then
(
function
(
total
){
question
=
total
.
setup
;
joke
=
total
.
punchline
;
const
face
=
{
icon_emoji
:
':laughing:'
};
function
firstFunction
(
channel
){
bot
.
postMessageToChannel
(
channel
,
joke
,
face
);
console
.
log
(
"허무개그 전송~~~~!"
);
}
function
secondFunction
(
channel
,
callback
){
function
firstFunction
(
channel
){
bot
.
postMessageToChannel
(
channel
,
question
,
face
);
console
.
log
(
"질문 불려짐"
)
firstFunction
(
channel
);
}
secondFunction
(
'everyone'
,
firstFunction
);
firstFunction
(
'everyone'
);
console
.
log
(
'질문 불려짐'
);
return
total
;
// bot.postMessageToChannel('everyone', question, face);
// bot.postMessageToChannel('full-stack-web', question, joke, face);
// bot.postMessageToChannel('bot_test', question, face);
...
...
@@ -92,6 +89,17 @@ randomJoke= ()=>{
// bot.postMessageToChannel('full-stack-web', joke, face);
// bot.postMessageToChannel('bot_test', joke, face);
})
.
then
((
all
)
=>
{
joke
=
all
.
punchline
;
const
face
=
{
icon_emoji
:
':laughing:'
};
function
secondFunction
(
channel
){
bot
.
postMessageToChannel
(
channel
,
joke
,
face
);
console
.
log
(
"허무개그 전송~~~~!"
)
}
secondFunction
(
'everyone'
);
})
client
.
close
();
})
}
...
...
@@ -178,9 +186,8 @@ programmingJoke= ()=>{
function
secondFunction
(
channel
,
callback
){
bot
.
postMessageToChannel
(
channel
,
question
,
face
);
console
.
log
(
"프로그래밍 질문 불려짐"
)
firstFunction
(
channel
);
}
secondFunction
(
'everyone'
,
firstFunction
);
secondFunction
(
'everyone'
).
then
(
firstFunction
(
'everyone'
)
);
// bot.postMessageToChannel('everyone', question, face);
// bot.postMessageToChannel('full-stack-web', question, joke, face);
// bot.postMessageToChannel('bot_test', question, face);
...
...
db_control.js
View file @
5d87310
const
MongoClient
=
require
(
'mongodb'
).
MongoClient
;
const
jokedoc
=
require
(
'./joke
s
/jokes.json'
);
const
jokedoc
=
require
(
'./joke
_data
/jokes.json'
);
const
dbname
=
'jokeapi'
;
const
collec
=
'jokes'
;
var
url
=
"mongodb://localhost:27017/jokeapi"
;
//
Create database
//
MongoClient.connect(url, function(err, db) {
//
if (err) throw err;
//
console.log("Database created!");
//
db.close();
//
});
//Create database
MongoClient
.
connect
(
url
,
function
(
err
,
db
)
{
if
(
err
)
throw
err
;
console
.
log
(
"Database created!"
);
db
.
close
();
});
// MongoClient.connect(url, function(err, db) {
// if (err) throw err;
// var dbo = db.db("jokeapi");
// dbo.createCollection("joke", function(err, res) {
// if (err) throw err;
// console.log("Collection created!");
// db.close();
// });
// });
//Create collection
MongoClient
.
connect
(
url
,
function
(
err
,
db
)
{
if
(
err
)
throw
err
;
var
dbo
=
db
.
db
(
"jokeapi"
);
dbo
.
createCollection
(
"joke"
,
function
(
err
,
res
)
{
if
(
err
)
throw
err
;
console
.
log
(
"Collection created!"
);
db
.
close
();
});
});
//
Storing data jokes.json data into mongodb
//
MongoClient.connect(url).then((client) => {
//Storing data jokes.json data into mongodb
MongoClient
.
connect
(
url
).
then
((
client
)
=>
{
//
console.log('Connected correctly to server');
console
.
log
(
'Connected correctly to server'
);
//
const db = client.db(dbname);
const
db
=
client
.
db
(
dbname
);
//
dboperation.insertDocument(db, jokedoc, collec)
//
.then((result) => {
//
console.log("Inserted Document:\n", result.ops);
dboperation
.
insertDocument
(
db
,
jokedoc
,
collec
)
.
then
((
result
)
=>
{
console
.
log
(
"Inserted Document:\n"
,
result
.
ops
);
//
return dboperation.findDocuments(db, collec);
//
})
//
.catch((err) => console.log(err));
return
dboperation
.
findDocuments
(
db
,
collec
);
})
.
catch
((
err
)
=>
console
.
log
(
err
));
//
})
//
.catch((err) => console.log(err));
})
.
catch
((
err
)
=>
console
.
log
(
err
));
...
...
Please
register
or
login
to post a comment