Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import hackchat
- import subprocess
- import threading
- # call "dc", eval the expression and return the result
- def eval(expr):
- print(expr)
- proc = subprocess.Popen(
- ['dc'],stdout=subprocess.PIPE,
- stdin=subprocess.PIPE,
- stderr=subprocess.PIPE)
- proc.stdin.write((expr + '\n').encode("iso-8859-1"))
- proc.stdin.close()
- result = proc.stderr.read().decode("iso-8859-1").strip()
- result = result + "\n" + proc.stdout.read().decode("iso-8859-1").strip()
- print(result)
- return result
- # called when a message was received
- def message_got(chat, message, sender):
- print(message)
- if message.split()[0]==".dc":
- chat.send_message(eval(message[3:]))
- def thread_function(name):
- x = input()
- chat.send_message(x)
- x = threading.Thread(target=thread_function, args=(1,))
- x.start()
- # create new bot
- chat = hackchat.HackChat("dcbot", "programming")
- chat.on_message += [message_got]
- chat.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement