# coding=utf-8
__author__ = 'm_messiah'
from base64 import b64decode
from random import choice
from fuzzywuzzy import process

responses = {
    "Hello": ["Hi there!", "Hi!", "Welcome!", "Hello, {name}!"],
    "Hi there": ["Hello!", "Hello, {name}!", "Hi!", "Welcome!"],
    "Hi!": ["Hi there!", "Hello, {name}!", "Welcome!", "Hello!"],
    "Welcome": ["Hi there!", "Hi!", "Hello!", "Hello, {name}!",],
    "How are you?": ["I'm fine!", "Status: Working...", "I'm doing great."],
    "Good bye": ["Bye, {name}!"]
}

def human_response(message):
    return choice(
        responses.get(
            process.extract(message.get("text", ""),
                            responses.keys(),
                            limit=1)[0][0]
        )
    ).format_map({'name': message["from"].get("first_name", ""),
                  'date': message.get("date", ""),
                  })


def about(arguments, message):
    return """Hey, %s!
My author is @m_messiah.
You can find this nickname at:
    + Telegram
    + Twitter
    + Instagram
    + VK
    + GitHub (m-messiah)
    """ % message["from"].get("first_name")

def base64_decode(arguments, message):
    try:
        return b64decode(" ".join(arguments).encode("utf8"))
    except:
        return "Can't decode it"

def help_message(arguments, message):
    result = ["Hey, %s!" % message["from"].get("first_name"),
              "\rI can accept only these commands:"]
    for command in CMD:
        result.append(command)
    return "\n\t".join(result)


CMD = {
    "0": human_response,
    "/whoisyourdaddy": about,
    "/base64": base64_decode,
    "/help": help_message,
}

@@ -546,196 +546,252 @@
     
-return choice(%0A        responses.get(%0A            process.extract(message.get(%22text%22, %22%22),%0A                            responses.keys(),%0A                            limit=1)%5B0%5D%5B0%5D%0A
+leven = process.extract(message.get(%22text%22, %22%22), responses.keys(), limit=1)%0A    if leven%5B0%5D%5B1%5D %3C 75:%0A        response = %22I can not understand you%22%0A    else:%0A        response = leven%5B0%5D%5B0%5D%0A    return choice(responses.get(response)%0A      
         
 )%0A  
@@ -786,18 +786,16 @@
         
-)%0A
     ).fo
@@ -869,16 +869,30 @@
         
+              
 'date': 
@@ -908,32 +908,46 @@
 et(%22date%22, %22%22),%0A
+              
                 

fix for unknown command