오원석

make.joke.r

......@@ -10,8 +10,8 @@ message_recieved = 0;
exports.startbot = ()=>{
// Get authorization to use the slackbot
const bot = new SlackBot({
token : "xoxb-582582124755-587875604934-gdWsVhzGXCze3mECWXpTsAP6",
name : "joker"
token : "xoxb-635297512738-635283536771-A03RoBh4Dv8qG1EiLudMpk1f",
name : "jokebot"
});
// Start the slackbot
......@@ -141,9 +141,8 @@ function MakeJoke(message,user_channel){
var temp=message.split(' ');
var user=temp[0].substring(2,temp[0].length-1);
console.log('유저 => '+user);
var path='./joke_data/user.json';
console.log(path);
fs.exists(path,function(exists){
if(exists){
console.log("yes file exists");
......@@ -155,24 +154,33 @@ function MakeJoke(message,user_channel){
obj=JSON.parse(data);
var length=obj.table.length;
obj.table.push({id : length+1, type : user, setup : msg[0], punchline : msg[1]});
var myobj = {id : length+1, type : user, setup : msg[0], punchline : msg[1]};
//var myobj = {id : length+1, type : user, setup : msg[0], punchline : msg[1]};
MongoClient.connect(url,function(err,db){
if(err) throw err;
var dbo = db.db("userdb");
dbo.collection("user").insertOne(myobj, function(err,res){
if(err) throw err;
console.log("1 insert!!");
db.close;
})
})
var array = dbo.collection('user').find({type : user}).toArray(function(err,docs){
if(err){
callback(err,null);
return ;
}
console.log(docs.length);
var myobj = {id : docs.length+1, type : user, setup : msg[0], punchline : msg[1]};
dbo.collection("user").insertOne(myobj, function(err,res){
if(err) throw err;
console.log("1 insert!!");
db.close();
})
});
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";
......@@ -189,7 +197,7 @@ function MakeJoke(message,user_channel){
dbo.collection("user").insertOne(myobj, function(err,res){
if(err) throw err;
console.log("1 insert!!");
db.close;
db.close();
})
});
var json=JSON.stringify(obj);
......@@ -259,10 +267,19 @@ 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 ;
}
ary_size=docs.length;
console.log(docs.length);
});
result = db.collection('user').findOne({type: user});
console.log(result);
// 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){
......@@ -284,12 +301,6 @@ UserMakeJoke= (message,user_channel)=>{
})
var path='./joke_data/'+user+'.json';
var data=fs.readFileSync(path);
var jsondata=JSON.parse(data);
}
//Function for giving out random joke after filtering only general type jokes
......
const route = require('./Routers/route');
// var express=require('express');
// var app=express();
// //Before activating must connect to mongodb to interface
// //Connecting code [mongod --dbpath=data --bind_ip 127.0.0.1] at mongodb directory
// app.get('/slack/bot',function(req,res){
//Before activating must connect to mongodb to interface
//Connecting code [mongod --dbpath=data --bind_ip 127.0.0.1] at mongodb directory
// })
// app.listen(3000,function(){
// console.log("Connetect 3000 port!!");
// })
route.startbot();
......
{"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"}]}
\ 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"}]}
\ No newline at end of file
......