from apps.decorators import on_command
from apps.slackutils import is_koreanword
import json
import os
import re
CACHE_DEFAULT_URL = './apps/game_cache/relay.json'


@on_command(['!단어'])
def run(robot, channel, tokens, user, command):
    ''''''
    msg = '단어를 말해줘야 하지'
    if len(tokens) < 1:
        return channel, msg
    if len(tokens[0]) < 2:
        msg = '두 글자 이상의 단어만 가능함'
        return channel, msg
    if is_koreanword(tokens[0]):
        wdat = {}
        if os.path.exists(CACHE_DEFAULT_URL):
            wdat = json.loads(open(CACHE_DEFAULT_URL).read())
        if tokens[0] not in wdat:
            wdat[tokens[0]] = 0
        wdat[tokens[0]] += 1
        with open(CACHE_DEFAULT_URL, 'w') as fp:
            json.dump(wdat, fp, indent=4)
        msg = tokens[0] + ' 은(는) 단어임'
    else:
        msg = tokens[0] + ' 은(는) 단어가 아님'
    return channel, msg

@@ -325,24 +325,68 @@
 annel, msg%0D%0A
+    msg = ''%0D%0A    for token in tokens:%0D%0A    
     if len(t
@@ -389,20 +389,16 @@
 en(token
-s%5B0%5D
 ) %3C 2:%0D%0A
@@ -405,20 +405,25 @@
         
+ 
+   
 msg 
++
 = '%EB%91%90 %EA%B8%80%EC%9E%90 
@@ -437,40 +437,55 @@
  %EA%B0%80%EB%8A%A5%ED%95%A8
-'%0D%0A        return channel, msg%0D%0A
+ (' + token + ')%5Cn'%0D%0A            continue%0D%0A    
     
@@ -510,16 +510,16 @@
 oken
-s%5B0%5D
 ):%0D%0A
+    
     
@@ -541,16 +541,20 @@
         
+   
+ 
 if os.pa
@@ -580,24 +580,28 @@
 AULT_URL):%0D%0A
+    
             
@@ -663,16 +663,20 @@
     
+    
 if token
 s%5B0%5D
@@ -671,20 +671,16 @@
 if token
-s%5B0%5D
  not in 
@@ -690,32 +690,36 @@
 t:%0D%0A            
+    
 wdat%5Btokens%5B0%5D%5D 
@@ -712,20 +712,16 @@
 at%5Btoken
-s%5B0%5D
 %5D = 0%0D%0A 
@@ -719,32 +719,36 @@
 n%5D = 0%0D%0A        
+    
 wdat%5Btokens%5B0%5D%5D 
@@ -741,20 +741,16 @@
 at%5Btoken
-s%5B0%5D
 %5D += 1%0D%0A
@@ -757,16 +757,20 @@
         
+   
+ 
 with ope
@@ -815,16 +815,20 @@
         
+    
 json.dum
@@ -854,39 +854,40 @@
 4)%0D%0A        
+    
 msg 
++
 = token
-s%5B0%5D
  + ' %EC%9D%80(%EB%8A%94) %EB%8B%A8%EC%96%B4
@@ -887,19 +887,25 @@
 %EC%9D%80(%EB%8A%94) %EB%8B%A8%EC%96%B4%EC%9E%84
+%5Cn
 '%0D%0A
+    
     else
@@ -919,23 +919,24 @@
     
+ 
+   
 msg 
++
 = token
-s%5B0%5D
  + '
@@ -947,16 +947,18 @@
 ) %EB%8B%A8%EC%96%B4%EA%B0%80 %EC%95%84%EB%8B%98
+%5Cn
 '%0D%0A    r

Add multiple word recognization