def onMessage(self, messageProtocolEntity): if messageProtocolEntity.getType() == 'text': time.sleep(random.randrange(Cfg.RAND_MIN,Cfg.RAND_MAX)) #Devine mensagem como enviada self.toLower(messageProtocolEntity.ack()) time.sleep(random.randrange(Cfg.RAND_MIN,Cfg.RAND_MAX)) self.toLower(AvailablePresenceProtocolEntity()) time.sleep(random.randrange(Cfg.RAND_MIN,Cfg.RAND_MAX)) self.toLower(PresenceProtocolEntity(name = name)) time.sleep(random.randrange(Cfg.RAND_MIN,Cfg.RAND_MAX)) #Devine mensagem como visualisada self.toLower(messageProtocolEntity.ack(True)) time.sleep(random.randrange(Cfg.RAND_MIN,Cfg.RAND_MAX)) self.toLower(OutgoingChatstateProtocolEntity(OutgoingChatstateProtocolEntity.STATE_TYPING, Jid.normalize(messageProtocolEntity.getFrom(False))))#Set esta escribiendo time.sleep(random.randrange(Cfg.RAND_MIN,Cfg.RAND_MAX)) #Envia a resposta self.onTextMessage(messageProtocolEntity) time.sleep(random.randrange(Cfg.RAND_MIN,Cfg.RAND_MAX)) self.toLower(OutgoingChatstateProtocolEntity(OutgoingChatstateProtocolEntity.STATE_PAUSED, Jid.normalize(messageProtocolEntity.getFrom(False))))#Set pausa time.sleep(random.randrange(Cfg.RAND_MIN,Cfg.RAND_MAX)) #Fica offline self.toLower(UnavailablePresenceProtocolEntity()) elif messageProtocolEntity.getType() == 'media': time.sleep(random.randrange(Cfg.RAND_MIN,Cfg.RAND_MAX)) self.toLower(AvailablePresenceProtocolEntity()) time.sleep(random.randrange(Cfg.RAND_MIN,Cfg.RAND_MAX)) self.toLower(PresenceProtocolEntity(name = name))#Set presencia self.onMediaMessage(messageProtocolEntity) self.toLower(messageProtocolEntity.ack()) self.toLower(messageProtocolEntity.ack(True)) time.sleep(random.randrange(Cfg.RAND_MIN,Cfg.RAND_MAX)) self.toLower(UnavailablePresenceProtocolEntity())#Set offline else: pass
def onTextMessage(self, messageProtocolEntity): if messageProtocolEntity.getType() == 'text': message = messageProtocolEntity.getBody().upper() recipient = messageProtocolEntity.getFrom() textmsg = TextMessageProtocolEntity if message.startswith(('$', '£', '\u20ac', '฿', '\u0243')) and len( message.split()) == 1 and len(message) > 1: new_symbol = ticker_sym() if new_symbol.messaged_ticker(message) != False: answer = new_symbol.messaged_ticker(message) else: return self.toLower(textmsg(answer, to=recipient)) else: return elif message == '&re start': answer = "Ok " + ", rebooting. Bye bye." self.toLower(textmsg(answer, to=recipient)) time.sleep(3) self.toLower(UnavailablePresenceProtocolEntity()) time.sleep(2) os.system('reboot') elif message == '&shut down': answer = "Ok " + ", shutting down. Bye bye." self.toLower(textmsg(answer, to=recipient)) time.sleep(3) self.toLower(UnavailablePresenceProtocolEntity()) time.sleep(2) os.system("sudo shutdown -h now") else: return
def onMessage(self, messageProtocolEntity): if messageProtocolEntity.getType() == 'text': time.sleep(0.5) elif messageProtocolEntity.getType() == 'media': time.sleep(0.5) time.sleep(0.5) self.toLower(messageProtocolEntity.ack()) #Set received (double v) time.sleep(0.5) self.toLower(PresenceProtocolEntity(name=name)) #Set name Presence time.sleep(0.5) self.toLower(AvailablePresenceProtocolEntity()) #Set online time.sleep(0.5) self.toLower( messageProtocolEntity.ack(True)) #Set read (double v blue) time.sleep(0.5) self.toLower( OutgoingChatstateProtocolEntity( OutgoingChatstateProtocolEntity.STATE_TYPING, Jid.normalize( messageProtocolEntity.getFrom(False)))) #Set is writing time.sleep(2) self.toLower( OutgoingChatstateProtocolEntity( OutgoingChatstateProtocolEntity.STATE_PAUSED, Jid.normalize( messageProtocolEntity.getFrom(False)))) #Set no is writing time.sleep(1) self.onTextMessage(messageProtocolEntity) #Send the answer time.sleep(3) self.toLower(UnavailablePresenceProtocolEntity()) #Set offline
def onMessage(self, messageProtocolEntity): print(messageProtocolEntity.getFrom()) # send receipt otherwise we keep receiving the same message over and over receipt = OutgoingReceiptProtocolEntity( messageProtocolEntity.getId(), messageProtocolEntity.getFrom(), False, messageProtocolEntity.getParticipant()) self.toLower(receipt) # route based on message type if messageProtocolEntity.getType() == 'text': self.onTextMessage(messageProtocolEntity) elif messageProtocolEntity.getType() == 'media': self.onMediaMessage(messageProtocolEntity) # to store in database, send grouped receipts later on when going online store = (messageProtocolEntity.getId(), messageProtocolEntity.getFrom(), messageProtocolEntity.getParticipant()) time.sleep(randint(3, 5)) self.toLower(AvailablePresenceProtocolEntity()) receipt = OutgoingReceiptProtocolEntity(store[0], store[1], True, store[2]) self.toLower(receipt) time.sleep(randint(3, 5)) self.toLower(UnavailablePresenceProtocolEntity())
def sendmessage(self, user_id, message): mylayer = self.stack.getLayer(8) mylayer.toLower(AvailablePresenceProtocolEntity()) outgoingMessageProtocolEntity = TextMessageProtocolEntity(message, to=user_id) mylayer.send(outgoingMessageProtocolEntity) time.sleep(5) mylayer.toLower(UnavailablePresenceProtocolEntity())
def onlineTimer(self): while True: global online global lastCommandTime if lastCommandTime + random.randint(10, 15) < time.time() and online: self.toLower( UnavailablePresenceProtocolEntity()) # Set offline online = False print('Online off') time.sleep(2)
def onMessage(self, messageProtocolEntity): if messageProtocolEntity.getType() == 'text': time.sleep(0.05) self.toLower(messageProtocolEntity.ack()) #Set received (double v) time.sleep(0.05) self.toLower(PresenceProtocolEntity(name=name)) #Set name Presence time.sleep(0.05) self.toLower(AvailablePresenceProtocolEntity()) #Set online time.sleep(0.05) self.toLower( messageProtocolEntity.ack(True)) #Set read (double v blue) time.sleep(0.05) self.onTextMessage(messageProtocolEntity) #Send the answer time.sleep(0.05) self.toLower(UnavailablePresenceProtocolEntity()) #Set offline elif messageProtocolEntity.getType() == 'media': self.toLower(messageProtocolEntity.ack()) #Set received (double v)
def offline(self): self.toLower(UnavailablePresenceProtocolEntity())
def set_offline(self, *_): ''' Set presence as unavailable ''' logging.debug('Setting presence offline.') entity = UnavailablePresenceProtocolEntity() self.toLower(entity)
def onTextMessage(self, messageProtocolEntity): namemitt = messageProtocolEntity.getNotify() message = messageProtocolEntity.getBody().lower() recipient = messageProtocolEntity.getFrom() textmsg = TextMessageProtocolEntity if messageProtocolEntity.getFrom(False) in ap: if message == 'fala puto': answer = "Puto e tu " + namemitt + " " self.toLower(textmsg(answer, to=recipient)) self.toLower(textmsg(answer, to=recipient)) print(recipient[2:12] + ":" + message) print(answer) elif message == 'filmes': lista_filmes_dir = os.listdir('/home/joao/filmes') for i in lista_filmes_dir: answer = i self.toLower(textmsg(answer, to=recipient)) time.sleep(0.5) time.sleep(2) self.toLower( textmsg( "Escolhe um arrombado, escreve dir na frente faz favor", to=recipient)) elif message[0:3] == 'dir': dir_filme = str('/home/joao/filmes/') + str( message[3:]) + str('/') lista_filmes_arq = os.listdir(dir_filme) for i in lista_filmes_arq: answer = i self.toLower(textmsg(answer, to=recipient)) time.sleep(1) self.toLower( textmsg( "Agora escreve o nome do arquivo com mov na frente, anda logo", to=recipient)) elif message[0:3] == 'mov': base_comando = 'python /home/joao/Development/stream2chromecast/stream2chromecast.py' dir_filme = str('/home/joao/filmes/') + str( message[3:-4]) + str('/') + str(message[3:]) dir_legenda = str('/home/joao/filmes/') + str( message[3:-4]) + str('/') + str(message[3:-4]) + ".vtt" comando_final = 'python /home/joao/Development/stream2chromecast/stream2chromecast.py' + ' -subtitles ' + dir_legenda + ' ' + dir_filme time.sleep(4) self.toLower( textmsg("Mandei pro chromecast, agora reza pra funcionar", to=recipient)) subprocess.Popen(comando_final, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True) elif message == 'pause': comando_final = 'python /home/joao/Development/stream2chromecast/stream2chromecast.py -pause' self.toLower(textmsg("Pausei, vai mijar", to=recipient)) subprocess.Popen(comando_final, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True) elif message == 'play': comando_final = 'python /home/joao/Development/stream2chromecast/stream2chromecast.py -continue' self.toLower(textmsg("Dei o play", to=recipient)) subprocess.Popen(comando_final, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True) elif message == 'stop': comando_final = 'python /home/joao/Development/stream2chromecast/stream2chromecast.py -stop' self.toLower(textmsg("Ja era", to=recipient)) subprocess.Popen(comando_final, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True) elif message == 'aumenta': comando_final = 'python /home/joao/Development/stream2chromecast/stream2chromecast.py -volup' self.toLower(textmsg("Ja era", to=recipient)) subprocess.Popen(comando_final, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True) elif message == 'abaixa': comando_final = 'python /home/joao/Development/stream2chromecast/stream2chromecast.py -voldown' self.toLower(textmsg("Ja era", to=recipient)) subprocess.Popen(comando_final, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True) elif message == 'manda nudes': answer = "Ok " + namemitt + ", seu safadinho. La vai." self.toLower(textmsg(answer, to=recipient)) print(recipient[2:12] + ":" + message) print(answer) time.sleep(1) self.toLower(UnavailablePresenceProtocolEntity()) time.sleep(1) else: answer = "Deculpe " + namemitt + ", Eu ainda nao entendo essa palavra" self.toLower(textmsg(answer, to=recipient)) print(recipient[2:12] + ":" + message) print(answer) else: answer = "Oi " + namemitt + ", Desculpe, nao quero ser rude, mas voce nao esta na lista de pessoas autorizadas desse numero" time.sleep(5) self.toLower(textmsg(answer, to=recipient)) print(recipient + ":" + message) print(answer) out_file = open(filelog, "a") out_file.write("------------------------" + "\n" + "Sender:" + "\n" + namemitt + "\n" + "Number sender:" + "\n" + recipient + "\n" + "Message text:" + "\n" + message + "\n" + "------------------------" + "\n" + "\n") out_file.close()
def onTextMessage(self, messageProtocolEntity): if messageProtocolEntity.getType() == 'text': message = messageProtocolEntity.getBody().lower() print(message) elif messageProtocolEntity.getType() == 'media': message = messageProtocolEntity.getMediaType() namemitt = messageProtocolEntity.getNotify() recipient = messageProtocolEntity.getFrom() textmsg = TextMessageProtocolEntity out_file = open(filelog, "a") out_file.write("------------------------" + "\n" + "Sender:" + "\n" + namemitt + "\n" + "Number sender:" + "\n" + recipient + "\n" + "Message text:" + "\n" + message + "\n" + "------------------------" + "\n" + "\n") out_file.close() #For a break to use the character \n #The sleep you write so ## time.sleep(1) if messageProtocolEntity.getFrom(False) <> "xxxxxx": if message == 'hi': answer = "Hi " + namemitt + ". What can i do for you today?\n-cv\n-aboutme\n-skills\n-temperature\n-speedtest\n-projects" self.toLower(textmsg(answer, to=recipient)) #self.toLower(textmsg(answer, to = recipient )) print answer elif message == '-list': answer = "Hi " + namemitt + "\n\nYou can ask me these things:\n-cv\n-aboutme\n-skills\n-temperature\n-speedtest\n-projects" self.toLower(textmsg(answer, to=recipient)) print answer elif message == 'temperature' or message == '-temperature': t = float( subprocess.check_output( ["/opt/vc/bin/vcgencmd measure_temp | cut -c6-9"], shell=True)[:-1]) ts = str(t) answer = 'My Raspberry Pi CPU temperature is ' + ts + ' °C' self.toLower(textmsg(answer, to=recipient)) print answer elif message == 'speedtest' or message == '-speedtest': try: st = pyspeedtest.SpeedTest() ping = st.ping() #print ping #print "%.2f" % down #print up answer = "My ping is %.1f " % ping self.toLower(textmsg(answer, to=recipient)) down = st.download() / 1000000 answer = "My download speed is %.2f mbps" % down self.toLower(textmsg(answer, to=recipient)) up = st.upload() / 1000000 answer = "My upload speed is %.2f mbps" % up self.toLower(textmsg(answer, to=recipient)) #print answer except: answer = "low speed can not connect server" self.toLower(textmsg(answer, to=recipient)) elif message == 'restart' and messageProtocolEntity.getFrom( False) == "905073648830": answer = "Ok " + namemitt + ", rebooting. Bye bye." self.toLower(textmsg(answer, to=recipient)) print answer time.sleep(3) self.toLower(UnavailablePresenceProtocolEntity()) time.sleep(2) os.system('sudo reboot') elif message == 'ip' and messageProtocolEntity.getFrom( False) == "905073648830": try: external_ip = urllib.urlopen( 'https://api.ipify.org/').read() answer = "My ip address is %s " % (external_ip) self.toLower(textmsg(answer, to=recipient)) except: answer = "couldn't connect server" self.toLower(textmsg(answer, to=recipient)) elif message == '-cv' or message == 'cv': answer = "https://drive.google.com/file/d/0B7VfVk5mxGRrWHZ0SnItUTM2UGM/view" self.toLower(textmsg(answer, to=recipient)) print answer #path = "/home/pi/Desktop/olcak/file/CV.jpg" #self.image_send(recipient, path) answer = "Here is my CV" self.toLower(textmsg(answer, to=recipient)) elif message == 'position': answer = "Hi " + namemitt + ", here is the position you asked me." self.toLower(textmsg(answer, to=recipient)) print answer latitude = "38.5167447" # from -90 to 90, positive means north and negative means south longitude = "27.2405762" # from -180 to 180, positive means east and negative means west locationName = "My Lovely house" # optional, the first line will become a clickable link, the second won't locationURL = "https://www.google.com.tr/maps/@38.5167447,27.2405762,596m/data=!3m1!1e3?hl=sg" # optional, this is the link you'll be redirected when you click the locationName locationEncoding = "raw" outLocation = (LocationMediaMessageProtocolEntity( latitude, longitude, locationName, locationURL, locationEncoding, to=recipient)) self.toLower(outLocation) elif message == '-aboutme' or message == 'aboutme': answer = "Hi! My name is Kutluhan Buyukburc and I am graduating from Ceylal Bayar University this June, with a Bachelor's degree in Electrical and Electronic Engineering. I enjoy playing chess (I won several chess competitions in my state when I was in high school!), going to the gym, and creating codes for Internet of things. I especially like creating codes that are useful to me and" answer = answer + "the people around me, such as a notification application for the online game Travian, and also an application which allows me to watch youtube videos while working on other programs on my computer. I am from Izmir, Turkey and I wish to seek employment in Singapore. Aside from my personal reasons for moving, I also find Singapore to be technologically advanced (way more than Turkey) and I am very intrigued by some technology that I observed while I was in Singapore. My favourite place in Singapore is the Night Safari and my favourite food would definitely be Chicken Rice =)" #answer=answer + "" self.toLower(textmsg(answer, to=recipient)) elif message == '-projects' or message == 'projects': answer = "https://github.com/kbuyukburc\nYou can find my projects$" self.toLower(textmsg(answer, to=recipient)) elif message == '-skills' or message == 'skills': answer = "PIC programing\nPLC programing\nLinux and Raspberry Pi knowledge\nC/C++ Python VB.net Asp.net PHP programing and SQL database knowledge\nAlso I have knowledge of finding vulnerabilities with Kali Linux tools" self.toLower(textmsg(answer, to=recipient)) #GPIO.output(14, True) # Pin 2 in up #answer = "Ok, il GPIO14 è su true" #self.toLower(textmsg(answer, to = recipient )) #print answer #elif message == 'off gpio14': #GPIO.output(14, False) # Pin 2 in down #answer = "Ok, il GPIO14 è su false" #self.toLower(textmsg(answer, to = recipient )) #print answer #elif message == "image": # print("Echoing image %s to %s" % (messageProtocolEntity.url, messageProtocolEntity.getFrom(False))) # answer = "Hi "+namemitt+", thank you for sending me your picture." # self.toLower(textmsg(answer, to = recipient )) # self.onMediaMessage(messageProtocolEntity) # print answer #elif message == "location": # print("Echoing location (%s, %s) to %s" % (messageProtocolEntity.getLatitude(), messageProtocolEntity.getLongitude(), messageProtocolEntity.getFrom(False))) # answer = "Hi "+namemitt+", thank you for sending me your geolocation." # self.toLower(textmsg(answer, to = recipient )) # print answer #elif message == "vcard": # print("Echoing vcard (%s, %s) to %s" % (messageProtocolEntity.getName(), messageProtocolEntity.getCardData(), messageProtocolEntity.getFrom(False))) # answer = "Hi "+namemitt+", thank you for sending me your contact." # self.toLower(textmsg(answer, to = recipient )) # print answer else: answer = "Sorry " + namemitt + ", I can not understand what you're asking me..\nCould you please write one of the following\n-cv\n-aboutme\n-skills\n-temperature\n-speedtest\n-projects " self.toLower(textmsg(answer, to=recipient)) print answer elif messageProtocolEntity.getFrom(False) == "xxxxxxxx": answer = "nevar amk" self.toLower(textmsg(answer, to=recipient)) print answer else: answer = "Hi " + namemitt + ", I'm sorry, I do not want to be rude, but I can not chat with you..\n-cv\n-aboutme\n-skills\n-temperature\n-speedtest\n-projects" #time.sleep(2) self.toLower(textmsg(answer, to=recipient)) print answer