김연준

Added slack_emoji file to easily use slack emoji / slight bug fixes

1 const MongoClient = require('mongodb').MongoClient; 1 const MongoClient = require('mongodb').MongoClient;
2 const SlackBot = require('slackbots'); 2 const SlackBot = require('slackbots');
3 const dbname = 'jokeapi'; 3 const dbname = 'jokeapi';
4 -const collec = 'jokes'; 4 +const emoji = require('../slack_emoji');
5 const url = 'mongodb://localhost:27017/'; 5 const url = 'mongodb://localhost:27017/';
6 6
7 exports.startbot = ()=>{ 7 exports.startbot = ()=>{
8 // Get authorization to use the slackbot 8 // Get authorization to use the slackbot
9 const bot = new SlackBot({ 9 const bot = new SlackBot({
10 - token : "xoxb-582582124755-587875604934-YBMZlb18wIdKQIEpyIV2dORa", 10 + token : "xoxb-582582124755-587875604934-t3xDZmtuLXVjgUMWDzAf8g1K",
11 name : "Joker" 11 name : "Joker"
12 }); 12 });
13 13
14 // Start the slackbot 14 // Start the slackbot
15 bot.on('start', () =>{ 15 bot.on('start', () =>{
16 - const face = { 16 + //Figure out user's all current channels in the team
17 - icon_emoji: ':bowtie:'
18 - };
19 - //Figure out user's all current channels and send the starting message
20 channel = bot.getChannels(); 17 channel = bot.getChannels();
21 channel.then((data)=>{ 18 channel.then((data)=>{
22 channel_length = data.channels.length; 19 channel_length = data.channels.length;
23 for(i=0; i< channel_length; ++i){ 20 for(i=0; i< channel_length; ++i){
24 bot.postMessageToChannel(data.channels[i].name, 'Have some fun with @Joker!\nFor commands write @joker --help' 21 bot.postMessageToChannel(data.channels[i].name, 'Have some fun with @Joker!\nFor commands write @joker --help'
25 - , face); 22 + , emoji.emojis('bowtie'));
26 } 23 }
27 return data; 24 return data;
28 }) 25 })
...@@ -40,12 +37,14 @@ bot.on('message', (data) => { ...@@ -40,12 +37,14 @@ bot.on('message', (data) => {
40 } 37 }
41 status = data; 38 status = data;
42 message_recieved = 0; 39 message_recieved = 0;
40 +
41 + //Figure out which channel the user is sending message
43 //If it's first input from the user, go through this loop to store the data of channel names and ids 42 //If it's first input from the user, go through this loop to store the data of channel names and ids
44 if(message_recieved == 0){ 43 if(message_recieved == 0){
45 channel_length; 44 channel_length;
46 channel_names = []; 45 channel_names = [];
47 channel_ids = []; 46 channel_ids = [];
48 - 47 + //bot.getChannels() returns a list of all channels in the team
49 channel = bot.getChannels(); 48 channel = bot.getChannels();
50 channel.then((data)=>{ 49 channel.then((data)=>{
51 channel_length = data.channels.length; 50 channel_length = data.channels.length;
...@@ -101,17 +100,11 @@ function handleMessage(message, current_channel){ ...@@ -101,17 +100,11 @@ function handleMessage(message, current_channel){
101 programmingJoke(current_channel); 100 programmingJoke(current_channel);
102 } 101 }
103 else if(message.includes(' me ')){ 102 else if(message.includes(' me ')){
104 - const quiet = { 103 + bot.postMessageToChannel(current_channel, "Tell you what??? :no_mouth:", emoji.emojis('no_mouth'));
105 - icon_emoji: ':no_mouth:'
106 - }
107 - bot.postMessageToChannel(current_channel, "Tell you what??? :no_mouth:", quiet);
108 } 104 }
109 else{ 105 else{
110 - const embarrased = {
111 - icon_emoji: ':flushed:'
112 - };
113 comment = "Sorry I dont' have that kind of joke.....:droplet::droplet::droplet:\nPlease use @joker --help to know what I can do!"; 106 comment = "Sorry I dont' have that kind of joke.....:droplet::droplet::droplet:\nPlease use @joker --help to know what I can do!";
114 - bot.postMessageToChannel(current_channel, comment, embarrased); 107 + bot.postMessageToChannel(current_channel, comment, emoji.emojis('flushed'));
115 108
116 } 109 }
117 110
...@@ -121,10 +114,7 @@ function handleMessage(message, current_channel){ ...@@ -121,10 +114,7 @@ function handleMessage(message, current_channel){
121 } 114 }
122 else if(message.includes(' what jokes')){ 115 else if(message.includes(' what jokes')){
123 jokeTypes = ["general", 'programming', 'knock-knock']; 116 jokeTypes = ["general", 'programming', 'knock-knock'];
124 - const face = { 117 + bot.postMessageToChannel(current_channel, `I have ${jokeTypes[0]}, ${jokeTypes[1]}, ${jokeTypes[2]} jokes!! :thumbsup: :thumbsup:`, emoji.emojis('thumbsup'));
125 - icon_emoji: ':thumbsup:'
126 - };
127 - bot.postMessageToChannel(current_channel, `I have ${jokeTypes[0]}, ${jokeTypes[1]}, ${jokeTypes[2]} jokes!! :thumbsup: :thumbsup:`, face);
128 return; 118 return;
129 } 119 }
130 // else{ 120 // else{
...@@ -160,12 +150,9 @@ randomJoke= (user_channel)=>{ ...@@ -160,12 +150,9 @@ randomJoke= (user_channel)=>{
160 user = result; 150 user = result;
161 user.then(function(total){ 151 user.then(function(total){
162 question = total.setup; 152 question = total.setup;
163 - const face = {
164 - icon_emoji: ':laughing:'
165 - };
166 153
167 function firstFunction(){ 154 function firstFunction(){
168 - bot.postMessageToChannel(user_channel, question, face); 155 + bot.postMessageToChannel(user_channel, question, emoji.emojis('laughing'));
169 } 156 }
170 firstFunction('everyone'); 157 firstFunction('everyone');
171 console.log('질문 불려짐'); 158 console.log('질문 불려짐');
...@@ -175,11 +162,8 @@ randomJoke= (user_channel)=>{ ...@@ -175,11 +162,8 @@ randomJoke= (user_channel)=>{
175 }) 162 })
176 .then((all)=>{ 163 .then((all)=>{
177 joke = all.punchline; 164 joke = all.punchline;
178 - const face = {
179 - icon_emoji: ':laughing:'
180 - };
181 setTimeout(function secondFunction(){ 165 setTimeout(function secondFunction(){
182 - bot.postMessageToChannel(user_channel, `${joke}:stuck_out_tongue_winking_eye::laughing:`, face, '/play secret') 166 + bot.postMessageToChannel(user_channel, `${joke}:stuck_out_tongue_winking_eye::laughing:`, emoji.emojis('laughing'))
183 console.log( "허무개그 전송~~~~!") 167 console.log( "허무개그 전송~~~~!")
184 }, 3000); 168 }, 3000);
185 169
...@@ -202,11 +186,7 @@ generalJoke= (user_channel)=>{ ...@@ -202,11 +186,7 @@ generalJoke= (user_channel)=>{
202 if(total.type === "general"){ 186 if(total.type === "general"){
203 question = total.setup; 187 question = total.setup;
204 joke = total.punchline; 188 joke = total.punchline;
205 - channel = 'everyone'; 189 + ques_and_joke = [question, joke];
206 - const face = {
207 - icon_emoji: ':laughing:'
208 - };
209 - ques_and_joke = [question, joke, face, channel];
210 return ques_and_joke; 190 return ques_and_joke;
211 } 191 }
212 else if(total.type != "general"){ 192 else if(total.type != "general"){
...@@ -216,16 +196,13 @@ generalJoke= (user_channel)=>{ ...@@ -216,16 +196,13 @@ generalJoke= (user_channel)=>{
216 196
217 }) 197 })
218 .then((joke_info)=>{ 198 .then((joke_info)=>{
219 - function askQuestion(){ 199 + bot.postMessageToChannel(user_channel, joke_info[0], emoji.emojis('laughing'));
220 - bot.postMessageToChannel(user_channel, joke_info[0], joke_info[2]); 200 + console.log("일반 질문 불려짐");
221 - console.log("일반 질문 불려짐");
222 - }
223 - askQuestion();
224 return joke_info; 201 return joke_info;
225 }) 202 })
226 .then((info)=>{ 203 .then((info)=>{
227 setTimeout(function secondFunction(){ 204 setTimeout(function secondFunction(){
228 - bot.postMessageToChannel(user_channel, `${info[1]}:stuck_out_tongue_winking_eye::laughing:`, info[2]) 205 + bot.postMessageToChannel(user_channel, `${info[1]}:stuck_out_tongue_winking_eye::laughing:`, emoji.emojis('laughing'))
229 console.log( "허무개그 전송~~~~!") 206 console.log( "허무개그 전송~~~~!")
230 }, 3000); 207 }, 3000);
231 }) 208 })
...@@ -247,11 +224,7 @@ programmingJoke= (user_channel)=>{ ...@@ -247,11 +224,7 @@ programmingJoke= (user_channel)=>{
247 if(total.type === "programming"){ 224 if(total.type === "programming"){
248 question = total.setup; 225 question = total.setup;
249 joke = total.punchline; 226 joke = total.punchline;
250 - channel = 'everyone'; 227 + ques_and_joke = [question, joke];
251 - const face = {
252 - icon_emoji: ':laughing:'
253 - };
254 - ques_and_joke = [question, joke, face, channel];
255 return ques_and_joke; 228 return ques_and_joke;
256 } 229 }
257 else if(total.type != "programming"){ 230 else if(total.type != "programming"){
...@@ -261,16 +234,13 @@ programmingJoke= (user_channel)=>{ ...@@ -261,16 +234,13 @@ programmingJoke= (user_channel)=>{
261 234
262 }) 235 })
263 .then((joke_info)=>{ 236 .then((joke_info)=>{
264 - function askQuestion(){ 237 + bot.postMessageToChannel(user_channel, joke_info[0], emoji.emojis('laughing'));
265 - bot.postMessageToChannel(user_channel, joke_info[0], joke_info[2]); 238 + console.log("프로그래밍 질문 불려짐");
266 - console.log("프로그래밍 질문 불려짐");
267 - }
268 - askQuestion();
269 return joke_info; 239 return joke_info;
270 }) 240 })
271 .then((info)=>{ 241 .then((info)=>{
272 setTimeout(function secondFunction(){ 242 setTimeout(function secondFunction(){
273 - bot.postMessageToChannel(user_channel, `${info[1]}:stuck_out_tongue_winking_eye::laughing:`, info[2]) 243 + bot.postMessageToChannel(user_channel, `${info[1]}:stuck_out_tongue_winking_eye::laughing:`, emoji.emojis('laughing'))
274 console.log( "허무개그 전송~~~~!") 244 console.log( "허무개그 전송~~~~!")
275 }, 3000); 245 }, 3000);
276 }) 246 })
...@@ -283,7 +253,6 @@ knockknockJoke= (user_channel)=>{ ...@@ -283,7 +253,6 @@ knockknockJoke= (user_channel)=>{
283 MongoClient.connect(url, function (err, client){ 253 MongoClient.connect(url, function (err, client){
284 if (err) throw err; 254 if (err) throw err;
285 var db = client.db('jokeapi'); 255 var db = client.db('jokeapi');
286 -
287 json_max = 61; 256 json_max = 61;
288 257
289 random = getRandomInt(json_max); 258 random = getRandomInt(json_max);
...@@ -293,11 +262,7 @@ knockknockJoke= (user_channel)=>{ ...@@ -293,11 +262,7 @@ knockknockJoke= (user_channel)=>{
293 if(total.type === "knock-knock"){ 262 if(total.type === "knock-knock"){
294 question = total.setup; 263 question = total.setup;
295 joke = total.punchline; 264 joke = total.punchline;
296 - channel = 'everyone'; 265 + ques_and_joke = [question, joke];
297 - const face = {
298 - icon_emoji: ':laughing:'
299 - };
300 - ques_and_joke = [question, joke, face, channel];
301 return ques_and_joke; 266 return ques_and_joke;
302 } 267 }
303 else if(total.type != "knock-knock"){ 268 else if(total.type != "knock-knock"){
...@@ -307,16 +272,14 @@ knockknockJoke= (user_channel)=>{ ...@@ -307,16 +272,14 @@ knockknockJoke= (user_channel)=>{
307 272
308 }) 273 })
309 .then((joke_info)=>{ 274 .then((joke_info)=>{
310 - function askQuestion(){ 275 + bot.postMessageToChannel(user_channel, joke_info[0], emoji.emojis('laughing'));
311 - bot.postMessageToChannel(user_channel, joke_info[0], joke_info[2]); 276 + console.log("똑똑 질문 불려짐");
312 - console.log("똑똑 질문 불려짐"); 277 +
313 - }
314 - askQuestion();
315 return joke_info; 278 return joke_info;
316 }) 279 })
317 .then((info)=>{ 280 .then((info)=>{
318 setTimeout(function secondFunction(){ 281 setTimeout(function secondFunction(){
319 - bot.postMessageToChannel(user_channel, `${info[1]}:stuck_out_tongue_winking_eye::laughing:`, info[2]) 282 + bot.postMessageToChannel(user_channel, `${info[1]}:stuck_out_tongue_winking_eye::laughing:`, emoji.emojis('laughing'))
320 console.log( "허무개그 전송~~~~!") 283 console.log( "허무개그 전송~~~~!")
321 }, 3000); 284 }, 3000);
322 }) 285 })
...@@ -327,11 +290,8 @@ knockknockJoke= (user_channel)=>{ ...@@ -327,11 +290,8 @@ knockknockJoke= (user_channel)=>{
327 //Function for giving out information to user to control the bot 290 //Function for giving out information to user to control the bot
328 runHelp = () =>{ 291 runHelp = () =>{
329 292
330 - const face = {
331 - icon_emoji: ':question:'
332 - };
333 comment = "Thanks for using Joker bot!:ghost::ghost:laugh:\nBot info: type '@joker --help'\nBot functions: @joker tell me [something] " 293 comment = "Thanks for using Joker bot!:ghost::ghost:laugh:\nBot info: type '@joker --help'\nBot functions: @joker tell me [something] "
334 - bot.postMessageToChannel('everyone', "Type @joker and write a joke that you would like\n ex- @joker random",face); 294 + bot.postMessageToChannel('everyone', "Type @joker and write a joke that you would like\n ex- @joker random",emoji.emojis('question'));
335 295
336 } 296 }
337 } 297 }
......
...@@ -19,11 +19,4 @@ exports.removeDocuments = (db, document , collection, callback)=>{ ...@@ -19,11 +19,4 @@ exports.removeDocuments = (db, document , collection, callback)=>{
19 exports.updateDocuments = (db, document , update ,collection, callback)=>{ 19 exports.updateDocuments = (db, document , update ,collection, callback)=>{
20 const coll = db.collection(collection); 20 const coll = db.collection(collection);
21 return coll.updateOne(document, {$set: update}, null); 21 return coll.updateOne(document, {$set: update}, null);
22 -}
23 -
24 -exports.getdata = (db, collection, input, callback) =>{
25 - const coll = db.collection(collection);
26 - result= coll.find({"type": input});
27 - console.log(result);
28 - return result;
29 } 22 }
...\ No newline at end of file ...\ No newline at end of file
......
1 +//Slack emoji storage
2 +//Link : https://www.webfx.com/tools/emoji-cheat-sheet/
3 +
4 +exports.emojis = (face) =>{
5 + emoji = {
6 + icon_emoji: `:${face}:`
7 + };
8 + return emoji;
9 +}
...\ No newline at end of file ...\ No newline at end of file