Skip to content

Instantly share code, notes, and snippets.

@hclivess
Created September 5, 2019 12:51
Show Gist options
  • Save hclivess/a9f838064a63ceaef7c001294e8f5950 to your computer and use it in GitHub Desktop.
Save hclivess/a9f838064a63ceaef7c001294e8f5950 to your computer and use it in GitHub Desktop.
fb_message_ai.py
from fbchat import Client
from fbchat.models import *
import time
import json
import random
from textgenrnn import textgenrnn
with open("secret.json") as file:
parsed = json.loads(file.read())
username = parsed['username']
password = parsed['password']
text = parsed['text']
def login():
client = Client(username, password)
return client
# Fetches a list of all users you're currently chatting with, as `User` objects
client = login()
users = client.fetchAllUsers()
print(f"users' IDs: {[user.uid for user in users]}")
print(f"users' names: {[user.name for user in users]}")
print(f"ready to send mass message {text}")
for user in users[100:]:
with open("sent.json","r") as file:
parsed = json.loads(file.read())
try:
while True:
if user.uid not in parsed:
client = login()
print("generating gibber...")
textgen = textgenrnn()
textgen.generate_to_file("ai.txt")
with open("ai.txt") as aifile:
gibber = aifile.read()
print(f"generated: {gibber}")
print(f"sending message to {user.name}")
client.send(Message(text=text + gibber), thread_id=user.uid, thread_type=ThreadType.USER)
with open("sent.json", "w") as file:
parsed[user.uid]=user.name
file.write(json.dumps(parsed))
delay = random.randint(60, 120)
print(f"sleeping for {delay} seconds...")
time.sleep(delay)
else:
print(f"skipping {user.uid}, {user.name}, message already sent")
break
except Exception as e:
print(e)
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment