Skip to content

Instantly share code, notes, and snippets.

@mmpataki

mmpataki/novpn.py

Last active Aug 27, 2020
Embed
What would you like to do?
FB term
import signal
import subprocess
from fbchat import Client
from fbchat.models import *
user = "F1_user_email"
passwd = "F1_user_password"
recvFrom = "F2_user_id"
client = None
class NoVPNClient(Client):
def onMessage(self, mid, author_id, message_object, thread_id, thread_type, ts, metadata, msg, **kwargs):
if author_id == recvFrom:
proc = subprocess.Popen(msg['body'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
client.send(Message(text="```{}```".format(proc.stdout.read())), thread_id=recvFrom, thread_type=ThreadType.USER)
else:
print("someone else sent a message: from: [{}] msg: [{}]".format(author_id, msg['body']))
# add signal handler to logout from fb
def sigint_handler(signal, frame):
print 'Interrupted, logging out'
client.logout()
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
# login to facebook
client = NoVPNClient(user, passwd)
client.listen()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment