Exemplo n.º 1
0
    def lambdabot_go(self, msg, txt):
        txt_shell = txt
        txt_shell = re.sub(r"^\s*(```|`)\s*","", txt_shell)
        txt_shell = txt_shell.replace(r"```","")
        txt_shell = re.sub(r"`\s*$","", txt_shell)
        txt_shell = re.sub(":(k|kind)","@kind", txt_shell)
        txt_shell = re.sub(":(t|type)","@type", txt_shell)
        txt_shell = re.sub("@(i|info)",":i", txt_shell)
        txt_shell = txt_shell.replace('“','"')
        txt_shell = txt_shell.replace('”','"')
        logging.info(txt_shell)
        trusted = ['base','bytestring','containers','array','microlens','random','lambdabot-trusted','time', 'stm']

        env = os.environ
        env["LC_CTYPE"] = "C"
        stdout=None
        stderr=None

        if (re.match(":(i|info)", txt_shell)):
            p_lambdabot = subprocess.Popen(['ghc']+['-e', txt_shell], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
            stdout, stderr = p_lambdabot.communicate()
            p_lambdabot.stdout.close()
        else:
            p_lambdabot = subprocess.Popen(['lambdabot']+['-t'+ x for x in trusted]+['-lWARNING', '-e'+txt_shell], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
            stdout, stderr = p_lambdabot.communicate()
            p_lambdabot.stdout.close()
        
        out = stdout.decode(encoding="utf-8", errors="ignore")
        # logging.info(out)

        outSlack = "\`\`\`"+out.replace("*","\*").replace("`","\`")+"\`\`\`"
        logging.info(outSlack)

        if (len(out)>0):
            return outSlack
        else:
            return "<error>"
Exemplo n.º 2
0
 def callback_room_joined(self, room):
     logging.info(room)